+ protected 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 loggerFinder = LoggerFinder.getLoggerFinder();
+
+ if (loggerFinder instanceof Consumer<?> && loggerFinder instanceof Supplier<?>) {
+ @SuppressWarnings("unchecked")
+ Consumer<Map<String, Object>> consumer = (Consumer<Map<String, Object>>) loggerFinder;
+ // ThinLoggerFinder.getConfigurationConsumer()
+ // ThinLoggerFinder.getLogEntryPublisher()
+
+ @SuppressWarnings("unchecked")
+ Supplier<Flow.Publisher<Map<String, Serializable>>> supplier = (Supplier<Flow.Publisher<Map<String, Serializable>>>) loggerFinder;
+ // logging
+ bundleContext.registerService(Consumer.class, consumer,
+ new Hashtable<>(Collections.singletonMap(Constants.SERVICE_PID, "argeo.logging.configuration")));
+ bundleContext.registerService(Flow.Publisher.class, supplier.get(),
+ new Hashtable<>(Collections.singletonMap(Constants.SERVICE_PID, "argeo.logging.publisher")));
+ }
+ OsgiBoot osgiBoot = new OsgiBoot(bundleContext);
+ String frameworkUuuid = bundleContext.getProperty(Constants.FRAMEWORK_UUID);
+
+ // separate thread in order to improve logging
+ Thread osgiBootThread = new Thread("OSGi boot framework " + frameworkUuuid) {
+ @Override
+ public void run() {
+ osgiBoot.bootstrap();
+ }
+ };
+ osgiBootThread.start();
+ // TODO return a completable stage so that inits can run in parallel
+// try {
+// osgiBootThread.join(60 * 1000);
+// } catch (InterruptedException e) {
+// // silent
+// }
+ }
+
+ public void update() {
+ stop();
+ try {
+ waitForStop(STOP_FOR_UPDATE_TIMEOUT);
+ } catch (InterruptedException e) {
+ logger.log(Level.TRACE, "Wait for stop interrupted", e);
+ }
+ run();
+
+ // TODO Optimise with OSGi mechanisms (e.g. framework.update())
+// if (osgiBoot != null) {
+// Objects.requireNonNull(osgiBoot);
+// osgiBoot.update();
+// }
+ }
+
+ protected void stop() {
+ if (framework == null)
+ return;
+ stop(framework.getBundleContext());
+ try {
+ framework.stop();
+ } catch (BundleException e) {
+ throw new IllegalStateException("Cannot stop OSGi framework", e);
+ }
+ }
+
+ protected void stop(BundleContext bundleContext) {
+// if (loggingConfigurationSr != null)
+// try {
+// loggingConfigurationSr.unregister();
+// } catch (Exception e) {
+// // silent
+// }
+// if (logEntryPublisherSr != null)
+// try {
+// logEntryPublisherSr.unregister();
+// } catch (Exception e) {
+// // silent
+// }
+ }
+