01: /*
02: * Copyright 2005-2007 The Kuali Foundation.
03: *
04: *
05: * Licensed under the Educational Community License, Version 1.0 (the "License");
06: * you may not use this file except in compliance with the License.
07: * You may obtain a copy of the License at
08: *
09: * http://www.opensource.org/licenses/ecl1.php
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: */
17: package edu.iu.uis.eden.core.dependencylifecycles;
18:
19: import org.kuali.rice.core.Core;
20: import org.kuali.rice.lifecycle.BaseLifecycle;
21:
22: import edu.emory.mathcs.backport.java.util.concurrent.Executors;
23: import edu.emory.mathcs.backport.java.util.concurrent.ScheduledExecutorService;
24: import edu.emory.mathcs.backport.java.util.concurrent.ScheduledFuture;
25: import edu.emory.mathcs.backport.java.util.concurrent.TimeUnit;
26: import edu.iu.uis.eden.KEWServiceLocator;
27: import edu.iu.uis.eden.batch.XmlPollerService;
28:
29: public class XmlPipelineLifeCycle extends BaseLifecycle {
30:
31: protected final org.apache.log4j.Logger LOG = org.apache.log4j.Logger
32: .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
41: .getXmlPollerService();
42: LOG
43: .info("Starting XML data loader. Polling at "
44: + xmlPoller.getPollIntervalSecs()
45: + "-second intervals");
46: if (!Core.getCurrentContextConfig().getDevMode()) {
47: future = scheduledExecutor.scheduleWithFixedDelay(
48: xmlPoller, xmlPoller.getInitialDelaySecs(),
49: xmlPoller.getPollIntervalSecs(), TimeUnit.SECONDS);
50: super .start();
51: }
52: }
53:
54: public void stop() throws Exception {
55: if (isStarted()) {
56: LOG.warn("Shutting down XML file polling timer");
57: try {
58: if (future != null) {
59: if (!future.cancel(false)) {
60: LOG
61: .warn("Failed to cancel the XML Poller service.");
62: }
63: future = null;
64: }
65: if (scheduledExecutor != null) {
66: scheduledExecutor.shutdownNow();
67: scheduledExecutor = null;
68: }
69: } finally {
70: super.stop();
71: }
72: }
73: }
74:
75: }
|