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;
.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
this.listener.logged(entry);
}
}
+
+ /*
+ * Install the default exception handler so that the uncaught
+ * exceptions are handled by our customized handler. This new
+ * handler will display the exceptions to OSGI console as well
+ * as log to file.
+ */
+ 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
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");
+ }
+ }
+ }
+
}