X-Git-Url: https://git.argeo.org/?a=blobdiff_plain;f=org.argeo.init%2Fsrc%2Forg%2Fargeo%2Finit%2Fosgi%2FOsgiRuntimeContext.java;h=373e3d6719115030884a2ed770b7dbf6667724d9;hb=def1b847ee067994c32f49107e22d3c04eac2b0e;hp=7f44f6b2746dccc914312180b493d56e7328ce3c;hpb=1010bff4f1ffadbf3f7988fbd3eba70f5d672c88;p=lgpl%2Fargeo-commons.git diff --git a/org.argeo.init/src/org/argeo/init/osgi/OsgiRuntimeContext.java b/org.argeo.init/src/org/argeo/init/osgi/OsgiRuntimeContext.java index 7f44f6b27..373e3d671 100644 --- a/org.argeo.init/src/org/argeo/init/osgi/OsgiRuntimeContext.java +++ b/org.argeo.init/src/org/argeo/init/osgi/OsgiRuntimeContext.java @@ -11,6 +11,7 @@ import java.util.function.Consumer; import org.argeo.init.RuntimeContext; import org.argeo.init.logging.ThinLoggerFinder; +import org.osgi.framework.Bundle; import org.osgi.framework.BundleContext; import org.osgi.framework.BundleException; import org.osgi.framework.Constants; @@ -73,25 +74,43 @@ public class OsgiRuntimeContext implements RuntimeContext { } public void stop(BundleContext bundleContext) { - if (loggingConfigurationSr != null) - loggingConfigurationSr.unregister(); - if (logEntryPublisherSr != null) - logEntryPublisherSr.unregister(); - +// if (loggingConfigurationSr != null) +// try { +// loggingConfigurationSr.unregister(); +// } catch (Exception e) { +// // silent +// } +// if (logEntryPublisherSr != null) +// try { +// logEntryPublisherSr.unregister(); +// } catch (Exception e) { +// // silent +// } } @Override public void waitForStop(long timeout) throws InterruptedException { if (framework == null) throw new IllegalStateException("Framework is not initialised"); - stop(framework.getBundleContext()); + framework.waitForStop(timeout); } - @Override public void close() throws Exception { + // TODO make shutdown of dynamic service more robust + Bundle scrBundle = osgiBoot.getBundlesBySymbolicName().get("org.apache.felix.scr"); + if (scrBundle != null) { + scrBundle.stop(); + while (!(scrBundle.getState() <= Bundle.RESOLVED)) { + Thread.sleep(500); + } + Thread.sleep(1000); + } + + stop(framework.getBundleContext()); if (framework != null) framework.stop(); + } }