Repository: karaf-cellar
Updated Branches:
  refs/heads/cellar-3.0.x 5a599f19c -> f71624e5c


[KARAF-3981] Improve bundle synchronizer


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

Branch: refs/heads/cellar-3.0.x
Commit: 96d50bb8703a8194f7d685449aadb878fbc8f454
Parents: 5a599f1
Author: Jean-Baptiste Onofré <[email protected]>
Authored: Mon Sep 14 08:06:08 2015 +0200
Committer: Jean-Baptiste Onofré <[email protected]>
Committed: Mon Sep 14 08:06:08 2015 +0200

----------------------------------------------------------------------
 .../karaf/cellar/bundle/BundleEventHandler.java |  50 +++----
 .../karaf/cellar/bundle/BundleSupport.java      |  72 ++++++----
 .../karaf/cellar/bundle/BundleSynchronizer.java | 138 ++++++++++++-------
 .../cellar/bundle/LocalBundleListener.java      |  33 ++---
 .../internal/CellarBundleMBeanImpl.java         |  55 +++-----
 .../karaf/cellar/bundle/shell/BlockCommand.java | 126 +++++++++--------
 .../bundle/shell/BundleCommandSupport.java      |  23 +---
 .../bundle/shell/InstallBundleCommand.java      |  14 +-
 .../cellar/bundle/shell/ListBundleCommand.java  |  19 ++-
 .../cellar/bundle/shell/StartBundleCommand.java |   8 +-
 .../cellar/bundle/shell/StopBundleCommand.java  |   8 +-
 .../bundle/shell/UninstallBundleCommand.java    |   6 +-
 .../resources/OSGI-INF/blueprint/blueprint.xml  |   1 +
 .../karaf/cellar/hazelcast/QueueProducer.java   |   4 +-
 .../karaf/cellar/hazelcast/TopicProducer.java   |   4 +-
 15 files changed, 301 insertions(+), 260 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/karaf-cellar/blob/96d50bb8/bundle/src/main/java/org/apache/karaf/cellar/bundle/BundleEventHandler.java
----------------------------------------------------------------------
diff --git 
a/bundle/src/main/java/org/apache/karaf/cellar/bundle/BundleEventHandler.java 
b/bundle/src/main/java/org/apache/karaf/cellar/bundle/BundleEventHandler.java
index 43a8c51..468ba29 100644
--- 
a/bundle/src/main/java/org/apache/karaf/cellar/bundle/BundleEventHandler.java
+++ 
b/bundle/src/main/java/org/apache/karaf/cellar/bundle/BundleEventHandler.java
@@ -20,7 +20,7 @@ import org.apache.karaf.cellar.core.control.SwitchStatus;
 import org.apache.karaf.cellar.core.event.EventHandler;
 import org.apache.karaf.cellar.core.event.EventType;
 import org.apache.karaf.features.Feature;
-import org.osgi.framework.BundleEvent;
+import org.osgi.framework.Bundle;
 import org.osgi.framework.BundleException;
 import org.osgi.service.cm.Configuration;
 import org.slf4j.Logger;
@@ -38,7 +38,7 @@ public class BundleEventHandler extends BundleSupport 
implements EventHandler<Cl
     public static final String SWITCH_ID = 
"org.apache.karaf.cellar.bundle.handler";
 
     private final Switch eventSwitch = new BasicSwitch(SWITCH_ID);
-    
+
     /**
      * Handle received bundle cluster events.
      *
@@ -52,11 +52,11 @@ public class BundleEventHandler extends BundleSupport 
implements EventHandler<Cl
             LOGGER.debug("CELLAR BUNDLE: {} switch is OFF, cluster event is 
not handled", SWITCH_ID);
             return;
         }
-        
+
         if (groupManager == null) {
-               //in rare cases for example right after installation this 
happens!
-               LOGGER.error("CELLAR BUNDLE: retrieved event {} while 
groupManager is not available yet!", event);
-               return;
+            //in rare cases for example right after installation this happens!
+            LOGGER.error("CELLAR BUNDLE: retrieved event {} while groupManager 
is not available yet!", event);
+            return;
         }
 
         // check if the group is local
@@ -66,37 +66,39 @@ public class BundleEventHandler extends BundleSupport 
implements EventHandler<Cl
         }
 
         try {
-            // check if the pid is marked as local.
+            // check if it's not a "local" event
+            if (event.getSourceNode() != null && 
event.getSourceNode().getId().equalsIgnoreCase(clusterManager.getNode().getId()))
 {
+                LOGGER.debug("CELLAR BUNDLE: cluster event is local (coming 
from local synchronizer or listener)");
+                return;
+            }
             if (isAllowed(event.getSourceGroup(), Constants.CATEGORY, 
event.getLocation(), EventType.INBOUND)) {
-               // check the features first
-               List<Feature> matchingFeatures = 
retrieveFeature(event.getLocation());
-               for (Feature feature : matchingFeatures) {
-                                       if (!isAllowed(event.getSourceGroup(), 
"features", feature.getName(), EventType.INBOUND)) {
-                                               LOGGER.trace("CELLAR BUNDLE: 
bundle {} is contained in feature {} marked BLOCKED INBOUND for cluster group 
{}", event.getLocation(), feature.getName(), event.getSourceGroup().getName());
-                                               return;
-                                       }
-                               }
-                if (event.getType() == BundleEvent.INSTALLED) {
+                // check the features first
+                List<Feature> matchingFeatures = 
retrieveFeature(event.getLocation());
+                for (Feature feature : matchingFeatures) {
+                    if (!isAllowed(event.getSourceGroup(), "features", 
feature.getName(), EventType.INBOUND)) {
+                        LOGGER.trace("CELLAR BUNDLE: bundle {} is contained in 
feature {} marked BLOCKED INBOUND for cluster group {}", event.getLocation(), 
feature.getName(), event.getSourceGroup().getName());
+                        return;
+                    }
+                }
+                if (event.getType() == Bundle.INSTALLED) {
                     installBundleFromLocation(event.getLocation());
                     LOGGER.debug("CELLAR BUNDLE: installing {}/{}", 
event.getSymbolicName(), event.getVersion());
-                } else if (event.getType() == BundleEvent.UNINSTALLED) {
+                } else if (event.getType() == Bundle.UNINSTALLED) {
                     uninstallBundle(event.getSymbolicName(), 
event.getVersion());
                     LOGGER.debug("CELLAR BUNDLE: uninstalling {}/{}", 
event.getSymbolicName(), event.getVersion());
-                } else if (event.getType() == BundleEvent.STARTED) {
+                } else if (event.getType() == Bundle.ACTIVE) {
                     startBundle(event.getSymbolicName(), event.getVersion());
                     LOGGER.debug("CELLAR BUNDLE: starting {}/{}", 
event.getSymbolicName(), event.getVersion());
-                } else if (event.getType() == BundleEvent.STOPPED) {
+                } else if (event.getType() == Bundle.RESOLVED) {
                     stopBundle(event.getSymbolicName(), event.getVersion());
                     LOGGER.debug("CELLAR BUNDLE: stopping {}/{}", 
event.getSymbolicName(), event.getVersion());
-                } else if (event.getType() == BundleEvent.UPDATED) {
-                    updateBundle(event.getSymbolicName(), event.getVersion());
-                    LOGGER.debug("CELLAR BUNDLE: updating {}/{}", 
event.getSymbolicName(), event.getVersion());
                 }
-            } else LOGGER.trace("CELLAR BUNDLE: bundle {} is marked BLOCKED 
INBOUND for cluster group {}", event.getSymbolicName(), 
event.getSourceGroup().getName());
+            } else
+                LOGGER.trace("CELLAR BUNDLE: bundle {} is marked BLOCKED 
INBOUND for cluster group {}", event.getSymbolicName(), 
event.getSourceGroup().getName());
         } catch (BundleException e) {
             LOGGER.error("CELLAR BUNDLE: failed to install bundle {}/{}.", new 
Object[]{event.getSymbolicName(), event.getVersion()}, e);
         } catch (Exception e) {
-               LOGGER.error("CELLAR BUNDLE: failed to handle bundle event", e);
+            LOGGER.error("CELLAR BUNDLE: failed to handle bundle event", e);
         }
     }
 

http://git-wip-us.apache.org/repos/asf/karaf-cellar/blob/96d50bb8/bundle/src/main/java/org/apache/karaf/cellar/bundle/BundleSupport.java
----------------------------------------------------------------------
diff --git 
a/bundle/src/main/java/org/apache/karaf/cellar/bundle/BundleSupport.java 
b/bundle/src/main/java/org/apache/karaf/cellar/bundle/BundleSupport.java
index da649cc..23fb02d 100644
--- a/bundle/src/main/java/org/apache/karaf/cellar/bundle/BundleSupport.java
+++ b/bundle/src/main/java/org/apache/karaf/cellar/bundle/BundleSupport.java
@@ -30,7 +30,27 @@ import java.util.List;
 public class BundleSupport extends CellarSupport {
 
     protected BundleContext bundleContext;
-       private FeaturesService featuresService;
+    private FeaturesService featuresService;
+
+    public boolean isInstalled(String location) {
+        Bundle[] bundles = getBundleContext().getBundles();
+        for (Bundle bundle : bundles) {
+            if (bundle.getLocation().equals(location)) {
+                return true;
+            }
+        }
+        return false;
+    }
+
+    public boolean isStarted(String location) {
+        Bundle[] bundles = getBundleContext().getBundles();
+        for (Bundle bundle : bundles) {
+            if (bundle.getLocation().equals(location) && (bundle.getState() == 
Bundle.ACTIVE)) {
+                return true;
+            }
+        }
+        return false;
+    }
 
     /**
      * Locally install a bundle.
@@ -46,7 +66,7 @@ public class BundleSupport extends CellarSupport {
      * Locally uninstall a bundle.
      *
      * @param symbolicName the bundle symbolic name.
-     * @param version the bundle version.
+     * @param version      the bundle version.
      * @throws BundleException in case of un-installation failure.
      */
     public void uninstallBundle(String symbolicName, String version) throws 
