karaf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gno...@apache.org
Subject [1/2] git commit: [KARAF-2923] Add support for regions in JMX events
Date Fri, 30 May 2014 14:05:38 GMT
Repository: karaf
Updated Branches:
  refs/heads/master f7bb021c4 -> 232bf6c04


[KARAF-2923] Add support for regions in JMX events

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

Branch: refs/heads/master
Commit: 2a1ad299adca2653be96d79870b5ccf1af4f0045
Parents: f7bb021
Author: Guillaume Nodet <gnodet@gmail.com>
Authored: Fri May 30 09:48:31 2014 +0200
Committer: Guillaume Nodet <gnodet@gmail.com>
Committed: Fri May 30 09:48:31 2014 +0200

----------------------------------------------------------------------
 .../org/apache/karaf/features/FeatureEvent.java  |  8 +++++++-
 .../features/internal/service/Deployer.java      | 19 ++++++++++++++-----
 .../internal/service/FeaturesServiceImpl.java    | 13 ++++++++-----
 .../management/FeaturesServiceMBean.java         |  4 +++-
 .../management/codec/JmxFeatureEvent.java        |  3 +++
 .../features/internal/service/DeployerTest.java  |  5 +++--
 6 files changed, 38 insertions(+), 14 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/karaf/blob/2a1ad299/features/core/src/main/java/org/apache/karaf/features/FeatureEvent.java
