X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=opendaylight%2Flogging%2Fbridge%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Flogging%2Fbridge%2Finternal%2FActivator.java;h=7061954e80e199b2a52c49eeace78ad27b9d4518;hb=ff1b4a79cca00743a00c3b0b1100bd0ab2b2fb31;hp=75c5ca9cbbbbd13cf050975a9cffcd4e916a4ad9;hpb=d192c699590d441eb96a697b9e8ab7a028f18860;p=controller.git diff --git a/opendaylight/logging/bridge/src/main/java/org/opendaylight/controller/logging/bridge/internal/Activator.java b/opendaylight/logging/bridge/src/main/java/org/opendaylight/controller/logging/bridge/internal/Activator.java index 75c5ca9cbb..7061954e80 100644 --- a/opendaylight/logging/bridge/src/main/java/org/opendaylight/controller/logging/bridge/internal/Activator.java +++ b/opendaylight/logging/bridge/src/main/java/org/opendaylight/controller/logging/bridge/internal/Activator.java @@ -12,6 +12,7 @@ package org.opendaylight.controller.logging.bridge.internal; import org.osgi.service.log.LogEntry; import java.util.Enumeration; import org.osgi.framework.BundleContext; +import org.osgi.framework.BundleException; import org.osgi.framework.BundleActivator; import org.osgi.framework.ServiceRegistration; import org.osgi.framework.ServiceReference; @@ -44,7 +45,7 @@ public class Activator implements BundleActivator { .getService(service); if (reader == null) { this.log.error("Cannot register the LogListener because " - + "cannot retrive LogReaderService"); + + "cannot retrieve LogReaderService"); } reader.addLogListener(this.listener); // Now lets walk all the exiting messages @@ -55,7 +56,7 @@ public class Activator implements BundleActivator { this.listener.logged(entry); } } - + /* * Install the default exception handler so that the uncaught * exceptions are handled by our customized handler. This new @@ -64,9 +65,17 @@ public class Activator implements BundleActivator { */ Thread.setDefaultUncaughtExceptionHandler(new org.opendaylight. controller.logging.bridge.internal.UncaughtExceptionHandler()); + + /* + * Install the Shutdown handler. This will intercept SIGTERM signal and + * close the system bundle. This allows for a graceful closing of OSGI + * framework. + */ + + Runtime.getRuntime().addShutdownHook(new shutdownHandler(context)); } else { this.log.error("Cannot register the LogListener because " - + "cannot retrive LogReaderService"); + + "cannot retrieve LogReaderService"); } } else { System.err @@ -86,4 +95,21 @@ public class Activator implements BundleActivator { this.listener = null; this.log = null; } + + private class shutdownHandler extends Thread { + BundleContext bundlecontext; + public shutdownHandler(BundleContext ctxt) { + this.bundlecontext = ctxt; + } + + public void run () { + try { + this.bundlecontext.getBundle(0).stop(); + log.debug("shutdown handler thread called"); + } catch (BundleException e) { + log.debug("Bundle couldn't be stopped"); + } + } + } + }