X-Git-Url: https://git.argeo.org/?a=blobdiff_plain;f=org.argeo.init%2Fsrc%2Forg%2Fargeo%2Finit%2Fosgi%2FActivator.java;h=b85b248b9e17c94f01be20070cb86e69f3a79dd4;hb=b6ee9c8baa2650ebbca59c9f24eac3599408bf7f;hp=518751f91e655f27bcadda1e4ea02e21d0e056fa;hpb=38b432ee473d4d604040fd9c4c234ae17fc7d070;p=lgpl%2Fargeo-commons.git diff --git a/org.argeo.init/src/org/argeo/init/osgi/Activator.java b/org.argeo.init/src/org/argeo/init/osgi/Activator.java index 518751f91..b85b248b9 100644 --- a/org.argeo.init/src/org/argeo/init/osgi/Activator.java +++ b/org.argeo.init/src/org/argeo/init/osgi/Activator.java @@ -4,6 +4,7 @@ import java.lang.System.Logger; import java.lang.System.Logger.Level; import java.util.Objects; +import org.argeo.init.Service; import org.argeo.init.logging.ThinLoggerFinder; import org.osgi.framework.BundleActivator; import org.osgi.framework.BundleContext; @@ -18,36 +19,45 @@ public class Activator implements BundleActivator { // must be called first ThinLoggerFinder.lazyInit(); } - private Logger logger = System.getLogger(Activator.class.getName()); + private final static Logger logger = System.getLogger(Activator.class.getName()); private Long checkpoint = null; + private boolean argeoInit = false; /** Not null if we created it ourselves. */ private OsgiRuntimeContext runtimeContext; public void start(final BundleContext bundleContext) throws Exception { - if (runtimeContext == null) { - runtimeContext = new OsgiRuntimeContext(bundleContext); - } - logger.log(Level.DEBUG, () -> "Argeo init via OSGi activator"); - - // admin thread + // The OSGi runtime was created by us, and therefore already initialized + argeoInit = Boolean.parseBoolean(bundleContext.getProperty(Service.PROP_ARGEO_INIT_MAIN)); + if (!argeoInit) { + if (runtimeContext == null) { + runtimeContext = new OsgiRuntimeContext(bundleContext); + logger.log(Level.DEBUG, () -> "Argeo init via OSGi activator"); + } + + // admin thread // Thread adminThread = new AdminThread(bundleContext); // adminThread.start(); - // bootstrap + // bootstrap // OsgiBoot osgiBoot = new OsgiBoot(bundleContext); - if (checkpoint == null) { + if (checkpoint == null) { // osgiBoot.bootstrap(); - checkpoint = System.currentTimeMillis(); - } else { - runtimeContext.update(); - checkpoint = System.currentTimeMillis(); + checkpoint = System.currentTimeMillis(); + } else { + runtimeContext.update(); + checkpoint = System.currentTimeMillis(); + } } } public void stop(BundleContext context) throws Exception { - Objects.nonNull(runtimeContext); - runtimeContext.stop(context); + if (!argeoInit) { + Objects.nonNull(runtimeContext); + runtimeContext.stop(context); + runtimeContext = null; + } } + }