felix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ccust...@apache.org
Subject svn commit: r834657 - in /felix/trunk/karaf: admin/management/ admin/management/src/main/java/org/apache/felix/karaf/admin/management/internal/ admin/management/src/main/resources/OSGI-INF/blueprint/ admin/management/src/test/java/org/apache/felix/kara...
Date Tue, 10 Nov 2009 20:40:46 GMT
Author: ccustine
Date: Tue Nov 10 20:40:46 2009
New Revision: 834657

URL: http://svn.apache.org/viewvc?rev=834657&view=rev
Log:
FELIX-1848 - Include instance name in the JMX ObjectName for AdminService and FeaturesService
MBeans

Added:
    felix/trunk/karaf/admin/management/src/test/java/org/apache/felix/karaf/admin/management/internal/MBeanRegistererTest.java
Modified:
    felix/trunk/karaf/admin/management/pom.xml
    felix/trunk/karaf/admin/management/src/main/java/org/apache/felix/karaf/admin/management/internal/MBeanRegistrer.java
    felix/trunk/karaf/admin/management/src/main/resources/OSGI-INF/blueprint/admin-management.xml
    felix/trunk/karaf/features/management/src/main/java/org/apache/felix/karaf/features/management/internal/MBeanRegistrer.java
    felix/trunk/karaf/features/management/src/main/resources/OSGI-INF/blueprint/features-management.xml

Modified: felix/trunk/karaf/admin/management/pom.xml
URL: http://svn.apache.org/viewvc/felix/trunk/karaf/admin/management/pom.xml?rev=834657&r1=834656&r2=834657&view=diff
==============================================================================
--- felix/trunk/karaf/admin/management/pom.xml (original)
+++ felix/trunk/karaf/admin/management/pom.xml Tue Nov 10 20:40:46 2009
@@ -54,6 +54,13 @@
             <artifactId>org.apache.felix.karaf.admin.core</artifactId>
         </dependency>
 
+        <dependency>
+            <groupId>org.easymock</groupId>
+            <artifactId>easymockclassextension</artifactId>
+            <version>${easymock.version}</version>
+            <scope>test</scope>
+        </dependency>
+
     </dependencies>
 
     <build>

Modified: felix/trunk/karaf/admin/management/src/main/java/org/apache/felix/karaf/admin/management/internal/MBeanRegistrer.java
URL: http://svn.apache.org/viewvc/felix/trunk/karaf/admin/management/src/main/java/org/apache/felix/karaf/admin/management/internal/MBeanRegistrer.java?rev=834657&r1=834656&r2=834657&view=diff
==============================================================================
--- felix/trunk/karaf/admin/management/src/main/java/org/apache/felix/karaf/admin/management/internal/MBeanRegistrer.java
(original)
+++ felix/trunk/karaf/admin/management/src/main/java/org/apache/felix/karaf/admin/management/internal/MBeanRegistrer.java
Tue Nov 10 20:40:46 2009
@@ -52,7 +52,8 @@
     protected void registerMBeans() throws JMException {
         if (mbeanServer != null && mbeans != null) {
             for (Map.Entry<Object, String> entry : mbeans.entrySet()) {
-                mbeanServer.registerMBean(entry.getKey(), new ObjectName(entry.getValue()));
+                String value = parseProperty(entry.getValue());
+                mbeanServer.registerMBean(entry.getKey(), new ObjectName(value));
             }
         }
     }
@@ -60,8 +61,20 @@
     protected void unregisterMBeans() throws JMException {
         if (mbeanServer != null && mbeans != null) {
             for (Map.Entry<Object, String> entry : mbeans.entrySet()) {
-                mbeanServer.unregisterMBean(new ObjectName(entry.getValue()));
+                String value = parseProperty(entry.getValue());
+                mbeanServer.unregisterMBean(new ObjectName(value));
             }
         }
     }
-}
\ No newline at end of file
+
+    protected String parseProperty(String raw) {
+        if (raw.indexOf("${") > -1 && raw.indexOf("}", raw.indexOf("${")) >
-1) {
+            String var = raw.substring(raw.indexOf("${") + 2, raw.indexOf("}"));
+            String val = System.getProperty(var);
+            if (val != null) {
+                raw = raw.replace("${" + var + "}", val);
+            }
+        }
+        return raw;
+    }
+}

Modified: felix/trunk/karaf/admin/management/src/main/resources/OSGI-INF/blueprint/admin-management.xml
URL: http://svn.apache.org/viewvc/felix/trunk/karaf/admin/management/src/main/resources/OSGI-INF/blueprint/admin-management.xml?rev=834657&r1=834656&r2=834657&view=diff
==============================================================================
--- felix/trunk/karaf/admin/management/src/main/resources/OSGI-INF/blueprint/admin-management.xml
(original)
+++ felix/trunk/karaf/admin/management/src/main/resources/OSGI-INF/blueprint/admin-management.xml
Tue Nov 10 20:40:46 2009
@@ -39,7 +39,7 @@
                             <argument value="org.apache.felix.karaf.admin.management.AdminServiceMBean"/>
                         </bean>
                     </key>
-                    <value>org.apache.felix.karaf:service=admin</value>
+                    <value>org.apache.felix.karaf:type=admin,name=${karaf.name}</value>
                 </entry>
             </map>
         </property>

