]> git.argeo.org Git - lgpl/argeo-commons.git/blob - Activator.java
1b21f56635f8885242cef1e26443b87a1708c9ab
[lgpl/argeo-commons.git] / Activator.java
1 package org.argeo.cms.internal.kernel;
2
3 import java.util.UUID;
4
5 import org.apache.commons.logging.Log;
6 import org.apache.commons.logging.LogFactory;
7 import org.argeo.security.SystemAuthentication;
8 import org.osgi.framework.BundleActivator;
9 import org.osgi.framework.BundleContext;
10
11 /**
12 * Activates the {@link Kernel} from the provided {@link BundleContext}. Gives
13 * access to kernel information for the rest of the bundle (and only it)
14 */
15 public class Activator implements BundleActivator {
16 private final Log log = LogFactory.getLog(Activator.class);
17
18 private final static String systemKey;
19 static {
20 systemKey = UUID.randomUUID().toString();
21 System.setProperty(SystemAuthentication.SYSTEM_KEY_PROPERTY, systemKey);
22 }
23
24 private static BundleContext bundleContext;
25 private Kernel kernel;
26
27 @Override
28 public void start(BundleContext context) throws Exception {
29 assert bundleContext == null;
30 assert kernel == null;
31 bundleContext = context;
32 try {
33 kernel = new Kernel();
34 kernel.init();
35 } catch (Exception e) {
36 log.error("Cannot boot kernel", e);
37 }
38 }
39
40 @Override
41 public void stop(BundleContext context) throws Exception {
42 kernel.destroy();
43 kernel = null;
44 bundleContext = null;
45 }
46
47 /**
48 * Singleton interface to the {@link BundleContext} related to the calling
49 * thread.
50 *
51 * @BundleScope
52 */
53 public static BundleContext getBundleContext() {
54 return bundleContext;
55 }
56
57 /**
58 * @return a String which is guaranteed to be unique between and constant
59 * within a Java static context (typically a VM launch)
60 * @BundleScope
61 */
62 public final static String getSystemKey() {
63 return systemKey;
64 }
65 }