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;
private Framework framework;
private OsgiBoot osgiBoot;
- @SuppressWarnings("rawtypes")
- private ServiceRegistration<Consumer> loggingConfigurationSr;
- @SuppressWarnings("rawtypes")
- private ServiceRegistration<Flow.Publisher> logEntryPublisherSr;
-
/**
* Constructor to use when the runtime context will create the OSGi
* {@link Framework}.
}
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);
--- /dev/null
+package org.argeo.init.prefs;
+
+import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.ExecutionException;
+import java.util.function.Consumer;
+import java.util.prefs.AbstractPreferences;
+import java.util.prefs.BackingStoreException;
+
+public class SystemRootPreferences extends AbstractPreferences implements Consumer<AbstractPreferences> {
+ private CompletableFuture<AbstractPreferences> singleChild;
+
+ protected SystemRootPreferences() {
+ super(null, "");
+ }
+
+ @Override
+ public void accept(AbstractPreferences t) {
+ this.singleChild.complete(t);
+ }
+
+ /*
+ * ABSTRACT PREFERENCES
+ */
+
+ @Override
+ protected void putSpi(String key, String value) {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ protected String getSpi(String key) {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ protected void removeSpi(String key) {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ protected void removeNodeSpi() throws BackingStoreException {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ protected String[] keysSpi() throws BackingStoreException {
+ return new String[0];
+ }
+
+ /** Will block. */
+ @Override
+ protected String[] childrenNamesSpi() throws BackingStoreException {
+ String childName;
+ try {
+ childName = singleChild.get().name();
+ } catch (InterruptedException | ExecutionException e) {
+ throw new IllegalStateException("Cannot get child preferences name", e);
+ }
+ return new String[] { childName };
+ }
+
+ @Override
+ protected AbstractPreferences childSpi(String name) {
+ String childName;
+ try {
+ childName = singleChild.get().name();
+ } catch (InterruptedException | ExecutionException e) {
+ throw new IllegalStateException("Cannot get child preferences name", e);
+ }
+ if (!childName.equals(name))
+ throw new IllegalArgumentException("Child name is " + childName + ", not " + name);
+ return null;
+ }
+
+ @Override
+ protected void syncSpi() throws BackingStoreException {
+ }
+
+ @Override
+ protected void flushSpi() throws BackingStoreException {
+ }
+
+}
--- /dev/null
+package org.argeo.init.prefs;
+
+import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.ExecutionException;
+import java.util.prefs.Preferences;
+import java.util.prefs.PreferencesFactory;
+
+public class ThinPreferencesFactory implements PreferencesFactory {
+ private static CompletableFuture<ThinPreferencesFactory> INSTANCE = new CompletableFuture<>();
+
+ private SystemRootPreferences systemRootPreferences;
+
+ public ThinPreferencesFactory() {
+ systemRootPreferences = new SystemRootPreferences();
+ if (INSTANCE.isDone())
+ throw new IllegalStateException(
+ "There is already a " + ThinPreferencesFactory.class.getName() + " instance.");
+ INSTANCE.complete(this);
+ }
+
+ @Override
+ public Preferences systemRoot() {
+ return systemRootPreferences;
+ }
+
+ @Override
+ public Preferences userRoot() {
+ throw new UnsupportedOperationException();
+ }
+
+ public SystemRootPreferences getSystemRootPreferences() {
+ return systemRootPreferences;
+ }
+
+ public static ThinPreferencesFactory getInstance() {
+ try {
+ return INSTANCE.get();
+ } catch (InterruptedException | ExecutionException e) {
+ throw new IllegalStateException("Cannot get " + ThinPreferencesFactory.class.getName() + " instance.", e);
+ }
+ }
+}