1 package org
.argeo
.init
.osgi
;
3 import java
.lang
.System
.Logger
;
4 import java
.lang
.System
.Logger
.Level
;
5 import java
.util
.Objects
;
7 import org
.argeo
.api
.init
.RuntimeManager
;
8 import org
.argeo
.init
.ServiceMain
;
9 import org
.argeo
.init
.logging
.ThinLoggerFinder
;
10 import org
.osgi
.framework
.BundleActivator
;
11 import org
.osgi
.framework
.BundleContext
;
14 * An OSGi configurator. See
15 * <a href="http://wiki.eclipse.org/Configurator">http:
16 * //wiki.eclipse.org/Configurator</a>
18 public class InitActivator
implements BundleActivator
{
20 // must be called first
21 ThinLoggerFinder
.lazyInit();
23 private final static Logger logger
= System
.getLogger(InitActivator
.class.getName());
25 private Long checkpoint
= null;
27 private boolean argeoInit
= false;
28 /** Not null if we created it ourselves. */
29 private OsgiRuntimeContext runtimeContext
;
31 private static OsgiRuntimeManager runtimeManager
;
33 public void start(final BundleContext bundleContext
) throws Exception
{
34 // The OSGi runtime was created by us, and therefore already initialized
35 argeoInit
= Boolean
.parseBoolean(bundleContext
.getProperty(ServiceMain
.PROP_ARGEO_INIT_MAIN
));
37 if (runtimeContext
== null) {
38 runtimeContext
= new OsgiRuntimeContext(bundleContext
);
39 logger
.log(Level
.DEBUG
, () -> "Argeo init via OSGi activator");
43 // Thread adminThread = new AdminThread(bundleContext);
44 // adminThread.start();
47 // OsgiBoot osgiBoot = new OsgiBoot(bundleContext);
48 if (checkpoint
== null) {
49 // osgiBoot.bootstrap();
50 checkpoint
= System
.currentTimeMillis();
52 runtimeContext
.update();
53 checkpoint
= System
.currentTimeMillis();
57 if (runtimeManager
!= null)
58 throw new IllegalArgumentException("Runtime manager is already set");
59 runtimeManager
= new OsgiRuntimeManager(bundleContext
);
62 public void stop(BundleContext context
) throws Exception
{
64 Objects
.nonNull(runtimeContext
);
65 runtimeContext
.stop(context
);
66 runtimeContext
= null;
68 runtimeManager
= null;
71 public static RuntimeManager
getRuntimeManager() {
72 return runtimeManager
;