From d9af1cf77bd1f283b930385c1e7af1cc4a11d807 Mon Sep 17 00:00:00 2001 From: gjoranv Date: Thu, 16 Jul 2020 12:38:23 +0200 Subject: Start platform bundles - Extract BundleStarter class from ApplicationBundleLoader. --- .../core/config/ApplicationBundleLoader.java | 25 +------------- .../yahoo/container/core/config/BundleStarter.java | 40 ++++++++++++++++++++++ .../core/config/HandlersConfigurerDi.java | 2 +- .../core/config/PlatformBundleLoader.java | 17 ++++++--- 4 files changed, 55 insertions(+), 29 deletions(-) create mode 100644 container-core/src/main/java/com/yahoo/container/core/config/BundleStarter.java diff --git a/container-core/src/main/java/com/yahoo/container/core/config/ApplicationBundleLoader.java b/container-core/src/main/java/com/yahoo/container/core/config/ApplicationBundleLoader.java index e20fbd7b2ae..5236daf0302 100644 --- a/container-core/src/main/java/com/yahoo/container/core/config/ApplicationBundleLoader.java +++ b/container-core/src/main/java/com/yahoo/container/core/config/ApplicationBundleLoader.java @@ -58,7 +58,7 @@ public class ApplicationBundleLoader { removeInactiveFileReferences(obsoleteReferences); installBundles(newFileReferences); - startBundles(); + BundleStarter.startBundles(reference2Bundle.values()); log.info(installedBundlesMessage()); return bundlesToUninstall; @@ -120,29 +120,6 @@ public class ApplicationBundleLoader { } } - /** - * Resolves and starts (calls the Bundles BundleActivator) all bundles. Bundle resolution must take place - * after all bundles are installed to ensure that the framework can resolve dependencies between bundles. - */ - private void startBundles() { - for (var bundle : reference2Bundle.values()) { - try { - if ( ! isFragment(bundle)) - bundle.start(); // NOP for already ACTIVE bundles - } catch(Exception e) { - throw new RuntimeException("Could not start bundle '" + bundle.getSymbolicName() + "'", e); - } - } - } - - private boolean isFragment(Bundle bundle) { - BundleRevision bundleRevision = bundle.adapt(BundleRevision.class); - if (bundleRevision == null) - throw new NullPointerException("Null bundle revision means that bundle has probably been uninstalled: " + - bundle.getSymbolicName() + ":" + bundle.getVersion()); - return (bundleRevision.getTypes() & BundleRevision.TYPE_FRAGMENT) != 0; - } - private String installedBundlesMessage() { StringBuilder sb = new StringBuilder("Installed bundles: {" ); for (Bundle b : osgi.getBundles()) diff --git a/container-core/src/main/java/com/yahoo/container/core/config/BundleStarter.java b/container-core/src/main/java/com/yahoo/container/core/config/BundleStarter.java new file mode 100644 index 00000000000..4a87c27b990 --- /dev/null +++ b/container-core/src/main/java/com/yahoo/container/core/config/BundleStarter.java @@ -0,0 +1,40 @@ +package com.yahoo.container.core.config; + +import org.osgi.framework.Bundle; +import org.osgi.framework.wiring.BundleRevision; + +import java.util.Collection; + +/** + * Utility to start a collection of bundles. + * + * @author gjoranv + */ +public class BundleStarter { + + private BundleStarter() { } + + /** + * Resolves and starts (calls the Bundles BundleActivator) all bundles. Bundle resolution must take place + * after all bundles are installed to ensure that the framework can resolve dependencies between bundles. + */ + static void startBundles(Collection bundles) { + for (var bundle : bundles) { + try { + if ( ! isFragment(bundle)) + bundle.start(); // NOP for already ACTIVE bundles + } catch(Exception e) { + throw new RuntimeException("Could not start bundle '" + bundle.getSymbolicName() + "'", e); + } + } + } + + private static boolean isFragment(Bundle bundle) { + BundleRevision bundleRevision = bundle.adapt(BundleRevision.class); + if (bundleRevision == null) + throw new NullPointerException("Null bundle revision means that bundle has probably been uninstalled: " + + bundle.getSymbolicName() + ":" + bundle.getVersion()); + return (bundleRevision.getTypes() & BundleRevision.TYPE_FRAGMENT) != 0; + } + +} diff --git a/container-core/src/main/java/com/yahoo/container/core/config/HandlersConfigurerDi.java b/container-core/src/main/java/com/yahoo/container/core/config/HandlersConfigurerDi.java index 40470a9f096..80c39bef2cb 100644 --- a/container-core/src/main/java/com/yahoo/container/core/config/HandlersConfigurerDi.java +++ b/container-core/src/main/java/com/yahoo/container/core/config/HandlersConfigurerDi.java @@ -137,7 +137,7 @@ public class HandlersConfigurerDi { @Override public void installPlatformBundles(Collection bundles) { log.fine("Installing platform bundles."); - platformBundleLoader.install(bundles); + platformBundleLoader.useBundles(new ArrayList<>(bundles)); } @Override diff --git a/container-core/src/main/java/com/yahoo/container/core/config/PlatformBundleLoader.java b/container-core/src/main/java/com/yahoo/container/core/config/PlatformBundleLoader.java index 76f0b959a58..f922bc0cb25 100644 --- a/container-core/src/main/java/com/yahoo/container/core/config/PlatformBundleLoader.java +++ b/container-core/src/main/java/com/yahoo/container/core/config/PlatformBundleLoader.java @@ -4,8 +4,9 @@ import com.yahoo.config.FileReference; import com.yahoo.osgi.Osgi; import org.osgi.framework.Bundle; -import java.util.Collection; +import java.util.LinkedHashSet; import java.util.List; +import java.util.Set; import java.util.logging.Logger; /** @@ -25,21 +26,29 @@ public class PlatformBundleLoader { installer = new DiskBundleInstaller(); } - public void install(Collection bundlesToInstall) { + public void useBundles(List fileReferences) { + Set installedBundles = install(fileReferences); + BundleStarter.startBundles(installedBundles); + } + + private Set install(List bundlesToInstall) { + var installedBundles = new LinkedHashSet(); for (FileReference reference : bundlesToInstall) { try { - installBundleFromDisk(reference); + installedBundles.addAll(installBundleFromDisk(reference)); } catch(Exception e) { throw new RuntimeException("Could not install bundle '" + reference + "'", e); } } + return installedBundles; } - private void installBundleFromDisk(FileReference reference) { + private List installBundleFromDisk(FileReference reference) { log.info("Installing bundle from disk with reference '" + reference.value() + "'"); List bundles = installer.installBundles(reference, osgi); log.fine("Installed " + bundles.size() + " bundles for file reference " + reference); + return bundles; } } -- cgit v1.2.3