]> git.argeo.org Git - gpl/argeo-slc.git/blobdiff - runtime/org.argeo.slc.launcher/src/main/java/org/argeo/slc/cli/SlcMain.java
Integrate ActiveMQ
[gpl/argeo-slc.git] / runtime / org.argeo.slc.launcher / src / main / java / org / argeo / slc / cli / SlcMain.java
index c4193369a0b172b3b66eb165503538a1b43f005d..32c3ce90660f3c8ffc87a745e5b9eb153e1a7c0c 100644 (file)
@@ -18,6 +18,9 @@ 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.FileSystemXmlApplicationContext;
 
 public class SlcMain {
        public enum Mode {
@@ -168,6 +171,32 @@ public class SlcMain {
                                System.exit(1);
                        }
                }
+               // Agent
+               else if (mode.equals(Mode.agent)) {
+                       if (runtimeStr == null)
+                               runtimeStr = "agent.xml";
+                       final ConfigurableApplicationContext applicationContext = new FileSystemXmlApplicationContext(
+                                       "agent.xml");
+                       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
+                               }
+                       }
+               }
        }
 
        public static void printUsage() {