X-Git-Url: https://git.argeo.org/?a=blobdiff_plain;f=org.argeo.init%2Fsrc%2Forg%2Fargeo%2Finit%2Fosgi%2FOsgiBoot.java;h=c26fad66817c3b654f1ea0e965d9025e556f0c2d;hb=af52952e94d59bba22d0ac861e7777b60cf06c78;hp=9f3bd25f783df4908aaa4c6bd8bfffa8c200597e;hpb=c66685995c1bf2c59bdf6d68753470c85828310a;p=lgpl%2Fargeo-commons.git diff --git a/org.argeo.init/src/org/argeo/init/osgi/OsgiBoot.java b/org.argeo.init/src/org/argeo/init/osgi/OsgiBoot.java index 9f3bd25f7..c26fad668 100644 --- a/org.argeo.init/src/org/argeo/init/osgi/OsgiBoot.java +++ b/org.argeo.init/src/org/argeo/init/osgi/OsgiBoot.java @@ -19,6 +19,9 @@ import java.util.Set; import java.util.SortedMap; import java.util.StringTokenizer; import java.util.TreeMap; +import java.util.concurrent.CompletableFuture; +import java.util.concurrent.ExecutionException; +import java.util.concurrent.ForkJoinPool; import org.argeo.init.a2.A2Source; import org.argeo.init.a2.ProvisioningManager; @@ -355,8 +358,17 @@ public class OsgiBoot implements OsgiBootConstants { FrameworkStartLevel frameworkStartLevel = bundleContext.getBundle(0).adapt(FrameworkStartLevel.class); // 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")); + int initialStartLevel = frameworkStartLevel.getInitialBundleStartLevel(); + int defaultStartLevel = Integer.parseInt(getProperty(PROP_OSGI_BUNDLES_DEFAULTSTARTLEVEL, "4")); + int activeStartLevel = Integer.parseInt(getProperty(PROP_OSGI_STARTLEVEL, "6")); + if (OsgiBootUtils.isDebug()) { + OsgiBootUtils.debug("OSGi default start level: " + + getProperty(PROP_OSGI_BUNDLES_DEFAULTSTARTLEVEL, "") + ", using " + defaultStartLevel); + OsgiBootUtils.debug("OSGi active start level: " + getProperty(PROP_OSGI_STARTLEVEL, "") + + ", using " + activeStartLevel); + OsgiBootUtils.debug("Framework start level: " + frameworkStartLevel.getStartLevel() + " (initial: " + + initialStartLevel + ")"); + } SortedMap> startLevels = new TreeMap>(); computeStartLevels(startLevels, properties, defaultStartLevel); @@ -383,13 +395,31 @@ 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 level after level + stages: for (int stage = initialStartLevel; stage <= activeStartLevel; stage++) { + OsgiBootUtils.info("Starting stage " + stage + "..."); + final int nextStage = stage; + final CompletableFuture stageCompleted = new CompletableFuture<>(); + ForkJoinPool.commonPool().execute(() -> { + frameworkStartLevel.setStartLevel(nextStage, (FrameworkEvent event) -> { + stageCompleted.complete(event); + }); + }); + FrameworkEvent event; + try { + event = stageCompleted.get(); + } catch (InterruptedException | ExecutionException e) { + throw new IllegalStateException("Cannot continue start", e); + } + if (event.getThrowable() != null) { + OsgiBootUtils.error("Stage " + nextStage + " failed, aborting start.", event.getThrowable()); + break stages; + } + } } private static void computeStartLevels(SortedMap> startLevels, Map properties, @@ -666,6 +696,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); }