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