karaf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jbono...@apache.org
Subject karaf git commit: [KARAF-2104] Add refreshRepository() operation on the FeatureMBean with regex support
Date Wed, 10 Dec 2014 05:39:35 GMT
Repository: karaf
Updated Branches:
  refs/heads/master a8e2aabf2 -> b10a00979


[KARAF-2104] Add refreshRepository() operation on the FeatureMBean with regex support


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

Branch: refs/heads/master
Commit: b10a0097930a91745201852b9111c9794ee0ff13
Parents: a8e2aab
Author: Jean-Baptiste Onofré <jbonofre@apache.org>
Authored: Wed Dec 10 06:37:49 2014 +0100
Committer: Jean-Baptiste Onofré <jbonofre@apache.org>
Committed: Wed Dec 10 06:37:49 2014 +0100

----------------------------------------------------------------------
 .../management/FeaturesServiceMBeanImpl.java    | 30 ++++++++++++++++----
 .../management/FeaturesServiceMBean.java        |  2 ++
 .../org/apache/karaf/itests/FeatureTest.java    | 13 +++++++++
 3 files changed, 40 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/karaf/blob/b10a0097/features/core/src/main/java/org/apache/karaf/features/internal/management/FeaturesServiceMBeanImpl.java
----------------------------------------------------------------------
diff --git a/features/core/src/main/java/org/apache/karaf/features/internal/management/FeaturesServiceMBeanImpl.java
b/features/core/src/main/java/org/apache/karaf/features/internal/management/FeaturesServiceMBeanImpl.java
index 4bed3c6..35d6481 100644
--- a/features/core/src/main/java/org/apache/karaf/features/internal/management/FeaturesServiceMBeanImpl.java
+++ b/features/core/src/main/java/org/apache/karaf/features/internal/management/FeaturesServiceMBeanImpl.java
@@ -17,11 +17,9 @@
 package org.apache.karaf.features.internal.management;
 
 import java.net.URI;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.EnumSet;
-import java.util.Hashtable;
-import java.util.List;
+import java.util.*;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
 
 import javax.management.MBeanNotificationInfo;
 import javax.management.MBeanRegistration;
@@ -141,6 +139,28 @@ public class FeaturesServiceMBeanImpl extends StandardEmitterMBean implements
         featuresService.removeRepository(new URI(uri), uninstall);
     }
 
+    public void refreshRepository(String uri) throws Exception {
+        if (uri == null || uri.isEmpty()) {
+            for (Repository repository : featuresService.listRepositories()) {
+                featuresService.refreshRepository(repository.getURI());
+            }
+        } else {
+            // regex support
+            Pattern pattern = Pattern.compile(uri);
+            List<URI> uris = new ArrayList<>();
+            for (Repository repository : featuresService.listRepositories()) {
+                URI u = repository.getURI();
+                Matcher matcher = pattern.matcher(u.toString());
+                if (matcher.matches()) {
+                    uris.add(u);
+                }
+            }
+            for (URI u :uris) {
+                featuresService.refreshRepository(u);
+            }
+        }
+    }
+
     public void installFeature(String name) throws Exception {
         featuresService.installFeature(name);
     }

http://git-wip-us.apache.org/repos/asf/karaf/blob/b10a0097/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 09385d0..ca33599 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
@@ -118,6 +118,8 @@ public interface FeaturesServiceMBean {
 
     void removeRepository(String url, boolean uninstall) throws Exception;
 
+    void refreshRepository(String url) throws Exception;
+
     void installFeature(String name) throws Exception;
 
     void installFeature(String name, boolean noRefresh) throws Exception;

http://git-wip-us.apache.org/repos/asf/karaf/blob/b10a0097/itests/src/test/java/org/apache/karaf/itests/FeatureTest.java
----------------------------------------------------------------------
diff --git a/itests/src/test/java/org/apache/karaf/itests/FeatureTest.java b/itests/src/test/java/org/apache/karaf/itests/FeatureTest.java
index f41e8b0..88fbf11 100644
--- a/itests/src/test/java/org/apache/karaf/itests/FeatureTest.java
+++ b/itests/src/test/java/org/apache/karaf/itests/FeatureTest.java
@@ -115,4 +115,17 @@ public class FeatureTest extends KarafTestSupport {
         assertContains("pax-web", refreshedRepo);
     }
 
+    @Test
+    public void repoRefreshViaMBean() throws Exception {
+        JMXConnector connector = null;
+        try {
+            connector = this.getJMXConnector();
+            MBeanServerConnection connection = connector.getMBeanServerConnection();
+            ObjectName name = new ObjectName("org.apache.karaf:type=feature,name=root");
+            connection.invoke(name, "refreshRepository", new Object[] { ".*pax-web.*" },
new String[]{ "java.lang.String" });
+        } finally {
+            close(connector);
+        }
+    }
+
 }


Mime
View raw message