]> git.argeo.org Git - gpl/argeo-slc.git/blobdiff - runtime/org.argeo.slc.launcher/src/main/java/org/argeo/slc/cli/SlcMain.java
Simplify equinox launching
[gpl/argeo-slc.git] / runtime / org.argeo.slc.launcher / src / main / java / org / argeo / slc / cli / SlcMain.java
index 32c3ce90660f3c8ffc87a745e5b9eb153e1a7c0c..946099eaeda534733df7e7d5c7dc488037291542 100644 (file)
@@ -15,21 +15,21 @@ import org.apache.commons.io.IOUtils;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.argeo.slc.SlcException;
-import org.argeo.slc.logging.Log4jUtils;
 import org.argeo.slc.runtime.SlcExecutionContext;
 import org.argeo.slc.runtime.SlcRuntime;
-import org.springframework.context.ApplicationContext;
 import org.springframework.context.ConfigurableApplicationContext;
+import org.springframework.context.support.ClassPathXmlApplicationContext;
 import org.springframework.context.support.FileSystemXmlApplicationContext;
 
 public class SlcMain {
        public enum Mode {
-               single, agent
+               single, agent, osgi
        }
 
        private static Log log = null;
 
        private final static String BOOTSTRAP_LOG4J_CONFIG = "org/argeo/slc/cli/bootstrapLog4j.properties";
+       private final static String DEFAULT_AGENT_CONTEXT = "classpath:org/argeo/slc/cli/spring-agent-default.xml";
 
        private final static Option modeOpt = OptionBuilder.withLongOpt("mode")
                        .withArgName("mode").hasArg().withDescription(
@@ -173,29 +173,20 @@ public class SlcMain {
                }
                // Agent
                else if (mode.equals(Mode.agent)) {
-                       if (runtimeStr == null)
-                               runtimeStr = "agent.xml";
-                       final ConfigurableApplicationContext applicationContext = new FileSystemXmlApplicationContext(
-                                       "agent.xml");
+                       final ConfigurableApplicationContext applicationContext;
+                       if (runtimeStr == null) {
+                               applicationContext = new ClassPathXmlApplicationContext(
+                                               DEFAULT_AGENT_CONTEXT);
+                       } else {
+                               applicationContext = new FileSystemXmlApplicationContext(
+                                               runtimeStr);
+                       }
+                       applicationContext.registerShutdownHook();
                        applicationContext.start();
                        log.info("SLC Agent context started.");
-
-                       Thread shutdownHook = new Thread("SLC agent shutdown hook") {
-                               public void run() {
-                                       applicationContext.stop();
-                                       applicationContext.close();
-                                       log.info("Closed agent application context.");
-                               }
-                       };
-                       Runtime.getRuntime().addShutdownHook(shutdownHook);
-
-                       while (applicationContext.isActive()) {
-                               try {
-                                       Thread.sleep(1000);
-                               } catch (InterruptedException e) {
-                                       // silent
-                               }
-                       }
+               }
+               // OSGi
+               else if (mode.equals(Mode.osgi)) {
                }
        }