X-Git-Url: https://git.argeo.org/?a=blobdiff_plain;f=org.argeo.cms%2Fsrc%2Forg%2Fargeo%2Fcms%2Finternal%2Fosgi%2FCmsActivator.java;h=94b08da4d316a37d7d614c74904c91c09a72ced3;hb=c7b612ca9bd7df43b0bec37c8abcae846587c978;hp=5e047d38a6b06db35900bd5439533e164646ff96;hpb=bfb5eb067a6796c0ee2a575b1e2431220352513a;p=lgpl%2Fargeo-commons.git diff --git a/org.argeo.cms/src/org/argeo/cms/internal/osgi/CmsActivator.java b/org.argeo.cms/src/org/argeo/cms/internal/osgi/CmsActivator.java index 5e047d38a..94b08da4d 100644 --- a/org.argeo.cms/src/org/argeo/cms/internal/osgi/CmsActivator.java +++ b/org.argeo.cms/src/org/argeo/cms/internal/osgi/CmsActivator.java @@ -1,9 +1,10 @@ package org.argeo.cms.internal.osgi; import java.security.AllPermission; -import java.util.Dictionary; -import org.argeo.api.cms.CmsLog; +import org.argeo.api.cms.CmsState; +import org.argeo.api.uuid.NodeIdSupplier; +import org.argeo.cms.internal.runtime.CmsStateImpl; import org.osgi.framework.BundleActivator; import org.osgi.framework.BundleContext; import org.osgi.framework.Constants; @@ -19,50 +20,15 @@ import org.osgi.service.permissionadmin.PermissionInfo; * bundle (and only it) */ public class CmsActivator implements BundleActivator { - private final static CmsLog log = CmsLog.getLog(CmsActivator.class); +// private final static CmsLog log = CmsLog.getLog(CmsActivator.class); + private final static String PROP_ARGEO_OSGI_PARENT_UUID = "argeo.osgi.parent.uuid"; // TODO make it configurable private boolean hardened = false; private static BundleContext bundleContext; -// private LogReaderService logReaderService; -// -// private CmsOsgiLogger logger; - - void init() { -// Runtime.getRuntime().addShutdownHook(new CmsShutdown()); -// instance = this; -// this.bc = bundleContext; -// if (bundleContext != null) -// this.logReaderService = getService(LogReaderService.class); -// initArgeoLogger(); -// this.internalExecutorService = Executors.newFixedThreadPool(Runtime.getRuntime().availableProcessors()); -// -// try { -// initSecurity(); -//// initArgeoLogger(); -// initNode(); -// -// if (log.isTraceEnabled()) -// log.trace("Kernel bundle started"); -// } catch (Throwable e) { -// log.error("## FATAL: CMS activator failed", e); -// } - } - - void destroy() { - try { - bundleContext = null; -// this.logReaderService = null; - } catch (Exception e) { - log.error("CMS activator shutdown failed", e); - } - - new GogoShellKiller().start(); - } - - private void initSecurity() { + protected void initSecurity() { // code-level permissions String osgiSecurity = bundleContext.getProperty(Constants.FRAMEWORK_SECURITY); if (osgiSecurity != null && Constants.FRAMEWORK_SECURITY_OSGI.equals(osgiSecurity)) { @@ -98,21 +64,14 @@ public class CmsActivator implements BundleActivator { } -// private void initArgeoLogger() { -// logger = new CmsOsgiLogger(logReaderService); -// if (bundleContext != null) -// bundleContext.registerService(ArgeoLogger.class, logger, null); +// static void registerService(Class clss, T service, Dictionary properties) { +// if (bundleContext != null) { +// bundleContext.registerService(clss, service, properties); +// } +// // } - - - public static void registerService(Class clss, T service, Dictionary properties) { - if (bundleContext != null) { - bundleContext.registerService(clss, service, properties); - } - - } - - public static T getService(Class clss) { +// + static T getService(Class clss) { if (bundleContext != null) { return bundleContext.getService(bundleContext.getServiceReference(clss)); } else { @@ -127,21 +86,32 @@ public class CmsActivator implements BundleActivator { @Override public void start(BundleContext bc) throws Exception { bundleContext = bc; - - init(); - + CmsStateImpl cmsState = new CmsStateImpl(); + cmsState.start(); + bundleContext.registerService(new String[] { CmsState.class.getName(), NodeIdSupplier.class.getName() }, + cmsState, null); } @Override public void stop(BundleContext bc) throws Exception { - - destroy(); - bundleContext = null; + try { + CmsStateImpl cmsState = (CmsStateImpl) getService(CmsState.class); + String parentFrameworkuuid = bc.getProperty(PROP_ARGEO_OSGI_PARENT_UUID); + if (parentFrameworkuuid == null) + new GogoShellKiller().start(); + cmsState.stop(); + } finally { + bundleContext = null; + } } - - public static BundleContext getBundleContext() { + static BundleContext getBundleContext() { return bundleContext; } + public static String getFrameworkProperty(String key) { + if (bundleContext == null) + return null; + return getBundleContext().getProperty(key); + } }