aries-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dav...@apache.org
Subject svn commit: r1199323 - in /aries/trunk/sandbox/jmx-next: jmx-api/src/main/java/org/osgi/jmx/framework/ jmx-core/src/main/java/org/apache/aries/jmx/codec/ jmx-core/src/main/java/org/apache/aries/jmx/framework/ jmx-itests/src/test/java/org/apache/aries/j...
Date Tue, 08 Nov 2011 16:10:07 GMT
Author: davidb
Date: Tue Nov  8 16:10:06 2011
New Revision: 1199323

URL: http://svn.apache.org/viewvc?rev=1199323&view=rev
Log:
Implement ServiceStateMBean.listServices(class, filter, items)

Modified:
    aries/trunk/sandbox/jmx-next/jmx-api/src/main/java/org/osgi/jmx/framework/ServiceStateMBean.java
    aries/trunk/sandbox/jmx-next/jmx-core/src/main/java/org/apache/aries/jmx/codec/ServiceData.java
    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-api/src/main/java/org/osgi/jmx/framework/ServiceStateMBean.java
URL: http://svn.apache.org/viewvc/aries/trunk/sandbox/jmx-next/jmx-api/src/main/java/org/osgi/jmx/framework/ServiceStateMBean.java?rev=1199323&r1=1199322&r2=1199323&view=diff
==============================================================================
--- aries/trunk/sandbox/jmx-next/jmx-api/src/main/java/org/osgi/jmx/framework/ServiceStateMBean.java
(original)
+++ aries/trunk/sandbox/jmx-next/jmx-api/src/main/java/org/osgi/jmx/framework/ServiceStateMBean.java
Tue Nov  8 16:10:06 2011
@@ -230,7 +230,7 @@ public interface ServiceStateMBean {
 	 */
 	TabularData listServices() throws IOException;
 	TabularData listServices(String clazz, String filter) throws IOException;
-    TabularData listServices(String clazz, String filter, String [] serviceTypeItems) throws
IOException;
+    TabularData listServices(String clazz, String filter, String ... serviceTypeItems) throws
IOException;
 
 	/**
 	 * Answer the list of identifiers of the bundles that use the service

Modified: aries/trunk/sandbox/jmx-next/jmx-core/src/main/java/org/apache/aries/jmx/codec/ServiceData.java
URL: http://svn.apache.org/viewvc/aries/trunk/sandbox/jmx-next/jmx-core/src/main/java/org/apache/aries/jmx/codec/ServiceData.java?rev=1199323&r1=1199322&r2=1199323&view=diff
==============================================================================
--- aries/trunk/sandbox/jmx-next/jmx-core/src/main/java/org/apache/aries/jmx/codec/ServiceData.java
(original)
+++ aries/trunk/sandbox/jmx-next/jmx-core/src/main/java/org/apache/aries/jmx/codec/ServiceData.java
Tue Nov  8 16:10:06 2011
@@ -25,6 +25,7 @@ import static org.osgi.jmx.framework.Ser
 import static org.osgi.jmx.framework.ServiceStateMBean.SERVICE_TYPE;
 import static org.osgi.jmx.framework.ServiceStateMBean.USING_BUNDLES;
 
+import java.util.Collection;
 import java.util.HashMap;
 import java.util.Map;
 
@@ -94,24 +95,41 @@ public class ServiceData {
      * @return
      */
     public CompositeData toCompositeData() {
-        CompositeData result = null;
+        return toCompositeData(ServiceStateMBean.SERVICE_TYPE.keySet());
+    }
+
+    public CompositeData toCompositeData(Collection<String> itemNames) {
         Map<String, Object> items = new HashMap<String, Object>();
+
         items.put(IDENTIFIER, this.serviceId);
-        items.put(BUNDLE_IDENTIFIER, this.bundleId);
-        items.put(OBJECT_CLASS, this.serviceInterfaces);
+
+        if (itemNames.contains(BUNDLE_IDENTIFIER))
+            items.put(BUNDLE_IDENTIFIER, this.bundleId);
+
+        if (itemNames.contains(OBJECT_CLASS))
+            items.put(OBJECT_CLASS, this.serviceInterfaces);
+
         //TabularData propertiesTable = new TabularDataSupport(PROPERTIES_TYPE);
         //for (PropertyData<? extends Object> propertyData : this.properties) {
         //    propertiesTable.put(propertyData.toCompositeData());
         //}
         // items.put(PROPERTIES, propertiesTable);
-        items.put(USING_BUNDLES, toLong(this.usingBundles));
+
+        if (itemNames.contains(USING_BUNDLES))
+            items.put(USING_BUNDLES, toLong(this.usingBundles));
+
+        String[] allItemNames = SERVICE_TYPE.keySet().toArray(new String [] {});
+        Object[] itemValues = new Object[allItemNames.length];
+        for (int i=0; i < allItemNames.length; i++) {
+            itemValues[i] = items.get(allItemNames[i]);
+        }
+
         try {
-            result = new CompositeDataSupport(SERVICE_TYPE, items);
+            return new CompositeDataSupport(SERVICE_TYPE, allItemNames, itemValues);
         } catch (OpenDataException e) {
             throw new IllegalStateException("Failed to create CompositeData for ServiceReference
with "
                     + Constants.SERVICE_ID + " [" + this.serviceId + "]", e);
         }
-        return result;
     }
 
     /**

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=1199323&r1=1199322&r2=1199323&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 16:10:06 2011
@@ -21,6 +21,8 @@ import static org.apache.aries.jmx.util.
 import static org.osgi.jmx.JmxConstants.PROPERTIES_TYPE;
 
 import java.io.IOException;
+import java.util.Arrays;
+import java.util.Collection;
 import java.util.concurrent.ExecutorService;
 import java.util.concurrent.Executors;
 import java.util.concurrent.RejectedExecutionException;
@@ -144,6 +146,17 @@ public class ServiceState extends Notifi
      * @see org.osgi.jmx.framework.ServiceStateMBean#listServices(java.lang.String, java.lang.String)
      */
     public TabularData listServices(String clazz, String filter) throws IOException {
+        return listServices(clazz, filter, ServiceStateMBean.SERVICE_TYPE.keySet());
+    }
+
+    /**
+     * @see org.osgi.jmx.framework.ServiceStateMBean#listServices(java.lang.String, java.lang.String,
java.lang.String...)
+     */
+    public TabularData listServices(String clazz, String filter, String ... serviceTypeItems)
throws IOException {
+        return listServices(clazz, filter, Arrays.asList(serviceTypeItems));
+    }
+
+    private TabularData listServices(String clazz, String filter, Collection<String>
serviceTypeItems) throws IOException {
         TabularData servicesTable = new TabularDataSupport(SERVICES_TYPE);
         ServiceReference[] allServiceReferences = null;
         try {
@@ -153,7 +166,7 @@ public class ServiceState extends Notifi
         }
         if (allServiceReferences != null) {
             for (ServiceReference reference : allServiceReferences) {
-                servicesTable.put(new ServiceData(reference).toCompositeData());
+                servicesTable.put(new ServiceData(reference).toCompositeData(serviceTypeItems));
             }
         }
         return servicesTable;
@@ -273,10 +286,4 @@ public class ServiceState extends Notifi
     protected ExecutorService getEventDispatcher() {
         return eventDispatcher;
     }
-
-    public TabularData listServices(String clazz, String filter, String[] serviceTypeItems)
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=1199323&r1=1199322&r2=1199323&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 16:10:06 2011
@@ -31,6 +31,7 @@ import static org.ops4j.pax.swissbox.tin
 import java.io.InputStream;
 import java.util.ArrayList;
 import java.util.Arrays;
+import java.util.Collection;
 import java.util.HashSet;
 import java.util.List;
 import java.util.Set;
@@ -50,9 +51,7 @@ import org.ops4j.pax.exam.CoreOptions;
 import org.ops4j.pax.exam.Customizer;
 import org.ops4j.pax.exam.Option;
 import org.ops4j.pax.exam.container.def.PaxRunnerOptions;
-import org.ops4j.pax.exam.container.def.options.VMOption;
 import org.ops4j.pax.exam.junit.Configuration;
-import org.ops4j.pax.exam.options.TimeoutOption;
 import org.osgi.framework.Bundle;
 import org.osgi.framework.Constants;
 import org.osgi.framework.ServiceReference;
@@ -71,8 +70,8 @@ public class ServiceStateMBeanTest exten
     @Configuration
     public static Option[] configuration() {
         return testOptions(
-                        new VMOption( "-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000"
),
-                        new TimeoutOption( 0 ),
+                        // new VMOption( "-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000"
),
+                        // new TimeoutOption( 0 ),
 
                         PaxRunnerOptions.rawPaxRunnerOption("config", "classpath:ss-runner.properties"),
                         CoreOptions.equinox().version("3.7.0.v20110613"),
@@ -288,10 +287,32 @@ public class ServiceStateMBeanTest exten
         assertEquals(refs.length, svcData.size());
 
         ServiceReference<InterfaceA> sref = bundleContext.getServiceReference(InterfaceA.class);
-        TabularData svcAData = mbean.listServices(InterfaceA.class.getName(), null);
-        assertEquals(1, svcAData.size());
-        CompositeData actualSvc = (CompositeData) svcAData.values().iterator().next();
+        TabularData svcTab = mbean.listServices(InterfaceA.class.getName(), null);
+        assertEquals(1, svcTab.size());
+        CompositeData actualSvc = (CompositeData) svcTab.values().iterator().next();
         CompositeData expectedSvc = mbean.getService((Long) sref.getProperty(Constants.SERVICE_ID));
         assertEquals(expectedSvc, actualSvc);
     }
+
+    @Test
+    public void testListServicesSelectiveItems() throws Exception {
+        ServiceStateMBean mbean = getMBean(ServiceStateMBean.OBJECTNAME, ServiceStateMBean.class);
+
+        String filter = "(|(service.pid=org.apache.aries.jmx.test.ServiceB)(service.pid=jmx.test.B.factory))";
+        ServiceReference<?>[] refs = bundleContext.getAllServiceReferences(null, filter);
+        TabularData svcData = mbean.listServices(null, filter, ServiceStateMBean.BUNDLE_IDENTIFIER);
+        assertEquals(refs.length, svcData.size());
+
+        long id = refs[0].getBundle().getBundleId();
+        for (ServiceReference<?> ref : refs) {
+            assertEquals("Precondition", id, ref.getBundle().getBundleId());
+        }
+
+        for (CompositeData cd : new ArrayList<CompositeData>((Collection<CompositeData>)
svcData.values())) {
+            assertEquals(id, cd.get(ServiceStateMBean.BUNDLE_IDENTIFIER));
+            assertNotNull(cd.get(ServiceStateMBean.IDENTIFIER));
+            assertNull(cd.get(ServiceStateMBean.OBJECT_CLASS));
+            assertNull(cd.get(ServiceStateMBean.USING_BUNDLES));
+        }
+    }
 }



Mime
View raw message