----------------------------------------------------------------------
diff --git a/features/core/src/main/java/org/apache/karaf/features/FeatureEvent.java b/features/core/src/main/java/org/apache/karaf/features/FeatureEvent.java
index 516c988..5a26e46 100644
--- a/features/core/src/main/java/org/apache/karaf/features/FeatureEvent.java
+++ b/features/core/src/main/java/org/apache/karaf/features/FeatureEvent.java
@@ -27,12 +27,14 @@ public class FeatureEvent extends EventObject {
 
     private final EventType type;
     private final Feature feature;
+    private final String region;
     private final boolean replay;
 
-    public FeatureEvent(Feature feature, EventType type, boolean replay) {
+    public FeatureEvent(EventType type, Feature feature, String region, boolean replay) {
         super(feature);
         this.type = type;
         this.feature = feature;
+        this.region = region;
         this.replay = replay;
     }
 
@@ -44,6 +46,10 @@ public class FeatureEvent extends EventObject {
         return feature;
     }
 
+    public String getRegion() {
+        return region;
+    }
+
     public boolean isReplay() {
         return replay;
     }

http://git-wip-us.apache.org/repos/asf/karaf/blob/2a1ad299/features/core/src/main/java/org/apache/karaf/features/internal/service/Deployer.java
----------------------------------------------------------------------
diff --git a/features/core/src/main/java/org/apache/karaf/features/internal/service/Deployer.java
b/features/core/src/main/java/org/apache/karaf/features/internal/service/Deployer.java
index 4d289cb..81cc0f8 100644
--- a/features/core/src/main/java/org/apache/karaf/features/internal/service/Deployer.java
+++ b/features/core/src/main/java/org/apache/karaf/features/internal/service/Deployer.java
@@ -767,12 +767,21 @@ public class Deployer {
         }
 
         // Call listeners
-        // TODO: add region information and avoid flattening
-        for (Feature feature : apply(flatten(delFeatures), map(dstate.features))) {
-            callback.callListeners(new FeatureEvent(feature, FeatureEvent.EventType.FeatureUninstalled,
false));
+        for (Map.Entry<String, Set<String>> entry : delFeatures.entrySet()) {
+            for (String name : entry.getValue()) {
+                Feature feature = dstate.features.get(name);
+                if (feature != null) {
+                    callback.callListeners(new FeatureEvent(FeatureEvent.EventType.FeatureUninstalled,
feature, entry.getKey(), false));
+                }
+            }
         }
-        for (Feature feature : apply(flatten(newFeatures), map(dstate.features))) {
-            callback.callListeners(new FeatureEvent(feature, FeatureEvent.EventType.FeatureInstalled,
false));
+        for (Map.Entry<String, Set<String>> entry : newFeatures.entrySet()) {
+            for (String name : entry.getValue()) {
+                Feature feature = dstate.features.get(name);
+                if (feature != null) {
+                    callback.callListeners(new FeatureEvent(FeatureEvent.EventType.FeatureInstalled,
feature, entry.getKey(), false));
+                }
+            }
         }
 
         print("Done.", verbose);

http://git-wip-us.apache.org/repos/asf/karaf/blob/2a1ad299/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 ce01342..faabc88 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
@@ -32,6 +32,7 @@ import java.util.LinkedHashSet;
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
+import java.util.TreeMap;
 import java.util.TreeSet;
 import java.util.concurrent.Callable;
 import java.util.concurrent.CountDownLatch;
@@ -266,18 +267,20 @@ public class FeaturesServiceImpl implements FeaturesService, Deployer.DeployCall
         listeners.add(listener);
         try {
             Set<String> repositories = new TreeSet<>();
-            Set<String> installedFeatures = new TreeSet<>();
+            Map<String, Set<String>> installedFeatures = new TreeMap<>();
             synchronized (lock) {
                 repositories.addAll(state.repositories);
-                installedFeatures.addAll(state.installedFeatures.keySet());
+                installedFeatures.putAll(copy(state.installedFeatures));
             }
             for (String uri : repositories) {
                 Repository repository = new RepositoryImpl(URI.create(uri));
                 listener.repositoryEvent(new RepositoryEvent(repository, RepositoryEvent.EventType.RepositoryAdded,
true));
             }
-            for (String id : installedFeatures) {
-                Feature feature = org.apache.karaf.features.internal.model.Feature.valueOf(id);
-                listener.featureEvent(new FeatureEvent(feature, FeatureEvent.EventType.FeatureInstalled,
true));
+            for (Map.Entry<String, Set<String>> entry : installedFeatures.entrySet())
{
+                for (String id : entry.getValue()) {
+                    Feature feature = org.apache.karaf.features.internal.model.Feature.valueOf(id);
+                    listener.featureEvent(new FeatureEvent(FeatureEvent.EventType.FeatureInstalled,
feature, entry.getKey(), true));
+                }
             }
         } catch (Exception e) {
             LOGGER.error("Error notifying listener about the current state", e);

http://git-wip-us.apache.org/repos/asf/karaf/blob/2a1ad299/features/core/src/main/java/org/apache/karaf/features/management/FeaturesServiceMBean.java
----------------------------------------------------------------------
diff --git a/features/core/src/main/java/org/apache/karaf/features/management/FeaturesServiceMBean.java
b/features/core/src/main/java/org/apache/karaf/features/management/FeaturesServiceMBean.java
index 60e0f9b..9cce26b 100644
--- a/features/core/src/main/java/org/apache/karaf/features/management/FeaturesServiceMBean.java
+++ b/features/core/src/main/java/org/apache/karaf/features/management/FeaturesServiceMBean.java
@@ -52,6 +52,8 @@ public interface FeaturesServiceMBean {
 
     String FEATURE_EVENT_EVENT_TYPE_UNINSTALLED = "Uninstalled";
 
+    String FEATURE_EVENT_REGION = "Region";
+
     /**
      * The item names in the CompositeData representing a feature
      */
@@ -70,7 +72,7 @@ public interface FeaturesServiceMBean {
      * The item names in the CompositeData representing the event raised for
      * feature events within the OSGi container by this bean
      */
-    String[] FEATURE_EVENT = {FEATURE_NAME, FEATURE_VERSION, FEATURE_EVENT_EVENT_TYPE};
+    String[] FEATURE_EVENT = {FEATURE_NAME, FEATURE_VERSION, FEATURE_EVENT_REGION, FEATURE_EVENT_EVENT_TYPE};
 
 
     String REPOSITORY_NAME = "Name";

http://git-wip-us.apache.org/repos/asf/karaf/blob/2a1ad299/features/core/src/main/java/org/apache/karaf/features/management/codec/JmxFeatureEvent.java
----------------------------------------------------------------------
diff --git a/features/core/src/main/java/org/apache/karaf/features/management/codec/JmxFeatureEvent.java
b/features/core/src/main/java/org/apache/karaf/features/management/codec/JmxFeatureEvent.java
index 2319a15..65f00c1 100644
--- a/features/core/src/main/java/org/apache/karaf/features/management/codec/JmxFeatureEvent.java
+++ b/features/core/src/main/java/org/apache/karaf/features/management/codec/JmxFeatureEvent.java
@@ -38,6 +38,7 @@ public class JmxFeatureEvent {
             Object[] itemValues = new Object[itemNames.length];
             itemValues[0] = event.getFeature().getName();
             itemValues[1] = event.getFeature().getVersion();
+            itemValues[2] = event.getRegion();
             switch (event.getType()) {
             case FeatureInstalled:
                 itemValues[2] = FeaturesServiceMBean.FEATURE_EVENT_EVENT_TYPE_INSTALLED;
@@ -71,10 +72,12 @@ public class JmxFeatureEvent {
             itemTypes[0] = SimpleType.STRING;
             itemTypes[1] = SimpleType.STRING;
             itemTypes[2] = SimpleType.STRING;
+            itemTypes[3] = SimpleType.STRING;
 
             itemDescriptions[0] = "The id of the feature";
             itemDescriptions[1] = "The version of the feature";
             itemDescriptions[2] = "The type of the event";
+            itemDescriptions[3] = "The region of this feature";
 
             return new CompositeType("FeatureEvent", description, itemNames,
                     itemDescriptions, itemTypes);

http://git-wip-us.apache.org/repos/asf/karaf/blob/2a1ad299/features/core/src/test/java/org/apache/karaf/features/internal/service/DeployerTest.java
----------------------------------------------------------------------
diff --git a/features/core/src/test/java/org/apache/karaf/features/internal/service/DeployerTest.java
b/features/core/src/test/java/org/apache/karaf/features/internal/service/DeployerTest.java
index 9478b67..f5e05d1 100644
--- a/features/core/src/test/java/org/apache/karaf/features/internal/service/DeployerTest.java
+++ b/features/core/src/test/java/org/apache/karaf/features/internal/service/DeployerTest.java
@@ -30,6 +30,7 @@ import java.util.jar.Manifest;
 import org.apache.felix.utils.version.VersionRange;
 import org.apache.karaf.features.Feature;
 import org.apache.karaf.features.FeatureEvent;
+import org.apache.karaf.features.FeaturesService;
 import org.apache.karaf.features.internal.support.TestBundle;
 import org.apache.karaf.features.internal.support.TestDownloadManager;
 import org.easymock.EasyMock;
@@ -164,9 +165,9 @@ public class DeployerTest {
         EasyMock.expectLastCall();
         callback.refreshPackages(EasyMock.eq(Collections.<Bundle>singleton(bundleA)));
         EasyMock.expectLastCall();
-        callback.callListeners(FeatureEventMatcher.eq(new FeatureEvent(f100, FeatureEvent.EventType.FeatureUninstalled,
false)));
+        callback.callListeners(FeatureEventMatcher.eq(new FeatureEvent(FeatureEvent.EventType.FeatureUninstalled,
f100, FeaturesService.ROOT_REGION, false)));
         EasyMock.expectLastCall();
-        callback.callListeners(FeatureEventMatcher.eq(new FeatureEvent(f101, FeatureEvent.EventType.FeatureInstalled,
false)));
+        callback.callListeners(FeatureEventMatcher.eq(new FeatureEvent(FeatureEvent.EventType.FeatureInstalled,
f101, FeaturesService.ROOT_REGION, false)));
         EasyMock.expectLastCall();
 
         EasyMock.replay(callback);


Mime
View raw message