mirror of
https://github.com/eclipse-sailing-analytics/sailing-analytics.git
synced 2026-11-07 11:32:16 +00:00
added an activator to com.sap.sse which registers a shutdown hook so the OSGi framework will shut down gracefully upon SIGTERM
Change-Id: Ic1d5741878e5139d1757585a5a96aaa2facba170
This commit is contained in:
1 parent
ee82994625
commit
612e139aa2
2 files changed
+39
No files matched your search
@@ -30,3 +30,4 @@ Import-Package: javax.servlet;version="3.1.0",
|
||||
org.osgi.framework;version="1.8.0",
|
||||
org.osgi.util.tracker;version="1.5.1"
|
||||
Automatic-Module-Name: com.sap.sse
|
||||
Bundle-Activator: com.sap.sse.impl.Activator
|
||||
+38
@@ -0,0 +1,38 @@
|
||||
package com.sap.sse.impl;
|
||||
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import org.osgi.framework.Bundle;
|
||||
import org.osgi.framework.BundleActivator;
|
||||
import org.osgi.framework.BundleContext;
|
||||
import org.osgi.framework.BundleException;
|
||||
|
||||
/**
|
||||
* Registers a shutdown hook that gracefully stops the OSGi framework by
|
||||
* grabbing the system bundle and stopping it.
|
||||
*
|
||||
* @author Axel Uhl (D043530)
|
||||
*
|
||||
*/
|
||||
public class Activator implements BundleActivator {
|
||||
private static final Logger logger = Logger.getLogger(Activator.class.getName());
|
||||
|
||||
@Override
|
||||
public void start(BundleContext context) throws Exception {
|
||||
Runtime.getRuntime().addShutdownHook(new Thread(()->{
|
||||
logger.info("Executing shutdown hook, gracefully shutting down OSGi framework");
|
||||
try {
|
||||
final Bundle systemBundle = context.getBundle(0);
|
||||
logger.info("Found system bundle "+systemBundle.getSymbolicName());
|
||||
systemBundle.stop();
|
||||
} catch (BundleException e) {
|
||||
logger.log(Level.WARNING, "Exception while trying to gracefully stop the OSGi framework", e);
|
||||
}
|
||||
}));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void stop(BundleContext context) throws Exception {
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user