import java.util.function.Supplier;
import org.argeo.api.init.RuntimeContext;
-import org.osgi.framework.Bundle;
import org.osgi.framework.BundleContext;
import org.osgi.framework.BundleException;
import org.osgi.framework.Constants;
private final static long STOP_FOR_UPDATE_TIMEOUT = 60 * 1000;
private final static long CLOSE_TIMEOUT = 60 * 1000;
- private final static String SYMBOLIC_NAME_FELIX_SCR = "org.apache.felix.scr";
+ // private final static String SYMBOLIC_NAME_FELIX_SCR = "org.apache.felix.scr";
private Map<String, String> config;
private Framework framework;
new Hashtable<>(Collections.singletonMap(Constants.SERVICE_PID, "argeo.logging.publisher")));
}
OsgiBoot osgiBoot = new OsgiBoot(bundleContext);
- osgiBoot.bootstrap(config);
+ String frameworkUuuid = bundleContext.getProperty(Constants.FRAMEWORK_UUID);
+
+ // separate thread in order to improve logging
+ Thread osgiBootThread = new Thread("OSGi boot framework " + frameworkUuuid) {
+ @Override
+ public void run() {
+ osgiBoot.bootstrap(config);
+ }
+ };
+ osgiBootThread.start();
+ // TODO return a completable stage so that inits can run in parallel
+// try {
+// osgiBootThread.join(60 * 1000);
+// } catch (InterruptedException e) {
+// // silent
+// }
}
public void update() {
public void close() throws Exception {
if (framework == null)
return;
-// Bundle scrBundle = osgiBoot.getBundlesBySymbolicName().get();
-// if (scrBundle != null && scrBundle.getState() > Bundle.RESOLVED) {
-// scrBundle.stop();
-// while (!(scrBundle.getState() <= Bundle.RESOLVED)) {
-// Thread.sleep(500);
+ // TODO make shutdown of dynamic service more robust
+// for (Bundle scrBundle : framework.getBundleContext().getBundles()) {
+// if (scrBundle.getSymbolicName().equals(SYMBOLIC_NAME_FELIX_SCR)) {
+// if (scrBundle.getState() > Bundle.RESOLVED) {
+// scrBundle.stop();
+// while (!(scrBundle.getState() <= Bundle.RESOLVED)) {
+// Thread.sleep(100);
+// }
+// Thread.sleep(500);
+// }
// }
-// Thread.sleep(1000);
// }
- // TODO make shutdown of dynamic service more robust
- for (Bundle scrBundle : framework.getBundleContext().getBundles()) {
- if (scrBundle.getSymbolicName().equals(SYMBOLIC_NAME_FELIX_SCR)) {
- if (scrBundle.getState() > Bundle.RESOLVED) {
- scrBundle.stop();
- while (!(scrBundle.getState() <= Bundle.RESOLVED)) {
- Thread.sleep(100);
- }
- Thread.sleep(100);
- }
- }
- }
-
stop();
waitForStop(CLOSE_TIMEOUT);
framework = null;