X-Git-Url: https://git.argeo.org/?a=blobdiff_plain;ds=inline;f=org.argeo.init%2Fsrc%2Forg%2Fargeo%2Finit%2Fosgi%2FActivator.java;h=b85b248b9e17c94f01be20070cb86e69f3a79dd4;hb=abf185c93b2a4a415dc60c40ed37e6cc9ee12318;hp=5a9527041bf01e5c99bb8cc9598d40c620a6b1ee;hpb=b7d8618ce593bbeca7e311d32a4d98988e27f877;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 5a9527041..b85b248b9 100644 --- a/org.argeo.init/src/org/argeo/init/osgi/Activator.java +++ b/org.argeo.init/src/org/argeo/init/osgi/Activator.java @@ -1,9 +1,11 @@ package org.argeo.init.osgi; -import java.util.Enumeration; -import java.util.ResourceBundle; -import java.util.Vector; +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; @@ -13,44 +15,49 @@ import org.osgi.framework.BundleContext; * //wiki.eclipse.org/Configurator */ public class Activator implements BundleActivator { - private Long checkpoint = null; - - public void start(final BundleContext bundleContext) throws Exception { - // admin thread - Thread adminThread = new AdminThread(bundleContext); - adminThread.start(); - - // bootstrap - OsgiBoot osgiBoot = new OsgiBoot(bundleContext); - if (checkpoint == null) { - osgiBoot.bootstrap(); - checkpoint = System.currentTimeMillis(); - } else { - osgiBoot.update(); - checkpoint = System.currentTimeMillis(); - } + static { + // must be called first + ThinLoggerFinder.lazyInit(); } + private final static Logger logger = System.getLogger(Activator.class.getName()); - public void stop(BundleContext context) throws Exception { - } + private Long checkpoint = null; - class JournaldResourceBundle extends ResourceBundle { + private boolean argeoInit = false; + /** Not null if we created it ourselves. */ + private OsgiRuntimeContext runtimeContext; - @Override - protected Object handleGetObject(String key) { - switch (key) { - case "ERROR": - return "<5>"; + public void start(final BundleContext bundleContext) throws Exception { + // 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"); } - return null; - } - @Override - public Enumeration getKeys() { - Vector keys = new Vector<>(); - keys.add("ERROR"); - return keys.elements(); + // admin thread +// Thread adminThread = new AdminThread(bundleContext); +// adminThread.start(); + + // bootstrap +// OsgiBoot osgiBoot = new OsgiBoot(bundleContext); + if (checkpoint == null) { +// osgiBoot.bootstrap(); + checkpoint = System.currentTimeMillis(); + } else { + runtimeContext.update(); + checkpoint = System.currentTimeMillis(); + } } + } + public void stop(BundleContext context) throws Exception { + if (!argeoInit) { + Objects.nonNull(runtimeContext); + runtimeContext.stop(context); + runtimeContext = null; + } } + }