Improve Argeo Init shutdown sequence.
[lgpl/argeo-commons.git] / org.argeo.init / src / org / argeo / init / Service.java
index 03e2f12732941952f90302854d9218e9f020344a..9dcea49d2d6199cad72b9696191de85ecbd69f53 100644 (file)
@@ -31,6 +31,7 @@ public class Service implements Runnable, AutoCloseable {
                Runtime.getRuntime().addShutdownHook(new Thread(() -> {
                        try {
                                if (Service.runtimeContext != null) {
+//                                     System.out.println("Argeo Init stopping with PID " + pid);
                                        Service.runtimeContext.close();
                                        Service.runtimeContext.waitForStop(0);
                                }
@@ -47,22 +48,26 @@ public class Service implements Runnable, AutoCloseable {
 //                     log.log(Logger.Level.DEBUG, key + "=" + System.getProperty(key.toString()));
 //             }
                try {
-                       try (OsgiRuntimeContext osgiRuntimeContext = new OsgiRuntimeContext((Map<String, String>) config)) {
+                       try {
+                               OsgiRuntimeContext osgiRuntimeContext = new OsgiRuntimeContext((Map<String, String>) config);
                                osgiRuntimeContext.run();
                                Service.runtimeContext = osgiRuntimeContext;
                                Service.runtimeContext.waitForStop(0);
                        } catch (NoClassDefFoundError e) {
-                               try (StaticRuntimeContext staticRuntimeContext = new StaticRuntimeContext((Map<String, String>) config)) {
-                                       staticRuntimeContext.run();
-                                       Service.runtimeContext = staticRuntimeContext;
-                                       Service.runtimeContext.waitForStop(0);
-                               }
+                               StaticRuntimeContext staticRuntimeContext = new StaticRuntimeContext((Map<String, String>) config);
+                               staticRuntimeContext.run();
+                               Service.runtimeContext = staticRuntimeContext;
+                               Service.runtimeContext.waitForStop(0);
                        }
                } catch (Exception e) {
                        e.printStackTrace();
                        System.exit(1);
                }
-               log.log(Logger.Level.DEBUG, "Argeo Init stopping with PID " + pid);
+               log.log(Logger.Level.DEBUG, "Argeo Init stopped with PID " + pid);
        }
 
+       
+       public static RuntimeContext getRuntimeContext() {
+               return runtimeContext;
+       }
 }