Added: felix/trunk/karaf/admin/management/src/test/java/org/apache/felix/karaf/admin/management/internal/MBeanRegistererTest.java
URL: http://svn.apache.org/viewvc/felix/trunk/karaf/admin/management/src/test/java/org/apache/felix/karaf/admin/management/internal/MBeanRegistererTest.java?rev=834657&view=auto
==============================================================================
--- felix/trunk/karaf/admin/management/src/test/java/org/apache/felix/karaf/admin/management/internal/MBeanRegistererTest.java
(added)
+++ felix/trunk/karaf/admin/management/src/test/java/org/apache/felix/karaf/admin/management/internal/MBeanRegistererTest.java
Tue Nov 10 20:40:46 2009
@@ -0,0 +1,65 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.felix.karaf.admin.management.internal;
+
+import java.util.Map;
+import java.util.HashMap;
+
+import javax.management.MBeanServer;
+import javax.management.ObjectName;
+
+import org.apache.felix.karaf.admin.management.AdminServiceMBean;
+
+import static org.easymock.classextension.EasyMock.*;
+import org.easymock.classextension.IMocksControl;
+
+import junit.framework.TestCase;
+import org.junit.Assert;
+
+public class MBeanRegistererTest extends TestCase {
+    public void testRegistration() throws Exception {
+        IMocksControl control = createNiceControl();
+        MBeanServer mbeanServer = control.createMock(MBeanServer.class);
+        String rawName = "org.apache.felix.karaf:type=admin,name=${karaf.name}";
+        AdminServiceMBean mbean = control.createMock(AdminServiceMBean.class);
+        ObjectName name = new ObjectName("org.apache.felix.karaf:type=admin,name=foobar");
+        expect(mbeanServer.registerMBean(isA(AdminServiceMBean.class), eq(name))).andReturn(null);
+        mbeanServer.unregisterMBean(eq(name));
+        expectLastCall();
+        control.replay();
+
+        String old = System.getProperty("karaf.name");
+        System.setProperty("karaf.name", "foobar");
+        MBeanRegistrer registerer = new MBeanRegistrer();
+        Map<Object, String> mbeans = new HashMap<Object, String>();
+        mbeans.put(mbean, rawName);
+        registerer.setMbeans(mbeans);
+        registerer.registerMBeanServer(mbeanServer);
+        registerer.unregisterMBeanServer(mbeanServer);
+
+        restoreProperties(old);
+        control.verify();
+    }
+
+    private void restoreProperties(String old) {
+        if (old != null) {
+           System.setProperty("karaf.name", old);
+        } else { 
+           System.getProperties().remove("karaf.name");
+        }
+    }
+}

Modified: felix/trunk/karaf/features/management/src/main/java/org/apache/felix/karaf/features/management/internal/MBeanRegistrer.java
URL: http://svn.apache.org/viewvc/felix/trunk/karaf/features/management/src/main/java/org/apache/felix/karaf/features/management/internal/MBeanRegistrer.java?rev=834657&r1=834656&r2=834657&view=diff
==============================================================================
--- felix/trunk/karaf/features/management/src/main/java/org/apache/felix/karaf/features/management/internal/MBeanRegistrer.java
(original)
+++ felix/trunk/karaf/features/management/src/main/java/org/apache/felix/karaf/features/management/internal/MBeanRegistrer.java
Tue Nov 10 20:40:46 2009
@@ -57,7 +57,8 @@
     protected void registerMBeans() throws JMException {
         if (mbeanServer != null && mbeans != null) {
             for (Map.Entry<Object, String> entry : mbeans.entrySet()) {
-                mbeanServer.registerMBean(entry.getKey(), new ObjectName(entry.getValue()));
+                String value = parseProperty(entry.getValue());
+                mbeanServer.registerMBean(entry.getKey(), new ObjectName(value));
             }
         }
     }
@@ -65,8 +66,20 @@
     protected void unregisterMBeans() throws JMException {
         if (mbeanServer != null && mbeans != null) {
             for (Map.Entry<Object, String> entry : mbeans.entrySet()) {
-                mbeanServer.unregisterMBean(new ObjectName(entry.getValue()));
+                String value = parseProperty(entry.getValue());
+                mbeanServer.unregisterMBean(new ObjectName(value));
             }
         }
     }
+
+    protected String parseProperty(String raw) {
+        if (raw.indexOf("${") > -1 && raw.indexOf("}", raw.indexOf("${")) >
-1) {
+            String var = raw.substring(raw.indexOf("${") + 2, raw.indexOf("}"));
+            String val = System.getProperty(var);
+            if (val != null) {
+                raw = raw.replace("${" + var + "}", val);
+            }
+        }
+        return raw;
+    }
 }

Modified: felix/trunk/karaf/features/management/src/main/resources/OSGI-INF/blueprint/features-management.xml
URL: http://svn.apache.org/viewvc/felix/trunk/karaf/features/management/src/main/resources/OSGI-INF/blueprint/features-management.xml?rev=834657&r1=834656&r2=834657&view=diff
==============================================================================
--- felix/trunk/karaf/features/management/src/main/resources/OSGI-INF/blueprint/features-management.xml
(original)
+++ felix/trunk/karaf/features/management/src/main/resources/OSGI-INF/blueprint/features-management.xml
Tue Nov 10 20:40:46 2009
@@ -41,7 +41,7 @@
                             <argument value="org.apache.felix.karaf.features.management.FeaturesServiceMBean"/>
                         </bean>
                     </key>
-                    <value>org.apache.felix.karaf:service=features</value>
+                    <value>org.apache.felix.karaf:type=features,name=${karaf.name}</value>
                 </entry>
             </map>
         </property>



Mime
View raw message