summaryrefslogtreecommitdiffstats
path: root/container-core
diff options
context:
space:
mode:
authorgjoranv <gv@verizonmedia.com>2020-07-16 12:38:23 +0200
committergjoranv <gv@verizonmedia.com>2020-07-16 22:57:36 +0200
commitd9af1cf77bd1f283b930385c1e7af1cc4a11d807 (patch)
tree770a4d9bdeea86b8625755805c0806e48094f096 /container-core
parent59bba1e2040eb26e02175e64534ace04cd2a851c (diff)
Start platform bundles
- Extract BundleStarter class from ApplicationBundleLoader.
Diffstat (limited to 'container-core')
-rw-r--r--container-core/src/main/java/com/yahoo/container/core/config/ApplicationBundleLoader.java25
-rw-r--r--container-core/src/main/java/com/yahoo/container/core/config/BundleStarter.java40
-rw-r--r--container-core/src/main/java/com/yahoo/container/core/config/HandlersConfigurerDi.java2
-rw-r--r--container-core/src/main/java/com/yahoo/container/core/config/PlatformBundleLoader.java17
4 files changed, 55 insertions, 29 deletions
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<Bundle> 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<FileReference> 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<FileReference> bundlesToInstall) {
+ public void useBundles(List<FileReference> fileReferences) {
+ Set<Bundle> installedBundles = install(fileReferences);
+ BundleStarter.startBundles(installedBundles);
+ }
+
+ private Set<Bundle> install(List<FileReference> bundlesToInstall) {
+ var installedBundles = new LinkedHashSet<Bundle>();
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<Bundle> installBundleFromDisk(FileReference reference) {
log.info("Installing bundle from disk with reference '" + reference.value() + "'");
List<Bundle> bundles = installer.installBundles(reference, osgi);
log.fine("Installed " + bundles.size() + " bundles for file reference " + reference);
+ return bundles;
}
}