X-Git-Url: https://git.argeo.org/?a=blobdiff_plain;f=org.argeo.init%2Fsrc%2Forg%2Fargeo%2Finit%2Fosgi%2FOsgiRuntimeContext.java;h=186577b4dba40dda3ee7169b0d2bb4c863489c10;hb=af52952e94d59bba22d0ac861e7777b60cf06c78;hp=373e3d6719115030884a2ed770b7dbf6667724d9;hpb=def1b847ee067994c32f49107e22d3c04eac2b0e;p=lgpl%2Fargeo-commons.git diff --git a/org.argeo.init/src/org/argeo/init/osgi/OsgiRuntimeContext.java b/org.argeo.init/src/org/argeo/init/osgi/OsgiRuntimeContext.java index 373e3d671..186577b4d 100644 --- a/org.argeo.init/src/org/argeo/init/osgi/OsgiRuntimeContext.java +++ b/org.argeo.init/src/org/argeo/init/osgi/OsgiRuntimeContext.java @@ -1,5 +1,6 @@ package org.argeo.init.osgi; +import java.lang.System.LoggerFinder; import java.util.Collections; import java.util.Hashtable; import java.util.Map; @@ -15,26 +16,28 @@ import org.osgi.framework.Bundle; import org.osgi.framework.BundleContext; import org.osgi.framework.BundleException; import org.osgi.framework.Constants; -import org.osgi.framework.ServiceRegistration; import org.osgi.framework.launch.Framework; import org.osgi.framework.launch.FrameworkFactory; /** An OSGi runtime context. */ -public class OsgiRuntimeContext implements RuntimeContext { +public class OsgiRuntimeContext implements RuntimeContext, AutoCloseable { private Map config; private Framework framework; private OsgiBoot osgiBoot; - @SuppressWarnings("rawtypes") - private ServiceRegistration loggingConfigurationSr; - @SuppressWarnings("rawtypes") - private ServiceRegistration logEntryPublisherSr; - + /** + * Constructor to use when the runtime context will create the OSGi + * {@link Framework}. + */ public OsgiRuntimeContext(Map config) { this.config = config; } - public OsgiRuntimeContext(BundleContext bundleContext) { + /** + * Constructor to use when the OSGi {@link Framework} has been created by other + * means. + */ + OsgiRuntimeContext(BundleContext bundleContext) { start(bundleContext); } @@ -55,16 +58,21 @@ public class OsgiRuntimeContext implements RuntimeContext { } public void start(BundleContext bundleContext) { + // preferences +// SystemRootPreferences systemRootPreferences = ThinPreferencesFactory.getInstance().getSystemRootPreferences(); +// bundleContext.registerService(AbstractPreferences.class, systemRootPreferences, new Hashtable<>()); + + // Make sure LoggerFinder has been searched for, since it is lazily loaded + LoggerFinder.getLoggerFinder(); + // logging - loggingConfigurationSr = bundleContext.registerService(Consumer.class, - ThinLoggerFinder.getConfigurationConsumer(), + bundleContext.registerService(Consumer.class, ThinLoggerFinder.getConfigurationConsumer(), new Hashtable<>(Collections.singletonMap(Constants.SERVICE_PID, "argeo.logging.configuration"))); - logEntryPublisherSr = bundleContext.registerService(Flow.Publisher.class, - ThinLoggerFinder.getLogEntryPublisher(), + bundleContext.registerService(Flow.Publisher.class, ThinLoggerFinder.getLogEntryPublisher(), new Hashtable<>(Collections.singletonMap(Constants.SERVICE_PID, "argeo.logging.publisher"))); osgiBoot = new OsgiBoot(bundleContext); - osgiBoot.bootstrap(); + osgiBoot.bootstrap(config); } @@ -113,4 +121,8 @@ public class OsgiRuntimeContext implements RuntimeContext { } + public Framework getFramework() { + return framework; + } + }