Make OSGi init more robust
authorMathieu Baudier <mbaudier@argeo.org>
Thu, 3 Nov 2022 08:05:47 +0000 (09:05 +0100)
committerMathieu Baudier <mbaudier@argeo.org>
Thu, 3 Nov 2022 08:05:47 +0000 (09:05 +0100)
org.argeo.init/src/org/argeo/init/a2/ProvisioningManager.java
org.argeo.init/src/org/argeo/init/osgi/OsgiBoot.java

index a237fdf48aecaa79349df7f0999c183c0e05a8e6..cbb296f4c1b780240ddd610ac3257fd8d8218476 100644 (file)
@@ -55,8 +55,8 @@ public class ProvisioningManager {
                                        updatedBundles.add(bundle);
                        }
                }
-               FrameworkWiring frameworkWiring = bc.getBundle(0).adapt(FrameworkWiring.class);
-               frameworkWiring.refreshBundles(updatedBundles);
+//             FrameworkWiring frameworkWiring = bc.getBundle(0).adapt(FrameworkWiring.class);
+//             frameworkWiring.refreshBundles(updatedBundles);
        }
 
        public void registerSource(String uri) {
index 9f3bd25f783df4908aaa4c6bd8bfffa8c200597e..223effb549c39799d6a34c2279f93cbe736ba0d7 100644 (file)
@@ -19,6 +19,7 @@ import java.util.Set;
 import java.util.SortedMap;
 import java.util.StringTokenizer;
 import java.util.TreeMap;
+import java.util.concurrent.ForkJoinPool;
 
 import org.argeo.init.a2.A2Source;
 import org.argeo.init.a2.ProvisioningManager;
@@ -357,6 +358,14 @@ public class OsgiBoot implements OsgiBootConstants {
                // default and active start levels from System properties
                Integer defaultStartLevel = Integer.parseInt(getProperty(PROP_OSGI_BUNDLES_DEFAULTSTARTLEVEL, "4"));
                Integer activeStartLevel = Integer.parseInt(getProperty(PROP_OSGI_STARTLEVEL, "6"));
+               if (OsgiBootUtils.isDebug()) {
+                       OsgiBootUtils.debug("OSGi default start level: "
+                                       + getProperty(PROP_OSGI_BUNDLES_DEFAULTSTARTLEVEL, "<not set>") + ", using " + defaultStartLevel);
+                       OsgiBootUtils.debug("OSGi active start level: " + getProperty(PROP_OSGI_STARTLEVEL, "<not set>")
+                                       + ", using " + activeStartLevel);
+                       OsgiBootUtils.debug("Framework start level: " + frameworkStartLevel.getStartLevel() + " (initial: "
+                                       + frameworkStartLevel.getInitialBundleStartLevel() + ")");
+               }
 
                SortedMap<Integer, List<String>> startLevels = new TreeMap<Integer, List<String>>();
                computeStartLevels(startLevels, properties, defaultStartLevel);
@@ -383,12 +392,21 @@ public class OsgiBoot implements OsgiBootConstants {
                                }
                        }
                }
-               frameworkStartLevel.setStartLevel(activeStartLevel, (FrameworkEvent event) -> {
-                       if (OsgiBootUtils.isDebug())
-                               OsgiBootUtils.debug("Framework event: " + event);
-                       int initialStartLevel = frameworkStartLevel.getInitialBundleStartLevel();
-                       int startLevel = frameworkStartLevel.getStartLevel();
-                       OsgiBootUtils.debug("Framework start level: " + startLevel + " (initial: " + initialStartLevel + ")");
+
+               if (OsgiBootUtils.isDebug())
+                       OsgiBootUtils.debug("About to set framework start level to " + activeStartLevel + " ...");
+
+               // Start the framework asynchronously
+               ForkJoinPool.commonPool().execute(() -> {
+                       frameworkStartLevel.setStartLevel(activeStartLevel, (FrameworkEvent event) -> {
+                               if (OsgiBootUtils.isDebug())
+                                       OsgiBootUtils.debug("Framework event: " + event);
+                               int initialStartLevel = frameworkStartLevel.getInitialBundleStartLevel();
+                               int startLevel = frameworkStartLevel.getStartLevel();
+                               if (OsgiBootUtils.isDebug())
+                                       OsgiBootUtils
+                                                       .debug("Framework start level: " + startLevel + " (initial: " + initialStartLevel + ")");
+                       });
                });
        }
 
@@ -666,6 +684,7 @@ public class OsgiBoot implements OsgiBootConstants {
        private void refreshFramework() {
                Bundle systemBundle = bundleContext.getBundle(0);
                FrameworkWiring frameworkWiring = systemBundle.adapt(FrameworkWiring.class);
+               // TODO deal with refresh breaking native loading (e.g SWT)
                frameworkWiring.refreshBundles(null);
        }