BundleException {
@@ -64,7 +84,7 @@ public class BundleSupport extends CellarSupport {
      * Locally start a bundle.
      *
      * @param symbolicName the bundle symbolic name.
-     * @param version the bundle version.
+     * @param version      the bundle version.
      * @throws BundleException in case of start failure.
      */
     public void startBundle(String symbolicName, String version) throws 
BundleException {
@@ -82,7 +102,7 @@ public class BundleSupport extends CellarSupport {
      * Locally stop a bundle.
      *
      * @param symbolicName the bundle symbolic name.
-     * @param version the bundle version.
+     * @param version      the bundle version.
      * @throws BundleException in case of stop failure.
      */
     public void stopBundle(String symbolicName, String version) throws 
BundleException {
@@ -100,7 +120,7 @@ public class BundleSupport extends CellarSupport {
      * Locally update a bundle.
      *
      * @param symbolicName the bundle symbolic name.
-     * @param version the bundle version.
+     * @param version      the bundle version.
      * @throws BundleException in case of update failure.
      */
     public void updateBundle(String symbolicName, String version) throws 
BundleException {
@@ -121,21 +141,21 @@ public class BundleSupport extends CellarSupport {
      * @return the list of feature where the bundle is present.
      * @throws Exception in case of retrieval failure.
      */
-       protected List<Feature> retrieveFeature(String bundleLocation) throws 
Exception {
-               Feature[] features = featuresService.listFeatures();
-               List<Feature> matchingFeatures = new ArrayList<Feature>();
-               for (Feature feature : features) {
-                       List<BundleInfo> bundles = feature.getBundles();
-                       for (BundleInfo bundleInfo : bundles) {
-                               String location = bundleInfo.getLocation();
-                               if (location.equalsIgnoreCase(bundleLocation)) {
-                                       matchingFeatures.add(feature);
-                                       LOGGER.debug("CELLAR BUNDLE: found a 
feature {} containing bundle {}", feature.getName(), bundleLocation);
-                               }
-                       }
-               }
-               return matchingFeatures;
-       }
+    protected List<Feature> retrieveFeature(String bundleLocation) throws 
Exception {
+        Feature[] features = featuresService.listFeatures();
+        List<Feature> matchingFeatures = new ArrayList<Feature>();
+        for (Feature feature : features) {
+            List<BundleInfo> bundles = feature.getBundles();
+            for (BundleInfo bundleInfo : bundles) {
+                String location = bundleInfo.getLocation();
+                if (location.equalsIgnoreCase(bundleLocation)) {
+                    matchingFeatures.add(feature);
+                    LOGGER.debug("CELLAR BUNDLE: found a feature {} containing 
bundle {}", feature.getName(), bundleLocation);
+                }
+            }
+        }
+        return matchingFeatures;
+    }
 
     public BundleContext getBundleContext() {
         return this.bundleContext;
@@ -145,12 +165,12 @@ public class BundleSupport extends CellarSupport {
         this.bundleContext = bundleContext;
     }
 
-       public FeaturesService getFeaturesService() {
-               return featuresService;
-       }
+    public FeaturesService getFeaturesService() {
+        return featuresService;
+    }
 
-       public void setFeaturesService(FeaturesService featureService) {
-               this.featuresService = featureService;
-       }
+    public void setFeaturesService(FeaturesService featureService) {
+        this.featuresService = featureService;
+    }
 
 }

http://git-wip-us.apache.org/repos/asf/karaf-cellar/blob/96d50bb8/bundle/src/main/java/org/apache/karaf/cellar/bundle/BundleSynchronizer.java
----------------------------------------------------------------------
diff --git 
a/bundle/src/main/java/org/apache/karaf/cellar/bundle/BundleSynchronizer.java 
b/bundle/src/main/java/org/apache/karaf/cellar/bundle/BundleSynchronizer.java
index b8278e2..9722a20 100644
--- 
a/bundle/src/main/java/org/apache/karaf/cellar/bundle/BundleSynchronizer.java
+++ 
b/bundle/src/main/java/org/apache/karaf/cellar/bundle/BundleSynchronizer.java
@@ -16,12 +16,10 @@ package org.apache.karaf.cellar.bundle;
 import org.apache.karaf.cellar.core.Configurations;
 import org.apache.karaf.cellar.core.Group;
 import org.apache.karaf.cellar.core.Synchronizer;
-import org.apache.karaf.cellar.core.control.SwitchStatus;
 import org.apache.karaf.cellar.core.event.EventProducer;
 import org.apache.karaf.cellar.core.event.EventType;
 import org.osgi.framework.Bundle;
 import org.osgi.framework.BundleContext;
-import org.osgi.framework.BundleEvent;
 import org.osgi.framework.BundleException;
 import org.osgi.framework.BundleReference;
 import org.osgi.service.cm.Configuration;
@@ -41,7 +39,15 @@ public class BundleSynchronizer extends BundleSupport 
implements Synchronizer {
 
     private static final transient Logger LOGGER = 
LoggerFactory.getLogger(BundleSynchronizer.class);
 
+    private EventProducer eventProducer;
+
+    public void setEventProducer(EventProducer eventProducer) {
+        this.eventProducer = eventProducer;
+    }
+
     public void init() {
+        if (groupManager == null)
+            return;
         Set<Group> groups = groupManager.listLocalGroups();
         if (groups != null && !groups.isEmpty()) {
             for (Group group : groups) {
@@ -62,19 +68,32 @@ public class BundleSynchronizer extends BundleSupport 
implements Synchronizer {
     @Override
     public void sync(Group group) {
         String policy = getSyncPolicy(group);
-        if (policy != null && policy.equalsIgnoreCase("cluster")) {
-            LOGGER.debug("CELLAR BUNDLE: sync policy is set as 'cluster' for 
cluster group " + group.getName());
-            if (clusterManager.listNodesByGroup(group).size() == 1 && 
clusterManager.listNodesByGroup(group).contains(clusterManager.getNode())) {
-                LOGGER.debug("CELLAR BUNDLE: node is the first and only member 
of the group, pushing state");
-                push(group);
-            } else {
-                LOGGER.debug("CELLAR BUNDLE: pulling state");
-                pull(group);
-            }
+        if (policy == null) {
+            LOGGER.warn("CELLAR BUNDLE: sync policy is not defined for cluster 
group " + group.getName());
         }
-        if (policy != null && policy.equalsIgnoreCase("node")) {
-            LOGGER.debug("CELLAR BUNDLE: sync policy is set as 'node' for 
cluster group " + group.getName());
+        if (policy.equalsIgnoreCase("cluster")) {
+            LOGGER.debug("CELLAR BUNDLE: sync policy set as 'cluster' for 
cluster group " + group.getName());
+            LOGGER.debug("CELLAR BUNDLE: updating node from the cluster (pull 
first)");
+            pull(group);
+            LOGGER.debug("CELLAR BUNDLE: updating cluster from the local node 
(push after)");
             push(group);
+        } else if (policy.equalsIgnoreCase("node")) {
+            LOGGER.debug("CELLAR BUNDLE: sync policy set as 'node' for cluster 
group " + group.getName());
+            LOGGER.debug("CELLAR BUNDLE: updating cluster from the local node 
(push first)");
+            push(group);
+            LOGGER.debug("CELLAR BUNDLE: updating node from the cluster (pull 
after)");
+            pull(group);
+        } else if (policy.equalsIgnoreCase("clusterOnly")) {
+            LOGGER.debug("CELLAR BUNDLE: sync policy set as 'clusterOnly' for 
cluster group " + group.getName());
+            LOGGER.debug("CELLAR BUNDLE: updating node from the cluster (pull 
only)");
+            pull(group);
+        } else if (policy.equalsIgnoreCase("nodeOnly")) {
+            LOGGER.debug("CELLAR BUNDLE: sync policy set as 'nodeOnly' for 
cluster group " + group.getName());
+            LOGGER.debug("CELLAR BUNDLE: updating cluster from the local node 
(push only)");
+            push(group);
+        } else {
+            LOGGER.debug("CELLAR BUNDLE: sync policy set as 'disabled' for 
cluster group " + group.getName());
+            LOGGER.debug("CELLAR BUNDLE: no sync");
         }
     }
 
@@ -106,11 +125,24 @@ public class BundleSynchronizer extends BundleSupport 
implements Synchronizer {
                             String bundleLocation = state.getLocation();
                             if (isAllowed(group, Constants.CATEGORY, 
bundleLocation, EventType.INBOUND)) {
                                 try {
-                                    if (state.getStatus() == 
BundleEvent.INSTALLED) {
-                                        
installBundleFromLocation(state.getLocation());
-                                    } else if (state.getStatus() == 
BundleEvent.STARTED) {
-                                        
installBundleFromLocation(state.getLocation());
-                                        startBundle(symbolicName, version);
+                                    if (state.getStatus() == Bundle.INSTALLED) 
{
+                                        if (!isInstalled(state.getLocation())) 
{
+                                            LOGGER.debug("CELLAR BUNDLE: 
installing bundle located {}", state.getLocation());
+                                            
installBundleFromLocation(state.getLocation());
+                                        } else {
+                                            LOGGER.debug("CELLAR BUNDLE: 
bundle located {} already installed on node", state.getLocation());
+                                        }
+                                    } else if (state.getStatus() == 
Bundle.ACTIVE) {
+                                        if (!isInstalled(state.getLocation())) 
{
+                                            LOGGER.debug("CELLAR BUNDLE: 
installing bundle located {}", state.getLocation());
+                                            
installBundleFromLocation(state.getLocation());
+                                        }
+                                        if (!isStarted(state.getLocation())) {
+                                            LOGGER.debug("CELLAR BUNDLE: 
starting bundle {}/{}", symbolicName, version);
+                                            startBundle(symbolicName, version);
+                                        } else {
+                                            LOGGER.debug("CELLAR BUNDLE: 
bundle located {} already started on node", state.getLocation());
+                                        }
                                     }
                                 } catch (BundleException e) {
                                     LOGGER.error("CELLAR BUNDLE: failed to 
pull bundle {}", id, e);
@@ -148,43 +180,49 @@ public class BundleSynchronizer extends BundleSupport 
implements Synchronizer {
                 for (Bundle bundle : bundles) {
                     long bundleId = bundle.getBundleId();
                     String symbolicName = bundle.getSymbolicName();
-                    String version = bundle.getVersion().toString();
+                    String version = 
bundle.getHeaders().get(org.osgi.framework.Constants.BUNDLE_VERSION);
                     String bundleLocation = bundle.getLocation();
                     int status = bundle.getState();
                     String id = symbolicName + "/" + version;
 
                     // check if the pid is marked as local.
                     if (isAllowed(group, Constants.CATEGORY, bundleLocation, 
EventType.OUTBOUND)) {
-
-                        BundleState bundleState = new BundleState();
-                        // get the bundle name or location.
-                        String name = (String) 
bundle.getHeaders().get(org.osgi.framework.Constants.BUNDLE_NAME);
-                        // if there is no name, then default to symbolic name.
-                        name = (name == null) ? symbolicName : name;
-                        // if there is no symbolic name, resort to location.
-                        name = (name == null) ? bundle.getLocation() : name;
-                        bundleState.setId(bundleId);
-                        bundleState.setName(name);
-                        bundleState.setSymbolicName(symbolicName);
-                        bundleState.setVersion(version);
-                        bundleState.setLocation(bundleLocation);
-
-                        if (status == Bundle.ACTIVE)
-                            status = BundleEvent.STARTED;
-                        if (status == Bundle.INSTALLED)
-                            status = BundleEvent.INSTALLED;
-                        if (status == Bundle.RESOLVED)
-                            status = BundleEvent.RESOLVED;
-                        if (status == Bundle.STARTING)
-                            status = BundleEvent.STARTING;
-                        if (status == Bundle.UNINSTALLED)
-                            status = BundleEvent.UNINSTALLED;
-                        if (status == Bundle.STOPPING)
-                            status = BundleEvent.STARTED;
-
-                        bundleState.setStatus(status);
-
-                        clusterBundles.put(id, bundleState);
+                        if (!clusterBundles.containsKey(id)) {
+                            LOGGER.debug("CELLAR BUNDLE: deploying bundle {} 
on the cluster", id);
+                            BundleState bundleState = new BundleState();
+                            // get the bundle name or location.
+                            String name = (String) 
bundle.getHeaders().get(org.osgi.framework.Constants.BUNDLE_NAME);
+                            // if there is no name, then default to symbolic 
name.
+                            name = (name == null) ? symbolicName : name;
+                            // if there is no symbolic name, resort to 
location.
+                            name = (name == null) ? bundle.getLocation() : 
name;
+                            bundleState.setId(bundleId);
+                            bundleState.setName(name);
+                            bundleState.setSymbolicName(symbolicName);
+                            bundleState.setVersion(version);
+                            bundleState.setLocation(bundleLocation);
+                            bundleState.setStatus(status);
+                            // update cluster state
+                            clusterBundles.put(id, bundleState);
+                            // send cluster event
+                            ClusterBundleEvent clusterEvent = new 
ClusterBundleEvent(symbolicName, version, bundleLocation, status);
+                            clusterEvent.setSourceGroup(group);
+                            
clusterEvent.setSourceNode(clusterManager.getNode());
+                            eventProducer.produce(clusterEvent);
+                        } else {
+                            BundleState bundleState = clusterBundles.get(id);
+                            if (bundleState.getStatus() != status) {
+                                LOGGER.debug("CELLAR BUNDLE: updating bundle 
{} on the cluster", id);
+                                // update cluster state
+                                bundleState.setStatus(status);
+                                clusterBundles.put(id, bundleState);
+                                // send cluster event
+                                ClusterBundleEvent clusterEvent = new 
ClusterBundleEvent(symbolicName, version, bundleLocation, status);
+                                clusterEvent.setSourceGroup(group);
+                                
clusterEvent.setSourceNode(clusterManager.getNode());
+                                eventProducer.produce(clusterEvent);
+                            }
+                        }
 
                     } else LOGGER.trace("CELLAR BUNDLE: bundle {} is marked 
BLOCKED OUTBOUND for cluster group {}", bundleLocation, groupName);
                 }
@@ -217,4 +255,4 @@ public class BundleSynchronizer extends BundleSupport 
implements Synchronizer {
         return "disabled";
     }
 
-}
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/karaf-cellar/blob/96d50bb8/bundle/src/main/java/org/apache/karaf/cellar/bundle/LocalBundleListener.java
----------------------------------------------------------------------
diff --git 
a/bundle/src/main/java/org/apache/karaf/cellar/bundle/LocalBundleListener.java 
b/bundle/src/main/java/org/apache/karaf/cellar/bundle/LocalBundleListener.java
index 39c2f56..9d9cfcf 100644
--- 
a/bundle/src/main/java/org/apache/karaf/cellar/bundle/LocalBundleListener.java
+++ 
b/bundle/src/main/java/org/apache/karaf/cellar/bundle/LocalBundleListener.java
@@ -55,7 +55,7 @@ public class LocalBundleListener extends BundleSupport 
implements SynchronousBun
         }
 
         if (!isEnabled()) {
-            LOGGER.debug("CELLAR BUNDLE: local listener is disabled");
+            LOGGER.trace("CELLAR BUNDLE: local listener is disabled");
             return;
         }
 
@@ -89,7 +89,7 @@ public class LocalBundleListener extends BundleSupport 
implements SynchronousBun
                     String symbolicName = event.getBundle().getSymbolicName();
                     String version = 
event.getBundle().getHeaders().get(org.osgi.framework.Constants.BUNDLE_VERSION);
                     String bundleLocation = event.getBundle().getLocation();
-                    int type = event.getType();
+                    int status = event.getBundle().getState();
 
                     if (isAllowed(group, Constants.CATEGORY, bundleLocation, 
EventType.OUTBOUND)) {
 
@@ -99,7 +99,7 @@ public class LocalBundleListener extends BundleSupport 
implements SynchronousBun
                         try {
                             // update bundles in the cluster group
                             Map<String, BundleState> clusterBundles = 
clusterManager.getMap(Constants.BUNDLE_MAP + Configurations.SEPARATOR + 
group.getName());
-                            if (type == BundleEvent.UNINSTALLED) {
+                            if (event.getType() == BundleEvent.UNINSTALLED) {
                                 clusterBundles.remove(symbolicName + "/" + 
version);
                             } else {
                                 BundleState state = 
clusterBundles.get(symbolicName + "/" + version);
@@ -110,27 +110,28 @@ public class LocalBundleListener extends BundleSupport 
implements SynchronousBun
                                 state.setName(name);
                                 state.setVersion(version);
                                 state.setSymbolicName(symbolicName);
-                                state.setStatus(type);
+                                state.setStatus(status);
                                 state.setLocation(bundleLocation);
                                 clusterBundles.put(symbolicName + "/" + 
version, state);
                             }
 
                             // check the features first
-                               List<Feature> matchingFeatures = 
retrieveFeature(bundleLocation);
-                               for (Feature feature : matchingFeatures) {
-                                               if (!isAllowed(group, 
"features", feature.getName(), EventType.OUTBOUND)) {
-                                                       LOGGER.trace("CELLAR 
BUNDLE: bundle {} is contained in feature {} marked BLOCKED OUTBOUND for 
cluster group {}", bundleLocation, feature.getName(), group.getName());
-                                                       return;
-                                               }
-                                       }
-                            
+                            List<Feature> matchingFeatures = 
retrieveFeature(bundleLocation);
+                            for (Feature feature : matchingFeatures) {
+                                if (!isAllowed(group, "features", 
feature.getName(), EventType.OUTBOUND)) {
+                                    LOGGER.trace("CELLAR BUNDLE: bundle {} is 
contained in feature {} marked BLOCKED OUTBOUND for cluster group {}", 
bundleLocation, feature.getName(), group.getName());
+                                    return;
+                                }
+                            }
+
                             // broadcast the cluster event
-                            ClusterBundleEvent clusterBundleEvent = new 
ClusterBundleEvent(symbolicName, version, bundleLocation, type);
+                            ClusterBundleEvent clusterBundleEvent = new 
ClusterBundleEvent(symbolicName, version, bundleLocation, status);
                             clusterBundleEvent.setSourceGroup(group);
+                            
clusterBundleEvent.setSourceNode(clusterManager.getNode());
                             eventProducer.produce(clusterBundleEvent);
                         } catch (Exception e) {
-                               LOGGER.error("CELLAR BUNDLE: failed to create 
bundle event", e);
-                                               } finally {
+                            LOGGER.error("CELLAR BUNDLE: failed to create 
bundle event", e);
+                        } finally {
                             
Thread.currentThread().setContextClassLoader(originalClassLoader);
                         }
 
@@ -175,4 +176,4 @@ public class LocalBundleListener extends BundleSupport 
implements SynchronousBun
         this.eventProducer = eventProducer;
     }
 
-}
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/karaf-cellar/blob/96d50bb8/bundle/src/main/java/org/apache/karaf/cellar/bundle/management/internal/CellarBundleMBeanImpl.java
----------------------------------------------------------------------
diff --git 
a/bundle/src/main/java/org/apache/karaf/cellar/bundle/management/internal/CellarBundleMBeanImpl.java
 
b/bundle/src/main/java/org/apache/karaf/cellar/bundle/management/internal/CellarBundleMBeanImpl.java
index 231aa73..44cdacf 100644
--- 
a/bundle/src/main/java/org/apache/karaf/cellar/bundle/management/internal/CellarBundleMBeanImpl.java
+++ 
b/bundle/src/main/java/org/apache/karaf/cellar/bundle/management/internal/CellarBundleMBeanImpl.java
@@ -16,16 +16,13 @@ package org.apache.karaf.cellar.bundle.management.internal;
 import org.apache.karaf.cellar.bundle.BundleState;
 import org.apache.karaf.cellar.bundle.ClusterBundleEvent;
 import org.apache.karaf.cellar.bundle.Constants;
-import org.apache.karaf.cellar.bundle.shell.BundleCommandSupport;
 import org.apache.karaf.cellar.core.*;
-import org.apache.karaf.cellar.core.control.ManageGroupAction;
 import org.apache.karaf.cellar.core.control.SwitchStatus;
 import org.apache.karaf.cellar.core.event.EventProducer;
 import org.apache.karaf.cellar.core.event.EventType;
 import org.apache.karaf.cellar.bundle.management.CellarBundleMBean;
 import org.osgi.framework.Bundle;
 import org.osgi.framework.BundleContext;
-import org.osgi.framework.BundleEvent;
 import org.osgi.service.cm.ConfigurationAdmin;
 
 import javax.management.NotCompliantMBeanException;
@@ -149,9 +146,9 @@ public class CellarBundleMBeanImpl extends StandardMBean 
implements CellarBundle
             state.setId(clusterBundles.size());
             state.setLocation(location);
             if (start) {
-                state.setStatus(BundleEvent.STARTED);
+                state.setStatus(Bundle.ACTIVE);
             } else {
-                state.setStatus(BundleEvent.INSTALLED);
+                state.setStatus(Bundle.INSTALLED);
             }
             clusterBundles.put(symbolicName + "/" + version, state);
         } finally {
@@ -159,10 +156,10 @@ public class CellarBundleMBeanImpl extends StandardMBean 
implements CellarBundle
         }
 
         // broadcast the event
-        ClusterBundleEvent event = new ClusterBundleEvent(symbolicName, 
version, location, BundleEvent.INSTALLED);
+        ClusterBundleEvent event = new ClusterBundleEvent(symbolicName, 
version, location, Bundle.INSTALLED);
         event.setSourceGroup(group);
         if (start) {
-            event = new ClusterBundleEvent(symbolicName, version, location, 
BundleEvent.STARTED);
+            event = new ClusterBundleEvent(symbolicName, version, location, 
Bundle.ACTIVE);
             event.setSourceGroup(group);
         }
         eventProducer.produce(event);
@@ -212,7 +209,7 @@ public class CellarBundleMBeanImpl extends StandardMBean 
implements CellarBundle
 
                 // broadcast the cluster event
                 String[] split = bundle.split("/");
-                ClusterBundleEvent event = new ClusterBundleEvent(split[0], 
split[1], location, BundleEvent.UNINSTALLED);
+                ClusterBundleEvent event = new ClusterBundleEvent(split[0], 
split[1], location, Bundle.UNINSTALLED);
                 event.setSourceGroup(group);
                 eventProducer.produce(event);
             }
@@ -263,12 +260,12 @@ public class CellarBundleMBeanImpl extends StandardMBean 
implements CellarBundle
                 }
 
                 // update the cluster state
-                state.setStatus(BundleEvent.STARTED);
+                state.setStatus(Bundle.ACTIVE);
                 clusterBundles.put(bundle, state);
 
                 // broadcast the cluster event
                 String[] split = bundle.split("/");
-                ClusterBundleEvent event = new ClusterBundleEvent(split[0], 
split[1], location, BundleEvent.STARTED);
+                ClusterBundleEvent event = new ClusterBundleEvent(split[0], 
split[1], location, Bundle.ACTIVE);
                 event.setSourceGroup(group);
                 eventProducer.produce(event);
             }
@@ -316,12 +313,12 @@ public class CellarBundleMBeanImpl extends StandardMBean 
implements CellarBundle
                 }
 
                 // update the cluster state
-                state.setStatus(BundleEvent.STOPPED);
+                state.setStatus(Bundle.RESOLVED);
                 clusterBundles.put(bundle, state);
 
                 // broadcast the cluster event
                 String[] split = bundle.split("/");
-                ClusterBundleEvent event = new ClusterBundleEvent(split[0], 
split[1], location, BundleEvent.STOPPED);
+                ClusterBundleEvent event = new ClusterBundleEvent(split[0], 
split[1], location, Bundle.RESOLVED);
                 event.setSourceGroup(group);
                 eventProducer.produce(event);
             }
@@ -396,25 +393,22 @@ public class CellarBundleMBeanImpl extends StandardMBean 
implements CellarBundle
             for (ExtendedBundleState bundle : bundles) {
                 String status;
                 switch (bundle.getStatus()) {
-                    case BundleEvent.INSTALLED:
+                    case Bundle.INSTALLED:
                         status = "Installed";
                         break;
-                    case BundleEvent.RESOLVED:
+                    case Bundle.RESOLVED:
                         status = "Resolved";
                         break;
-                    case BundleEvent.STARTED:
+                    case Bundle.ACTIVE:
                         status = "Active";
                         break;
-                    case BundleEvent.STARTING:
+                    case Bundle.STARTING:
                         status = "Starting";
                         break;
-                    case BundleEvent.STOPPED:
-                        status = "Resolved";
-                        break;
-                    case BundleEvent.STOPPING:
+                    case Bundle.STOPPING:
                         status = "Stopping";
                         break;
-                    case BundleEvent.UNINSTALLED:
+                    case Bundle.UNINSTALLED:
                         status = "Uninstalled";
                         break;
                     default:
@@ -604,23 +598,10 @@ public class CellarBundleMBeanImpl extends StandardMBean 
implements CellarBundle
                 name = (name == null) ? bundle.getLocation() : name;
                 extendedState.setId(bundle.getBundleId());
                 extendedState.setName(name);
-                
extendedState.setVersion(bundle.getHeaders().get("Bundle-Version").toString());
+                
extendedState.setVersion(bundle.getHeaders().get(org.osgi.framework.Constants.BUNDLE_VERSION));
                 extendedState.setSymbolicName(bundle.getSymbolicName());
                 extendedState.setLocation(bundle.getLocation());
-                int status = bundle.getState();
-                if (status == Bundle.ACTIVE)
-                    status = BundleEvent.STARTED;
-                if (status == Bundle.INSTALLED)
-                    status = BundleEvent.INSTALLED;
-                if (status == Bundle.RESOLVED)
-                    status = BundleEvent.RESOLVED;
-                if (status == Bundle.STARTING)
-                    status = BundleEvent.STARTING;
-                if (status == Bundle.UNINSTALLED)
-                    status = BundleEvent.UNINSTALLED;
-                if (status == Bundle.STOPPING)
-                    status = BundleEvent.STARTED;
-                extendedState.setStatus(status);
+                extendedState.setStatus(bundle.getState());
                 extendedState.setCluster(false);
                 extendedState.setLocal(true);
                 bundles.put(key, extendedState);
@@ -658,4 +639,4 @@ public class CellarBundleMBeanImpl extends StandardMBean 
implements CellarBundle
         }
     }
 
-}
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/karaf-cellar/blob/96d50bb8/bundle/src/main/java/org/apache/karaf/cellar/bundle/shell/BlockCommand.java
----------------------------------------------------------------------
diff --git 
a/bundle/src/main/java/org/apache/karaf/cellar/bundle/shell/BlockCommand.java 
b/bundle/src/main/java/org/apache/karaf/cellar/bundle/shell/BlockCommand.java
index 098d38a..88a9b69 100644
--- 
a/bundle/src/main/java/org/apache/karaf/cellar/bundle/shell/BlockCommand.java
+++ 
b/bundle/src/main/java/org/apache/karaf/cellar/bundle/shell/BlockCommand.java
@@ -39,7 +39,6 @@ public class BlockCommand extends BundleCommandSupport {
     boolean blacklist = false;
 
     public Object doExecute() throws Exception {
-
         Group group = groupManager.findGroupByName(groupName);
         if (group == null) {
             System.err.println("Cluster group " + groupName + " doesn't 
exist");
@@ -48,85 +47,92 @@ public class BlockCommand extends BundleCommandSupport {
 
         List<String> patterns = new ArrayList<String>();
 
-        Map<String, ExtendedBundleState> bundles = gatherBundles();
-        List<String> selectedBundles = selector(bundles);
-        for (String selectedBundle : selectedBundles) {
-            patterns.add(bundles.get(selectedBundle).getLocation());
-        }
+        ClassLoader originalClassLoader = 
Thread.currentThread().getContextClassLoader();
+        
Thread.currentThread().setContextClassLoader(getClass().getClassLoader());
 
-        if (patterns.isEmpty() && ids != null) {
-            for (String id : ids) {
-                patterns.add(id);
+        try {
+            Map<String, ExtendedBundleState> bundles = gatherBundles(false);
+            List<String> selectedBundles = selector(bundles);
+            for (String selectedBundle : selectedBundles) {
+                patterns.add(bundles.get(selectedBundle).getLocation());
             }
-        }
 
-        CellarSupport support = new CellarSupport();
-        support.setClusterManager(clusterManager);
-        support.setGroupManager(groupManager);
-        support.setConfigurationAdmin(configurationAdmin);
+            if (patterns.isEmpty() && ids != null) {
+                for (String id : ids) {
+                    patterns.add(id);
+                }
+            }
 
-        if (!in && !out) {
-            in = true;
-            out = true;
-        }
-        if (!whitelist && !blacklist) {
-            whitelist = true;
-            blacklist = true;
-        }
+            CellarSupport support = new CellarSupport();
+            support.setClusterManager(clusterManager);
+            support.setGroupManager(groupManager);
+            support.setConfigurationAdmin(configurationAdmin);
 
-        if (patterns.isEmpty()) {
-            // display mode
-            if (in) {
-                System.out.println("INBOUND:");
-                if (whitelist) {
-                    System.out.print("\twhitelist: ");
-                    Set<String> list = 
support.getListEntries(Configurations.WHITELIST, groupName, Constants.CATEGORY, 
EventType.INBOUND);
-                    System.out.println(list.toString());
-                }
-                if (blacklist) {
-                    System.out.print("\tblacklist: ");
-                    Set<String> list = 
support.getListEntries(Configurations.BLACKLIST, groupName, Constants.CATEGORY, 
EventType.INBOUND);
-                    System.out.println(list.toString());
-                }
+            if (!in && !out) {
+                in = true;
+                out = true;
             }
-            if (out) {
-                System.out.println("OUTBOUND:");
-                if (whitelist) {
-                    System.out.print("\twhitelist: ");
-                    Set<String> list = 
support.getListEntries(Configurations.WHITELIST, groupName, Constants.CATEGORY, 
EventType.OUTBOUND);
-                    System.out.println(list.toString());
-                }
-                if (blacklist) {
-                    System.out.print("\tblacklist: ");
-                    Set<String> list = 
support.getListEntries(Configurations.BLACKLIST, groupName, Constants.CATEGORY, 
EventType.OUTBOUND);
-                    System.out.println(list.toString());
-                }
+            if (!whitelist && !blacklist) {
+                whitelist = true;
+                blacklist = true;
             }
-        } else {
-            // edit mode
-            for (String pattern : patterns) {
-                System.out.println("Updating blocking policy for " + pattern);
+
+            if (patterns.isEmpty()) {
+                // display mode
                 if (in) {
+                    System.out.println("INBOUND:");
                     if (whitelist) {
-                        System.out.println("\tinbound whitelist ...");
-                        support.switchListEntry(Configurations.WHITELIST, 
groupName, Constants.CATEGORY, EventType.INBOUND, pattern);
+                        System.out.print("\twhitelist: ");
+                        Set<String> list = 
support.getListEntries(Configurations.WHITELIST, groupName, Constants.CATEGORY, 
EventType.INBOUND);
+                        System.out.println(list.toString());
                     }
                     if (blacklist) {
-                        System.out.println("\tinbound blacklist ...");
-                        support.switchListEntry(Configurations.BLACKLIST, 
groupName, Constants.CATEGORY, EventType.INBOUND, pattern);
+                        System.out.print("\tblacklist: ");
+                        Set<String> list = 
support.getListEntries(Configurations.BLACKLIST, groupName, Constants.CATEGORY, 
EventType.INBOUND);
+                        System.out.println(list.toString());
                     }
                 }
                 if (out) {
+                    System.out.println("OUTBOUND:");
                     if (whitelist) {
-                        System.out.println("\toutbound whitelist ...");
-                        support.switchListEntry(Configurations.WHITELIST, 
groupName, Constants.CATEGORY, EventType.OUTBOUND, pattern);
+                        System.out.print("\twhitelist: ");
+                        Set<String> list = 
support.getListEntries(Configurations.WHITELIST, groupName, Constants.CATEGORY, 
EventType.OUTBOUND);
+                        System.out.println(list.toString());
                     }
                     if (blacklist) {
-                        System.out.println("\toutbound blacklist ...");
-                        support.switchListEntry(Configurations.BLACKLIST, 
groupName, Constants.CATEGORY, EventType.OUTBOUND, pattern);
+                        System.out.print("\tblacklist: ");
+                        Set<String> list = 
support.getListEntries(Configurations.BLACKLIST, groupName, Constants.CATEGORY, 
EventType.OUTBOUND);
+                        System.out.println(list.toString());
+                    }
+                }
+            } else {
+                // edit mode
+                for (String pattern : patterns) {
+                    System.out.println("Updating blocking policy for " + 
pattern);
+                    if (in) {
+                        if (whitelist) {
+                            System.out.println("\tinbound whitelist ...");
+                            support.switchListEntry(Configurations.WHITELIST, 
groupName, Constants.CATEGORY, EventType.INBOUND, pattern);
+                        }
+                        if (blacklist) {
+                            System.out.println("\tinbound blacklist ...");
+                            support.switchListEntry(Configurations.BLACKLIST, 
groupName, Constants.CATEGORY, EventType.INBOUND, pattern);
+                        }
+                    }
+                    if (out) {
+                        if (whitelist) {
+                            System.out.println("\toutbound whitelist ...");
+                            support.switchListEntry(Configurations.WHITELIST, 
groupName, Constants.CATEGORY, EventType.OUTBOUND, pattern);
+                        }
+                        if (blacklist) {
+                            System.out.println("\toutbound blacklist ...");
+                            support.switchListEntry(Configurations.BLACKLIST, 
groupName, Constants.CATEGORY, EventType.OUTBOUND, pattern);
+                        }
                     }
                 }
             }
+        } finally {
+            Thread.currentThread().setContextClassLoader(originalClassLoader);
         }
 
         return null;

http://git-wip-us.apache.org/repos/asf/karaf-cellar/blob/96d50bb8/bundle/src/main/java/org/apache/karaf/cellar/bundle/shell/BundleCommandSupport.java
----------------------------------------------------------------------
diff --git 
a/bundle/src/main/java/org/apache/karaf/cellar/bundle/shell/BundleCommandSupport.java
 
b/bundle/src/main/java/org/apache/karaf/cellar/bundle/shell/BundleCommandSupport.java
index 66a73e5..39f6464 100644
--- 
a/bundle/src/main/java/org/apache/karaf/cellar/bundle/shell/BundleCommandSupport.java
+++ 
b/bundle/src/main/java/org/apache/karaf/cellar/bundle/shell/BundleCommandSupport.java
@@ -19,7 +19,6 @@ import org.apache.karaf.cellar.core.Configurations;
 import org.apache.karaf.cellar.core.shell.CellarCommandSupport;
 import org.apache.karaf.shell.commands.Argument;
 import org.osgi.framework.Bundle;
-import org.osgi.framework.BundleEvent;
 
 import java.util.ArrayList;
 import java.util.HashMap;
@@ -158,7 +157,7 @@ public abstract class BundleCommandSupport extends 
CellarCommandSupport {
         }
     }
 
-    protected Map<String, ExtendedBundleState> gatherBundles() {
+    protected Map<String, ExtendedBundleState> gatherBundles(boolean 
clusterOnly) {
         Map<String, ExtendedBundleState> bundles = new HashMap<String, 
ExtendedBundleState>();
 
         // retrieve bundles from the cluster
@@ -177,6 +176,9 @@ public abstract class BundleCommandSupport extends 
CellarCommandSupport {
             bundles.put(key, extendedState);
         }
 
+        if (clusterOnly)
+            return bundles;
+
         // retrieve local bundles
         for (Bundle bundle : bundleContext.getBundles()) {
             String version = (String) 
bundle.getHeaders().get(org.osgi.framework.Constants.BUNDLE_VERSION);
@@ -195,22 +197,9 @@ public abstract class BundleCommandSupport extends 
CellarCommandSupport {
                 name = (name == null) ? bundle.getLocation() : name;
                 extendedState.setId(bundle.getBundleId());
                 extendedState.setName(name);
-                
extendedState.setVersion(bundle.getHeaders().get("Bundle-Version").toString());
+                
extendedState.setVersion(bundle.getHeaders().get(org.osgi.framework.Constants.BUNDLE_VERSION));
                 extendedState.setLocation(bundle.getLocation());
-                int status = bundle.getState();
-                if (status == Bundle.ACTIVE)
-                    status = BundleEvent.STARTED;
-                if (status == Bundle.INSTALLED)
-                    status = BundleEvent.INSTALLED;
-                if (status == Bundle.RESOLVED)
-                    status = BundleEvent.RESOLVED;
-                if (status == Bundle.STARTING)
-                    status = BundleEvent.STARTING;
-                if (status == Bundle.UNINSTALLED)
-                    status = BundleEvent.UNINSTALLED;
-                if (status == Bundle.STOPPING)
-                    status = BundleEvent.STARTED;
-                extendedState.setStatus(status);
+                extendedState.setStatus(bundle.getState());
                 extendedState.setCluster(false);
                 extendedState.setLocal(true);
                 bundles.put(key, extendedState);

http://git-wip-us.apache.org/repos/asf/karaf-cellar/blob/96d50bb8/bundle/src/main/java/org/apache/karaf/cellar/bundle/shell/InstallBundleCommand.java
----------------------------------------------------------------------
diff --git 
a/bundle/src/main/java/org/apache/karaf/cellar/bundle/shell/InstallBundleCommand.java
 
b/bundle/src/main/java/org/apache/karaf/cellar/bundle/shell/InstallBundleCommand.java
index 3f86aac..be29148 100644
--- 
a/bundle/src/main/java/org/apache/karaf/cellar/bundle/shell/InstallBundleCommand.java
+++ 
b/bundle/src/main/java/org/apache/karaf/cellar/bundle/shell/InstallBundleCommand.java
@@ -26,7 +26,7 @@ import 
org.apache.karaf.cellar.core.shell.CellarCommandSupport;
 import org.apache.karaf.shell.commands.Argument;
 import org.apache.karaf.shell.commands.Command;
 import org.apache.karaf.shell.commands.Option;
-import org.osgi.framework.BundleEvent;
+import org.osgi.framework.Bundle;
 
 import java.net.URL;
 import java.util.List;
@@ -103,9 +103,9 @@ public class InstallBundleCommand extends 
CellarCommandSupport {
                     state.setId(clusterBundles.size());
                     state.setLocation(url);
                     if (start) {
-                        state.setStatus(BundleEvent.STARTED);
+                        state.setStatus(Bundle.ACTIVE);
                     } else {
-                        state.setStatus(BundleEvent.INSTALLED);
+                        state.setStatus(Bundle.INSTALLED);
                     }
                     clusterBundles.put(symbolicName + "/" + version, state);
                 } finally {
@@ -113,10 +113,12 @@ public class InstallBundleCommand extends 
CellarCommandSupport {
                 }
 
                 // broadcast the cluster event
-                ClusterBundleEvent event = new 
ClusterBundleEvent(symbolicName, version, url, BundleEvent.INSTALLED);
-                event.setSourceGroup(group);
+                ClusterBundleEvent event;
                 if (start) {
-                    event = new ClusterBundleEvent(symbolicName, version, url, 
BundleEvent.STARTED);
+                    event = new ClusterBundleEvent(symbolicName, version, url, 
Bundle.ACTIVE);
+                    event.setSourceGroup(group);
+                } else {
+                    event = new ClusterBundleEvent(symbolicName, version, url, 
Bundle.INSTALLED);
                     event.setSourceGroup(group);
                 }
                 eventProducer.produce(event);

http://git-wip-us.apache.org/repos/asf/karaf-cellar/blob/96d50bb8/bundle/src/main/java/org/apache/karaf/cellar/bundle/shell/ListBundleCommand.java
----------------------------------------------------------------------
diff --git 
a/bundle/src/main/java/org/apache/karaf/cellar/bundle/shell/ListBundleCommand.java
 
b/bundle/src/main/java/org/apache/karaf/cellar/bundle/shell/ListBundleCommand.java
index 165d5de..3bfa04a 100644
--- 
a/bundle/src/main/java/org/apache/karaf/cellar/bundle/shell/ListBundleCommand.java
+++ 
b/bundle/src/main/java/org/apache/karaf/cellar/bundle/shell/ListBundleCommand.java
@@ -21,7 +21,7 @@ import org.apache.karaf.cellar.core.event.EventType;
 import org.apache.karaf.shell.commands.Command;
 import org.apache.karaf.shell.commands.Option;
 import org.apache.karaf.shell.table.ShellTable;
-import org.osgi.framework.BundleEvent;
+import org.osgi.framework.Bundle;
 
 import java.util.*;
 
@@ -61,7 +61,7 @@ public class ListBundleCommand extends BundleCommandSupport {
         
Thread.currentThread().setContextClassLoader(getClass().getClassLoader());
 
         try {
-            Map<String, ExtendedBundleState> allBundles = gatherBundles();
+            Map<String, ExtendedBundleState> allBundles = gatherBundles(false);
             if (allBundles != null && !allBundles.isEmpty()) {
                 System.out.println(String.format("Bundles in cluster group " + 
groupName));
 
@@ -85,25 +85,22 @@ public class ListBundleCommand extends BundleCommandSupport 
{
                 for (ExtendedBundleState bundle : bundles) {
                     String status;
                     switch (bundle.getStatus()) {
-                        case BundleEvent.INSTALLED:
+                        case Bundle.INSTALLED:
                             status = "Installed";
                             break;
-                        case BundleEvent.RESOLVED:
+                        case Bundle.RESOLVED:
                             status = "Resolved";
                             break;
-                        case BundleEvent.STARTED:
+                        case Bundle.ACTIVE:
                             status = "Active";
                             break;
-                        case BundleEvent.STARTING:
+                        case Bundle.STARTING:
                             status = "Starting";
                             break;
-                        case BundleEvent.STOPPED:
-                            status = "Resolved";
-                            break;
-                        case BundleEvent.STOPPING:
+                        case Bundle.STOPPING:
                             status = "Stopping";
                             break;
-                        case BundleEvent.UNINSTALLED:
+                        case Bundle.UNINSTALLED:
                             status = "Uninstalled";
                             break;
                         default:

http://git-wip-us.apache.org/repos/asf/karaf-cellar/blob/96d50bb8/bundle/src/main/java/org/apache/karaf/cellar/bundle/shell/StartBundleCommand.java
----------------------------------------------------------------------
diff --git 
a/bundle/src/main/java/org/apache/karaf/cellar/bundle/shell/StartBundleCommand.java
 
b/bundle/src/main/java/org/apache/karaf/cellar/bundle/shell/StartBundleCommand.java
index 552d753..815b200 100644
--- 
a/bundle/src/main/java/org/apache/karaf/cellar/bundle/shell/StartBundleCommand.java
+++ 
b/bundle/src/main/java/org/apache/karaf/cellar/bundle/shell/StartBundleCommand.java
@@ -23,7 +23,7 @@ import org.apache.karaf.cellar.core.control.SwitchStatus;
 import org.apache.karaf.cellar.core.event.EventProducer;
 import org.apache.karaf.cellar.core.event.EventType;
 import org.apache.karaf.shell.commands.Command;
-import org.osgi.framework.BundleEvent;
+import org.osgi.framework.Bundle;
 
 import java.util.List;
 import java.util.Map;
@@ -55,7 +55,7 @@ public class StartBundleCommand extends BundleCommandSupport {
         try {
             Map<String, BundleState> clusterBundles = 
clusterManager.getMap(Constants.BUNDLE_MAP + Configurations.SEPARATOR + 
groupName);
 
-            List<String> bundles = selector(gatherBundles());
+            List<String> bundles = selector(gatherBundles(true));
 
             for (String bundle : bundles) {
                 BundleState state = clusterBundles.get(bundle);
@@ -74,12 +74,12 @@ public class StartBundleCommand extends 
BundleCommandSupport {
                 }
 
                 // update the cluster state
-                state.setStatus(BundleEvent.STARTED);
+                state.setStatus(Bundle.ACTIVE);
                 clusterBundles.put(bundle, state);
 
                 // broadcast the cluster event
                 String[] split = bundle.split("/");
-                ClusterBundleEvent event = new ClusterBundleEvent(split[0], 
split[1], location, BundleEvent.STARTED);
+                ClusterBundleEvent event = new ClusterBundleEvent(split[0], 
split[1], location, Bundle.ACTIVE);
                 event.setSourceGroup(group);
                 eventProducer.produce(event);
             }

http://git-wip-us.apache.org/repos/asf/karaf-cellar/blob/96d50bb8/bundle/src/main/java/org/apache/karaf/cellar/bundle/shell/StopBundleCommand.java
----------------------------------------------------------------------
diff --git 
a/bundle/src/main/java/org/apache/karaf/cellar/bundle/shell/StopBundleCommand.java
 
b/bundle/src/main/java/org/apache/karaf/cellar/bundle/shell/StopBundleCommand.java
index d91aa9a..8b6952e 100644
--- 
a/bundle/src/main/java/org/apache/karaf/cellar/bundle/shell/StopBundleCommand.java
+++ 
b/bundle/src/main/java/org/apache/karaf/cellar/bundle/shell/StopBundleCommand.java
@@ -23,7 +23,7 @@ import org.apache.karaf.cellar.core.control.SwitchStatus;
 import org.apache.karaf.cellar.core.event.EventProducer;
 import org.apache.karaf.cellar.core.event.EventType;
 import org.apache.karaf.shell.commands.Command;
-import org.osgi.framework.BundleEvent;
+import org.osgi.framework.Bundle;
 
 import java.util.List;
 import java.util.Map;
@@ -54,7 +54,7 @@ public class StopBundleCommand extends BundleCommandSupport {
         try {
             Map<String, BundleState> clusterBundles = 
clusterManager.getMap(Constants.BUNDLE_MAP + Configurations.SEPARATOR + 
groupName);
 
-            List<String> bundles = selector(gatherBundles());
+            List<String> bundles = selector(gatherBundles(true));
 
             for (String bundle : bundles) {
                 BundleState state = clusterBundles.get(bundle);
@@ -73,12 +73,12 @@ public class StopBundleCommand extends BundleCommandSupport 
{
                 }
 
                 // update the cluster state
-                state.setStatus(BundleEvent.STOPPED);
+                state.setStatus(Bundle.RESOLVED);
                 clusterBundles.put(bundle, state);
 
                 // broadcast the cluster event
                 String[] split = bundle.split("/");
-                ClusterBundleEvent event = new ClusterBundleEvent(split[0], 
split[1], location, BundleEvent.STOPPED);
+                ClusterBundleEvent event = new ClusterBundleEvent(split[0], 
split[1], location, Bundle.RESOLVED);
                 event.setSourceGroup(group);
                 eventProducer.produce(event);
             }

http://git-wip-us.apache.org/repos/asf/karaf-cellar/blob/96d50bb8/bundle/src/main/java/org/apache/karaf/cellar/bundle/shell/UninstallBundleCommand.java
----------------------------------------------------------------------
diff --git 
a/bundle/src/main/java/org/apache/karaf/cellar/bundle/shell/UninstallBundleCommand.java
 
b/bundle/src/main/java/org/apache/karaf/cellar/bundle/shell/UninstallBundleCommand.java
index 760a58a..2f98ec5 100644
--- 
a/bundle/src/main/java/org/apache/karaf/cellar/bundle/shell/UninstallBundleCommand.java
+++ 
b/bundle/src/main/java/org/apache/karaf/cellar/bundle/shell/UninstallBundleCommand.java
@@ -23,7 +23,7 @@ import org.apache.karaf.cellar.core.control.SwitchStatus;
 import org.apache.karaf.cellar.core.event.EventProducer;
 import org.apache.karaf.cellar.core.event.EventType;
 import org.apache.karaf.shell.commands.Command;
-import org.osgi.framework.BundleEvent;
+import org.osgi.framework.Bundle;
 
 import java.util.List;
 import java.util.Map;
@@ -55,7 +55,7 @@ public class UninstallBundleCommand extends 
BundleCommandSupport {
         try {
             Map<String, BundleState> clusterBundles = 
clusterManager.getMap(Constants.BUNDLE_MAP + Configurations.SEPARATOR + 
groupName);
 
-            List<String> bundles = selector(gatherBundles());
+            List<String> bundles = selector(gatherBundles(true));
 
             for (String bundle : bundles) {
                 BundleState state = clusterBundles.get(bundle);
@@ -78,7 +78,7 @@ public class UninstallBundleCommand extends 
BundleCommandSupport {
 
                 // broadcast the cluster event
                 String[] split = bundle.split("/");
-                ClusterBundleEvent event = new ClusterBundleEvent(split[0], 
split[1], location, BundleEvent.UNINSTALLED);
+                ClusterBundleEvent event = new ClusterBundleEvent(split[0], 
split[1], location, Bundle.UNINSTALLED);
                 event.setSourceGroup(group);
                 eventProducer.produce(event);
             }

http://git-wip-us.apache.org/repos/asf/karaf-cellar/blob/96d50bb8/bundle/src/main/resources/OSGI-INF/blueprint/blueprint.xml
----------------------------------------------------------------------
diff --git a/bundle/src/main/resources/OSGI-INF/blueprint/blueprint.xml 
b/bundle/src/main/resources/OSGI-INF/blueprint/blueprint.xml
index ec986e7..0742ab5 100644
--- a/bundle/src/main/resources/OSGI-INF/blueprint/blueprint.xml
+++ b/bundle/src/main/resources/OSGI-INF/blueprint/blueprint.xml
@@ -35,6 +35,7 @@
         <property name="groupManager" ref="groupManager"/>
         <property name="clusterManager" ref="clusterManager"/>
         <property name="bundleContext" ref="blueprintBundleContext"/>
+        <property name="eventProducer" ref="eventProducer"/>
     </bean>
     <service ref="synchronizer" 
interface="org.apache.karaf.cellar.core.Synchronizer">
         <service-properties>

http://git-wip-us.apache.org/repos/asf/karaf-cellar/blob/96d50bb8/hazelcast/src/main/java/org/apache/karaf/cellar/hazelcast/QueueProducer.java
----------------------------------------------------------------------
diff --git 
a/hazelcast/src/main/java/org/apache/karaf/cellar/hazelcast/QueueProducer.java 
b/hazelcast/src/main/java/org/apache/karaf/cellar/hazelcast/QueueProducer.java
index 4dcf404..b489444 100644
--- 
a/hazelcast/src/main/java/org/apache/karaf/cellar/hazelcast/QueueProducer.java
+++ 
b/hazelcast/src/main/java/org/apache/karaf/cellar/hazelcast/QueueProducer.java
@@ -31,6 +31,7 @@ import com.hazelcast.core.HazelcastInstance;
 import com.hazelcast.core.IQueue;
 import org.apache.karaf.cellar.core.Configurations;
 import org.apache.karaf.cellar.core.Node;
+import org.apache.karaf.cellar.core.command.Command;
 import org.apache.karaf.cellar.core.command.Result;
 import org.apache.karaf.cellar.core.control.BasicSwitch;
 import org.apache.karaf.cellar.core.control.Switch;
@@ -71,7 +72,8 @@ public class QueueProducer<E extends Event> implements 
EventProducer<E> {
     @Override
     public void produce(E event) {
         if (this.getSwitch().getStatus().equals(SwitchStatus.ON) || 
event.getForce() || event instanceof Result) {
-            event.setSourceNode(node);
+            if (event instanceof Result || event instanceof Command)
+                event.setSourceNode(node);
             try {
                 queue.put(event);
             } catch (InterruptedException e) {

http://git-wip-us.apache.org/repos/asf/karaf-cellar/blob/96d50bb8/hazelcast/src/main/java/org/apache/karaf/cellar/hazelcast/TopicProducer.java
----------------------------------------------------------------------
diff --git 
a/hazelcast/src/main/java/org/apache/karaf/cellar/hazelcast/TopicProducer.java 
b/hazelcast/src/main/java/org/apache/karaf/cellar/hazelcast/TopicProducer.java
index 65f20f1..6ea4fc9 100644
--- 
a/hazelcast/src/main/java/org/apache/karaf/cellar/hazelcast/TopicProducer.java
+++ 
b/hazelcast/src/main/java/org/apache/karaf/cellar/hazelcast/TopicProducer.java
@@ -17,6 +17,7 @@ import com.hazelcast.core.HazelcastInstance;
 import com.hazelcast.core.ITopic;
 import org.apache.karaf.cellar.core.Configurations;
 import org.apache.karaf.cellar.core.Node;
+import org.apache.karaf.cellar.core.command.Command;
 import org.apache.karaf.cellar.core.command.Result;
 import org.apache.karaf.cellar.core.control.BasicSwitch;
 import org.apache.karaf.cellar.core.control.Switch;
@@ -57,7 +58,8 @@ public class TopicProducer<E extends Event> implements 
EventProducer<E> {
     @Override
     public void produce(E event) {
         if (this.getSwitch().getStatus().equals(SwitchStatus.ON) || 
event.getForce() || event instanceof Result) {
-            event.setSourceNode(node);
+            if (event instanceof Result || event instanceof Command)
+                event.setSourceNode(node);
             topic.publish(event);
         } else {
             if (eventSwitch.getStatus().equals(SwitchStatus.OFF)) {

Reply via email to