aries-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dav...@apache.org
Subject svn commit: r1199262 - in /aries/trunk/sandbox/jmx-next: jmx-core/src/main/java/org/apache/aries/jmx/framework/ServiceState.java jmx-itests/src/test/java/org/apache/aries/jmx/framework/ServiceStateMBeanTest.java
Date Tue, 08 Nov 2011 14:33:28 GMT
Author: davidb
Date: Tue Nov  8 14:33:28 2011
New Revision: 1199262

URL: http://svn.apache.org/viewvc?rev=1199262&view=rev
Log:
Implement ServiceStateMBean.getProperty()

Modified:
    aries/trunk/sandbox/jmx-next/jmx-core/src/main/java/org/apache/aries/jmx/framework/ServiceState.java
    aries/trunk/sandbox/jmx-next/jmx-itests/src/test/java/org/apache/aries/jmx/framework/ServiceStateMBeanTest.java

Modified: aries/trunk/sandbox/jmx-next/jmx-core/src/main/java/org/apache/aries/jmx/framework/ServiceState.java
URL: http://svn.apache.org/viewvc/aries/trunk/sandbox/jmx-next/jmx-core/src/main/java/org/apache/aries/jmx/framework/ServiceState.java?rev=1199262&r1=1199261&r2=1199262&view=diff
==============================================================================
--- aries/trunk/sandbox/jmx-next/jmx-core/src/main/java/org/apache/aries/jmx/framework/ServiceState.java
(original)
+++ aries/trunk/sandbox/jmx-next/jmx-core/src/main/java/org/apache/aries/jmx/framework/ServiceState.java
Tue Nov  8 14:33:28 2011
@@ -110,6 +110,14 @@ public class ServiceState extends Notifi
     }
 
     /**
+     * @see org.osgi.jmx.framework.ServiceStateMBean#getProperty(long, java.lang.String)
+     */
+    public CompositeData getProperty(long serviceId, String key) throws IOException {
+        ServiceReference reference = resolveService(bundleContext, serviceId);
+            return PropertyData.newInstance(key, reference.getProperty(key)).toCompositeData();
+    }
+
+    /**
      * @see org.osgi.jmx.framework.ServiceStateMBean#getUsingBundles(long)
      */
     public long[] getUsingBundles(long serviceId) throws IOException {
@@ -122,16 +130,7 @@ public class ServiceState extends Notifi
      * @see org.osgi.jmx.framework.ServiceStateMBean#getService(long)
      */
     public CompositeData getService(long serviceId) throws IOException {
-        try {
-            ServiceReference[] srefs = bundleContext.getAllServiceReferences(null, "(" +
Constants.SERVICE_ID + "=" + serviceId + ")");
-            if (srefs.length >= 0) {
-                return new ServiceData(srefs[0]).toCompositeData();
-            } else {
-                return null;
-            }
-        } catch (InvalidSyntaxException e) {
-            return null;
-        }
+        return new ServiceData(resolveService(bundleContext, serviceId)).toCompositeData();
     }
 
     /**
@@ -270,11 +269,6 @@ public class ServiceState extends Notifi
 
     ////// TODO these
 
-    public CompositeData getProperty(long serviceId, String key) throws IOException {
-        // TODO Auto-generated method stub
-        return null;
-    }
-
     public TabularData listServices(String clazz, String filter) throws IOException {
         // TODO Auto-generated method stub
         return null;

Modified: aries/trunk/sandbox/jmx-next/jmx-itests/src/test/java/org/apache/aries/jmx/framework/ServiceStateMBeanTest.java
URL: http://svn.apache.org/viewvc/aries/trunk/sandbox/jmx-next/jmx-itests/src/test/java/org/apache/aries/jmx/framework/ServiceStateMBeanTest.java?rev=1199262&r1=1199261&r2=1199262&view=diff
==============================================================================
--- aries/trunk/sandbox/jmx-next/jmx-itests/src/test/java/org/apache/aries/jmx/framework/ServiceStateMBeanTest.java
(original)
+++ aries/trunk/sandbox/jmx-next/jmx-itests/src/test/java/org/apache/aries/jmx/framework/ServiceStateMBeanTest.java
Tue Nov  8 14:33:28 2011
@@ -244,7 +244,7 @@ public class ServiceStateMBeanTest exten
     }
 
     @Test
-    public void testGetService() throws Exception {
+    public void testGetServiceAndGetProperty() throws Exception {
         ServiceStateMBean mbean = getMBean(ServiceStateMBean.OBJECTNAME, ServiceStateMBean.class);
 
         ServiceReference<InterfaceA> sref = bundleContext.getServiceReference(InterfaceA.class);
@@ -259,5 +259,22 @@ public class ServiceStateMBeanTest exten
         Bundle[] ub = sref.getUsingBundles();
         assertEquals("Precondition", 1, ub.length);
         assertTrue(Arrays.equals(new Long[] {ub[0].getBundleId()}, (Long[]) svcData.get("UsingBundles")));
+
+        // Test mbean.getProperty()
+        String pid = (String) sref.getProperty(Constants.SERVICE_PID);
+        CompositeData pidData = mbean.getProperty(serviceID, Constants.SERVICE_PID);
+        assertEquals(pid, pidData.get("Value"));
+        assertEquals("String", pidData.get("Type"));
+
+        CompositeData idData = mbean.getProperty(serviceID, Constants.SERVICE_ID);
+        assertEquals("" + serviceID, idData.get("Value"));
+        assertEquals("Long", idData.get("Type"));
+
+        CompositeData ocData = mbean.getProperty(serviceID, Constants.OBJECTCLASS);
+        String form1 = InterfaceA.class.getName() + "," + ManagedService.class.getName();
+        String form2 = ManagedService.class.getName() + "," + InterfaceA.class.getName();
+        assertTrue(ocData.get("Value").equals(form1) ||
+                   ocData.get("Value").equals(form2));
+        assertEquals("Array of String", ocData.get("Type"));
     }
 }



Mime
View raw message