karaf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jbono...@apache.org
Subject [1/2] karaf git commit: [KARAF-2104] Add refreshRepository() operation with regex support in the FeaturesMBean
Date Fri, 12 Dec 2014 05:46:10 GMT
Repository: karaf
Updated Branches:
  refs/heads/karaf-3.0.x 86aff6b16 -> 5b8f91a96


[KARAF-2104] Add refreshRepository() operation with regex support in the FeaturesMBean


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

Branch: refs/heads/karaf-3.0.x
Commit: 4b797038f101c3d30a7129120465e5baad37ac4a
Parents: d7d1845
Author: Jean-Baptiste Onofré <jbonofre@apache.org>
Authored: Fri Dec 12 06:44:38 2014 +0100
Committer: Jean-Baptiste Onofré <jbonofre@apache.org>
Committed: Fri Dec 12 06:44:38 2014 +0100

----------------------------------------------------------------------
 .../management/FeaturesServiceMBean.java        |  2 ++
 .../internal/FeaturesServiceMBeanImpl.java      | 22 ++++++++++++++++++++
 .../org/apache/karaf/itests/FeatureTest.java    | 13 ++++++++++++
 3 files changed, 37 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/karaf/blob/4b797038/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 dda5854..4b9284b 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
@@ -32,6 +32,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 noClean, boolean noRefresh) throws Exception;

http://git-wip-us.apache.org/repos/asf/karaf/blob/4b797038/features/core/src/main/java/org/apache/karaf/features/management/internal/FeaturesServiceMBeanImpl.java
----------------------------------------------------------------------
diff --git a/features/core/src/main/java/org/apache/karaf/features/management/internal/FeaturesServiceMBeanImpl.java
b/features/core/src/main/java/org/apache/karaf/features/management/internal/FeaturesServiceMBeanImpl.java
index 3479586..bcbf199 100644
--- a/features/core/src/main/java/org/apache/karaf/features/management/internal/FeaturesServiceMBeanImpl.java
+++ b/features/core/src/main/java/org/apache/karaf/features/management/internal/FeaturesServiceMBeanImpl.java
@@ -19,6 +19,8 @@ import java.util.Arrays;
 import java.util.EnumSet;
 import java.util.Hashtable;
 import java.util.List;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
 
 import javax.management.MBeanNotificationInfo;
 import javax.management.MBeanRegistration;
@@ -135,6 +137,26 @@ public class FeaturesServiceMBeanImpl extends StandardEmitterMBean implements
         featuresService.removeRepository(new URI(uri), uninstall);
     }
 
+    public void refreshRepository(String url) throws Exception {
+        List<URI> uris = new ArrayList<URI>();
+        if (url != null && !url.isEmpty()) {
+            Pattern pattern = Pattern.compile(url);
+            for (Repository r : featuresService.listRepositories()) {
+                Matcher matcher = pattern.matcher(r.getURI().toString());
+                if (matcher.matches()) {
+                    uris.add(r.getURI());
+                }
+            }
+        } else {
+            for (Repository r : featuresService.listRepositories()) {
+                uris.add(r.getURI());
+            }
+        }
+        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/4b797038/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 879cc51..822f066 100644
--- a/itests/src/test/java/org/apache/karaf/itests/FeatureTest.java
+++ b/itests/src/test/java/org/apache/karaf/itests/FeatureTest.java
@@ -111,4 +111,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