Move Jetty factory to the servlet bundle
[lgpl/argeo-commons.git] / org.argeo.cms / src / org / argeo / cms / internal / runtime / CmsStateImpl.java
index 7b47b520d580fa602dda48c663f94ec493a9bb1c..b493c08ef3cb923d286444d96e96b8e1c1fdc4ab 100644 (file)
@@ -3,8 +3,6 @@ package org.argeo.cms.internal.runtime;
 import java.net.InetAddress;
 import java.net.URL;
 import java.net.UnknownHostException;
-import java.util.ArrayList;
-import java.util.List;
 
 import javax.security.auth.login.Configuration;
 
@@ -28,15 +26,14 @@ public class CmsStateImpl implements CmsState {
        // REFERENCES
        private Long availableSince;
 
-
 //     private ThreadGroup threadGroup = new ThreadGroup("CMS");
-       private List<Runnable> stopHooks = new ArrayList<>();
+//     private List<Runnable> stopHooks = new ArrayList<>();
 
        private String stateUuid;
 //     private final boolean cleanState;
        private String hostname;
 
-       public void init() {
+       public void start() {
 //             instance = this;
 
                Runtime.getRuntime().addShutdownHook(new CmsShutdown());
@@ -49,27 +46,27 @@ public class CmsStateImpl implements CmsState {
 
                        if (log.isTraceEnabled())
                                log.trace("CMS State started");
-               } catch (Throwable e) {
-                       log.error("## FATAL: CMS activator failed", e);
-               }
 
-               this.stateUuid = KernelUtils.getFrameworkProp(Constants.FRAMEWORK_UUID);
+                       this.stateUuid = KernelUtils.getFrameworkProp(Constants.FRAMEWORK_UUID);
 //             this.cleanState = stateUuid.equals(frameworkUuid);
-               try {
-                       this.hostname = InetAddress.getLocalHost().getHostName();
-               } catch (UnknownHostException e) {
-                       log.error("Cannot set hostname: " + e);
-               }
+                       try {
+                               this.hostname = InetAddress.getLocalHost().getHostName();
+                       } catch (UnknownHostException e) {
+                               log.error("Cannot set hostname: " + e);
+                       }
 
-               availableSince = System.currentTimeMillis();
-               if (log.isDebugEnabled())
-                       // log.debug("## CMS starting... stateUuid=" + this.stateUuid + (cleanState ? "
-                       // (clean state) " : " "));
-                       log.debug("## CMS starting... (" + stateUuid + ")");
+                       availableSince = System.currentTimeMillis();
+                       if (log.isDebugEnabled())
+                               // log.debug("## CMS starting... stateUuid=" + this.stateUuid + (cleanState ? "
+                               // (clean state) " : " "));
+                               log.debug("## CMS starting... (" + stateUuid + ")");
 
 //             initI18n();
 //             initServices();
 
+               } catch (RuntimeException e) {
+                       log.error("## FATAL: CMS activator failed", e);
+               }
        }
 
        private void initSecurity() {
@@ -178,18 +175,19 @@ public class CmsStateImpl implements CmsState {
 //                     log.debug("Initialised default Bitronix transaction manager");
 //     }
 
-       public void destroy() {
+       public void stop() {
                if (log.isDebugEnabled())
                        log.debug("CMS stopping...  (" + this.stateUuid + ")");
+//             new GogoShellKiller().start();
 
                // In a different thread in order to avoid interruptions
-               Thread stopHookThread = new Thread(() -> applyStopHooks(), "Apply Argeo Stop Hooks");
-               stopHookThread.start();
-               try {
-                       stopHookThread.join(10 * 60 * 1000);
-               } catch (InterruptedException e) {
-                       // silent
-               }
+//             Thread stopHookThread = new Thread(() -> applyStopHooks(), "Apply Argeo Stop Hooks");
+//             stopHookThread.start();
+//             try {
+//                     stopHookThread.join(10 * 60 * 1000);
+//             } catch (InterruptedException e) {
+//                     // silent
+//             }
 
 //             internalExecutorService.shutdown();
 
@@ -198,19 +196,19 @@ public class CmsStateImpl implements CmsState {
        }
 
        /** Apply shutdown hoos in reverse order. */
-       private void applyStopHooks() {
-               for (int i = stopHooks.size() - 1; i >= 0; i--) {
-                       try {
-                               stopHooks.get(i).run();
-                       } catch (Exception e) {
-                               log.error("Could not run shutdown hook #" + i);
-                       }
-               }
-               // Clean hanging Gogo shell thread
-               new GogoShellKiller().start();
-
-//             instance = null;
-       }
+//     private void applyStopHooks() {
+////           for (int i = stopHooks.size() - 1; i >= 0; i--) {
+////                   try {
+////                           stopHooks.get(i).run();
+////                   } catch (Exception e) {
+////                           log.error("Could not run shutdown hook #" + i);
+////                   }
+////           }
+//             // Clean hanging Gogo shell thread
+//             new GogoShellKiller().start();
+//
+////           instance = null;
+//     }
 
 //     @Override
 //     public boolean isClean() {