X-Git-Url: https://git.argeo.org/?a=blobdiff_plain;f=org.argeo.cms%2Fsrc%2Forg%2Fargeo%2Fcms%2Finternal%2Fkernel%2FCmsShutdown.java;h=bfc58501c48ee1b4c0b8f5766524b6c4d18ccb9e;hb=ed3d525b21f55ed76763381b91c888404487e3e1;hp=43295ae3f2681f47eee52d03c573a7bd68ba5652;hpb=d84d867f0b1c4d8a9b251260ef6d5679e40e5c42;p=lgpl%2Fargeo-commons.git diff --git a/org.argeo.cms/src/org/argeo/cms/internal/kernel/CmsShutdown.java b/org.argeo.cms/src/org/argeo/cms/internal/kernel/CmsShutdown.java index 43295ae3f..bfc58501c 100644 --- a/org.argeo.cms/src/org/argeo/cms/internal/kernel/CmsShutdown.java +++ b/org.argeo.cms/src/org/argeo/cms/internal/kernel/CmsShutdown.java @@ -24,38 +24,42 @@ class CmsShutdown extends Thread { public CmsShutdown() { super("CMS Shutdown Hook"); - framework = (Framework) FrameworkUtil.getBundle(CmsShutdown.class).getBundleContext().getBundle(0); + framework = FrameworkUtil.getBundle(CmsShutdown.class) != null + ? (Framework) FrameworkUtil.getBundle(CmsShutdown.class).getBundleContext().getBundle(0) + : null; } @Override public void run() { - if (framework.getState() != Bundle.ACTIVE) { + if (framework != null && framework.getState() != Bundle.ACTIVE) { return; } - + if (log.isDebugEnabled()) log.debug("Shutting down OSGi framework..."); try { - // shutdown framework - framework.stop(); - // wait for shutdown - FrameworkEvent shutdownEvent = framework.waitForStop(timeout); - int stoppedType = shutdownEvent.getType(); - Runtime runtime = Runtime.getRuntime(); - if (stoppedType == FrameworkEvent.STOPPED) { - // close VM - //System.exit(EXIT_OK); - } else if (stoppedType == FrameworkEvent.ERROR) { - log.error("The OSGi framework stopped with an error"); - runtime.halt(EXIT_ERROR); - } else if (stoppedType == FrameworkEvent.WAIT_TIMEDOUT) { - log.error("The OSGi framework hasn't stopped after " + timeout + "ms." - + " Forcibly terminating the JVM..."); - runtime.halt(EXIT_TIMEOUT); - } else { - log.error("Unknown state of OSGi framework after " + timeout + "ms." - + " Forcibly terminating the JVM... (" + shutdownEvent + ")"); - runtime.halt(EXIT_UNKNOWN); + if (framework != null) { + // shutdown framework + framework.stop(); + // wait for shutdown + FrameworkEvent shutdownEvent = framework.waitForStop(timeout); + int stoppedType = shutdownEvent.getType(); + Runtime runtime = Runtime.getRuntime(); + if (stoppedType == FrameworkEvent.STOPPED) { + // close VM + // System.exit(EXIT_OK); + } else if (stoppedType == FrameworkEvent.ERROR) { + log.error("The OSGi framework stopped with an error"); + runtime.halt(EXIT_ERROR); + } else if (stoppedType == FrameworkEvent.WAIT_TIMEDOUT) { + log.error("The OSGi framework hasn't stopped after " + timeout + "ms." + + " Forcibly terminating the JVM..."); + runtime.halt(EXIT_TIMEOUT); + } else { + log.error("Unknown state of OSGi framework after " + timeout + "ms." + + " Forcibly terminating the JVM... (" + shutdownEvent + ")"); + runtime.halt(EXIT_UNKNOWN); + } } } catch (Exception e) { e.printStackTrace();