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