You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@karaf.apache.org by gn...@apache.org on 2014/04/22 14:32:24 UTC

[6/6] git commit: [KARAF-2888] Respect start level when starting and stopping bundles

[KARAF-2888] Respect start level when starting and stopping bundles


Project: http://git-wip-us.apache.org/repos/asf/karaf/repo
Commit: http://git-wip-us.apache.org/repos/asf/karaf/commit/e8023c6f
Tree: http://git-wip-us.apache.org/repos/asf/karaf/tree/e8023c6f
Diff: http://git-wip-us.apache.org/repos/asf/karaf/diff/e8023c6f

Branch: refs/heads/master
Commit: e8023c6ff4434b349483f2790a62370d3d1f2940
Parents: 6057a37
Author: Guillaume Nodet <gn...@gmail.com>
Authored: Tue Apr 22 10:13:30 2014 +0200
Committer: Guillaume Nodet <gn...@gmail.com>
Committed: Tue Apr 22 14:31:49 2014 +0200

----------------------------------------------------------------------
 .../karaf/features/internal/osgi/Activator.java |  3 --
 .../internal/service/FeaturesServiceImpl.java   | 29 ++++++++++++--------
 2 files changed, 18 insertions(+), 14 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/karaf/blob/e8023c6f/features/core/src/main/java/org/apache/karaf/features/internal/osgi/Activator.java
----------------------------------------------------------------------
diff --git a/features/core/src/main/java/org/apache/karaf/features/internal/osgi/Activator.java b/features/core/src/main/java/org/apache/karaf/features/internal/osgi/Activator.java
index 0551d21..b2cdd6e 100644
--- a/features/core/src/main/java/org/apache/karaf/features/internal/osgi/Activator.java
+++ b/features/core/src/main/java/org/apache/karaf/features/internal/osgi/Activator.java
@@ -121,9 +121,6 @@ public class Activator extends BaseActivator {
         register(ManagedService.class, featureFinder, props);
 
        FeatureConfigInstaller configInstaller = new FeatureConfigInstaller(configurationAdmin);
-        // TODO: honor respectStartLvlDuringFeatureStartup and respectStartLvlDuringFeatureUninstall
-//        boolean respectStartLvlDuringFeatureStartup = getBoolean("respectStartLvlDuringFeatureStartup", true);
-//        boolean respectStartLvlDuringFeatureUninstall = getBoolean("respectStartLvlDuringFeatureUninstall", true);
         String overrides = getString("overrides", new File(System.getProperty("karaf.etc"), "overrides.properties").toURI().toString());
         String featureResolutionRange = getString("featureResolutionRange", FeaturesServiceImpl.DEFAULT_FEATURE_RESOLUTION_RANGE);
         String bundleUpdateRange = getString("bundleUpdateRange", FeaturesServiceImpl.DEFAULT_BUNDLE_UPDATE_RANGE);

http://git-wip-us.apache.org/repos/asf/karaf/blob/e8023c6f/features/core/src/main/java/org/apache/karaf/features/internal/service/FeaturesServiceImpl.java
----------------------------------------------------------------------
diff --git a/features/core/src/main/java/org/apache/karaf/features/internal/service/FeaturesServiceImpl.java b/features/core/src/main/java/org/apache/karaf/features/internal/service/FeaturesServiceImpl.java
index 84b9529..ec5b55d 100644
--- a/features/core/src/main/java/org/apache/karaf/features/internal/service/FeaturesServiceImpl.java
+++ b/features/core/src/main/java/org/apache/karaf/features/internal/service/FeaturesServiceImpl.java
@@ -31,6 +31,7 @@ import java.util.LinkedHashSet;
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
+import java.util.SortedMap;
 import java.util.TreeMap;
 import java.util.TreeSet;
 import java.util.concurrent.Callable;
@@ -888,7 +889,6 @@ public class FeaturesServiceImpl implements FeaturesService {
         //
         // Compute deployment
         //
-        // TODO: compute bundles/region mapping to support multiple bundles and bunde moving into a different region
         Deployment deployment = computeDeployment(resolver, state);
 
         if (deployment.regions.isEmpty()) {
@@ -1469,19 +1469,22 @@ public class FeaturesServiceImpl implements FeaturesService {
     }
 
     protected List<Bundle> getBundlesToStart(Collection<Bundle> bundles) {
-        // TODO: make this pluggable ?
-        // TODO: honor respectStartLvlDuringFeatureStartup
+        // Restart the features service last, regardless of any other consideration
+        // so that we don't end up with the service trying to do stuff before we're done
+        boolean restart = bundles.remove(bundle);
+
+        SortedMap<Integer, Set<Bundle>> bundlesPerStartLevel = new TreeMap<Integer, Set<Bundle>>();
+        for (Bundle bundle : bundles) {
+            int sl = bundle.adapt(BundleStartLevel.class).getStartLevel();
+            addToMapSet(bundlesPerStartLevel, sl, bundle);
+        }
+        bundles = bundlesPerStartLevel.remove(bundlesPerStartLevel.firstKey());
 
         // We hit FELIX-2949 if we don't use the correct order as Felix resolver isn't greedy.
         // In order to minimize that, we make sure we resolve the bundles in the order they
         // are given back by the resolution, meaning that all root bundles (i.e. those that were
         // not flagged as dependencies in features) are started before the others.   This should
         // make sure those important bundles are started first and minimize the problem.
-
-        // Restart the features service last, regardless of any other consideration
-        // so that we don't end up with the service trying to do stuff before we're done
-        boolean restart = bundles.remove(bundle);
-
         List<BundleRevision> revs = new ArrayList<BundleRevision>();
         for (Bundle bundle : bundles) {
             revs.add(bundle.adapt(BundleRevision.class));
@@ -1490,15 +1493,19 @@ public class FeaturesServiceImpl implements FeaturesService {
         for (BundleRevision rev : RequirementSort.sort(revs)) {
             sorted.add(rev.getBundle());
         }
-        if (restart) {
+        if (sorted.isEmpty() && restart) {
             sorted.add(bundle);
         }
         return sorted;
     }
 
     protected List<Bundle> getBundlesToStop(Collection<Bundle> bundles) {
-        // TODO: make this pluggable ?
-        // TODO: honor respectStartLvlDuringFeatureUninstall
+        SortedMap<Integer, Set<Bundle>> bundlesPerStartLevel = new TreeMap<Integer, Set<Bundle>>();
+        for (Bundle bundle : bundles) {
+            int sl = bundle.adapt(BundleStartLevel.class).getStartLevel();
+            addToMapSet(bundlesPerStartLevel, sl, bundle);
+        }
+        bundles = bundlesPerStartLevel.get(bundlesPerStartLevel.lastKey());
 
         List<Bundle> bundlesToDestroy = new ArrayList<Bundle>();
         for (Bundle bundle : bundles) {