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