1 package org
.argeo
.slc
.execution
.old
;
3 import java
.io
.FileInputStream
;
4 import java
.util
.Properties
;
6 import org
.apache
.commons
.io
.IOUtils
;
7 import org
.apache
.commons
.logging
.Log
;
8 import org
.apache
.commons
.logging
.LogFactory
;
9 import org
.argeo
.slc
.core
.execution
.ConsoleContextDescriber
;
10 import org
.argeo
.slc
.core
.execution
.ExecutionFinishedEvent
;
11 import org
.argeo
.slc
.core
.execution
.NewExecutionEvent
;
12 import org
.argeo
.slc
.execution
.ExecutionContext
;
13 import org
.argeo
.slc
.logging
.Log4jUtils
;
14 import org
.argeo
.slc
.process
.SlcExecution
;
15 import org
.springframework
.beans
.factory
.support
.SimpleBeanDefinitionRegistry
;
16 import org
.springframework
.beans
.factory
.xml
.XmlBeanDefinitionReader
;
17 import org
.springframework
.context
.ApplicationEvent
;
18 import org
.springframework
.context
.ApplicationListener
;
19 import org
.springframework
.context
.support
.GenericApplicationContext
;
21 public class EfLauncher
implements ApplicationListener
{
22 private final Log log
;
24 private boolean running
= false;
27 Properties userProperties
= new Properties();
28 FileInputStream in
= null;
30 in
= new FileInputStream("src/slc/conf/slc.properties");
31 userProperties
.load(in
);
32 } catch (Exception e
) {
35 IOUtils
.closeQuietly(in
);
38 // Set as System properties
39 for (Object obj
: userProperties
.keySet()) {
40 String key
= obj
.toString();
41 System
.setProperty(key
, userProperties
.getProperty(key
));
45 System
.setProperty("log4j.defaultInitOverride", "true");
47 Log4jUtils
.initLog4j(null);
48 log
= LogFactory
.getLog(EfLauncher
.class);
51 public void launch(String script
) {
54 GenericApplicationContext context
= new GenericApplicationContext();
55 XmlBeanDefinitionReader reader
= new XmlBeanDefinitionReader(context
);
56 reader
.loadBeanDefinitions(script
);
57 // FileSystemXmlApplicationContext context = new
58 // FileSystemXmlApplicationContext(
60 context
.addApplicationListener(this);
63 log
.debug("Context initialized");
65 SlcExecution slcExecution
= new SlcExecution();
66 slcExecution
.getAttributes().put("slc.flows", "main");
69 context
.publishEvent(new NewExecutionEvent(this, slcExecution
));
75 } catch (InterruptedException e
) {
81 public synchronized boolean isRunning() {
85 public synchronized void setRunning(boolean running
) {
86 this.running
= running
;
89 public void onApplicationEvent(ApplicationEvent event
) {
90 if (event
instanceof ExecutionFinishedEvent
) {
91 ExecutionContext executionContext
= ((ExecutionFinishedEvent
) event
)
92 .getExecutionContext();
93 log
.debug("Execution " + executionContext
.getUuid()
94 + " finished, stopping launcher...");
103 public static void main(String
[] args
) {
104 String script
= "file:src/slc/conf/main.xml";
105 new EfLauncher().launch(script
);
108 private static void describe(String script
) {
109 SimpleBeanDefinitionRegistry registry
= new SimpleBeanDefinitionRegistry();
110 XmlBeanDefinitionReader reader
= new XmlBeanDefinitionReader(registry
);
111 reader
.loadBeanDefinitions(script
);
112 new ConsoleContextDescriber().describeContext(registry
);