1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.kuali.rice.kew.lifecycle;
18
19 import java.util.concurrent.Executors;
20 import java.util.concurrent.ScheduledExecutorService;
21 import java.util.concurrent.ScheduledFuture;
22 import java.util.concurrent.TimeUnit;
23
24 import org.kuali.rice.core.config.ConfigContext;
25 import org.kuali.rice.core.lifecycle.BaseLifecycle;
26 import org.kuali.rice.kew.batch.XmlPollerService;
27 import org.kuali.rice.kew.service.KEWServiceLocator;
28
29
30 public class XmlPipelineLifeCycle extends BaseLifecycle {
31
32 protected final org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(XmlPipelineLifeCycle.class);
33
34 private ScheduledExecutorService scheduledExecutor;
35 private ScheduledFuture future;
36
37 public void start() throws Exception {
38 LOG.info("Configuring XML ingestion pipeline...");
39 scheduledExecutor = Executors.newScheduledThreadPool(1);
40 final XmlPollerService xmlPoller = KEWServiceLocator.getXmlPollerService();
41 LOG.info("Starting XML data loader. Polling at " + xmlPoller.getPollIntervalSecs() + "-second intervals");
42 if (!ConfigContext.getCurrentContextConfig().getDevMode()) {
43 future = scheduledExecutor.scheduleWithFixedDelay(xmlPoller, xmlPoller.getInitialDelaySecs(), xmlPoller.getPollIntervalSecs(), TimeUnit.SECONDS);
44 super.start();
45 }
46 }
47
48 public void stop() throws Exception {
49 if (isStarted()) {
50 LOG.warn("Shutting down XML file polling timer");
51 try {
52 if (future != null) {
53 if (!future.cancel(false)) {
54 LOG.warn("Failed to cancel the XML Poller service.");
55 }
56 future = null;
57 }
58 if (scheduledExecutor != null) {
59 scheduledExecutor.shutdownNow();
60 scheduledExecutor = null;
61 }
62 } finally {
63 super.stop();
64 }
65 }
66 }
67
68 }