1 package org.dfdaemon.il2.core;
2
3 import org.apache.commons.logging.Log;
4 import org.apache.commons.logging.LogFactory;
5 import org.springframework.beans.BeansException;
6 import org.springframework.beans.factory.annotation.Required;
7 import org.springframework.context.ApplicationContext;
8 import org.springframework.context.ApplicationContextAware;
9 import org.springframework.context.ConfigurableApplicationContext;
10 import org.springframework.context.Lifecycle;
11 import org.springframework.context.support.ClassPathXmlApplicationContext;
12
13 import java.util.List;
14
15
16
17
18
19
20 public class Daemon implements Lifecycle, ApplicationContextAware {
21
22 private static final Log LOGGER = LogFactory.getLog(Daemon.class);
23
24 private List<String> _modules;
25 private ApplicationContext _applicationContext;
26
27 private ConfigurableApplicationContext _configurableApplicationContext;
28 private boolean _started;
29
30
31
32
33 public void start() {
34 if (isRunning())
35 return;
36
37 if (LOGGER.isDebugEnabled())
38 LOGGER.debug("Start");
39
40 _modules.add(0, "META-INF/dfdaemon/il2-core.xml");
41 _configurableApplicationContext =
42 new ClassPathXmlApplicationContext(_modules.toArray(new String[_modules.size()]), _applicationContext);
43 _configurableApplicationContext.start();
44 _started = true;
45 }
46
47
48
49
50 public void stop() {
51 if (!isRunning())
52 return;
53 if (LOGGER.isDebugEnabled())
54 LOGGER.debug("Stop");
55 _configurableApplicationContext.close();
56 _configurableApplicationContext = null;
57 _started = false;
58 }
59
60
61
62
63 public boolean isRunning() {
64 return _started;
65 }
66
67
68
69
70
71
72 @Required
73 public void setModules(List<String> modules) {
74 _modules = modules;
75 }
76
77
78
79
80 public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
81 _applicationContext = applicationContext;
82 }
83 }