]> git.argeo.org Git - lgpl/argeo-commons.git/blob - org.argeo.init/src/org/argeo/init/osgi/Activator.java
Introduce cms ping command
[lgpl/argeo-commons.git] / org.argeo.init / src / org / argeo / init / osgi / Activator.java
1 package org.argeo.init.osgi;
2
3 import java.lang.System.Logger;
4 import java.lang.System.Logger.Level;
5 import java.util.Objects;
6
7 import org.argeo.init.Service;
8 import org.argeo.init.logging.ThinLoggerFinder;
9 import org.osgi.framework.BundleActivator;
10 import org.osgi.framework.BundleContext;
11
12 /**
13 * An OSGi configurator. See
14 * <a href="http://wiki.eclipse.org/Configurator">http:
15 * //wiki.eclipse.org/Configurator</a>
16 */
17 public class Activator implements BundleActivator {
18 static {
19 // must be called first
20 ThinLoggerFinder.lazyInit();
21 }
22 private final static Logger logger = System.getLogger(Activator.class.getName());
23
24 private Long checkpoint = null;
25
26 private boolean argeoInit = false;
27 /** Not null if we created it ourselves. */
28 private OsgiRuntimeContext runtimeContext;
29
30 public void start(final BundleContext bundleContext) throws Exception {
31 // The OSGi runtime was created by us, and therefore already initialized
32 argeoInit = Boolean.parseBoolean(bundleContext.getProperty(Service.PROP_ARGEO_INIT_MAIN));
33 if (!argeoInit) {
34 if (runtimeContext == null) {
35 runtimeContext = new OsgiRuntimeContext(bundleContext);
36 logger.log(Level.DEBUG, () -> "Argeo init via OSGi activator");
37 }
38
39 // admin thread
40 // Thread adminThread = new AdminThread(bundleContext);
41 // adminThread.start();
42
43 // bootstrap
44 // OsgiBoot osgiBoot = new OsgiBoot(bundleContext);
45 if (checkpoint == null) {
46 // osgiBoot.bootstrap();
47 checkpoint = System.currentTimeMillis();
48 } else {
49 runtimeContext.update();
50 checkpoint = System.currentTimeMillis();
51 }
52 }
53 }
54
55 public void stop(BundleContext context) throws Exception {
56 if (!argeoInit) {
57 Objects.nonNull(runtimeContext);
58 runtimeContext.stop(context);
59 runtimeContext = null;
60 }
61 }
62
63 }