You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@aries.apache.org by da...@apache.org on 2011/11/01 11:29:25 UTC

svn commit: r1195917 - in /aries/trunk/sandbox/jmx-next: jmx-api/src/main/java/org/osgi/jmx/framework/ jmx-core/src/main/java/org/apache/aries/jmx/framework/ jmx-itests/src/test/java/org/apache/aries/jmx/framework/

Author: davidb
Date: Tue Nov  1 10:29:25 2011
New Revision: 1195917

URL: http://svn.apache.org/viewvc?rev=1195917&view=rev
Log:
Add getServiceIds() to ServiceStateMBean

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/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=1195917&r1=1195916&r2=1195917&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  1 10:29:25 2011
@@ -1,6 +1,6 @@
 /*
  * Copyright (c) OSGi Alliance (2009, 2010). All Rights Reserved.
- * 
+ *
  * Licensed 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
@@ -18,6 +18,7 @@ package org.osgi.jmx.framework;
 
 import java.io.IOException;
 
+import javax.management.openmbean.CompositeData;
 import javax.management.openmbean.CompositeType;
 import javax.management.openmbean.SimpleType;
 import javax.management.openmbean.TabularData;
@@ -30,7 +31,7 @@ import org.osgi.jmx.JmxConstants;
  * This MBean represents the Service state of the framework. This MBean also
  * emits events that clients can use to get notified of the changes in the
  * service state of the framework.
- * 
+ *
  * @version $Revision$
  * @ThreadSafe
  */
@@ -172,7 +173,7 @@ public interface ServiceStateMBean {
 
 	/**
 	 * Answer the list of interfaces that this service implements
-	 * 
+	 *
 	 * @param serviceId
 	 *            the identifier of the service
 	 * @return the list of interfaces
@@ -185,7 +186,7 @@ public interface ServiceStateMBean {
 
 	/**
 	 * Answer the bundle identifier of the bundle which registered the service
-	 * 
+	 *
 	 * @param serviceId
 	 *            the identifier of the service
 	 * @return the identifier for the bundle
@@ -195,12 +196,13 @@ public interface ServiceStateMBean {
 	 *             if the service indicated does not exist
 	 */
 	long getBundleIdentifier(long serviceId) throws IOException;
+	CompositeData getService(long serviceId) throws IOException;
 
 	/**
 	 * Answer the map of properties associated with this service
-	 * 
+	 *
 	 * @see JmxConstants#PROPERTIES_TYPE for the details of the TabularType
-	 * 
+	 *
 	 * @param serviceId
 	 *            the identifier of the service
 	 * @return the table of properties. These include the standard mandatory
@@ -212,12 +214,14 @@ public interface ServiceStateMBean {
 	 *             if the service indicated does not exist
 	 */
 	TabularData getProperties(long serviceId) throws IOException;
+	CompositeData getProperty(long serviceId, String key) throws IOException;
+	long[] getServiceIds() throws IOException;
 
 	/**
 	 * Answer the service state of the system in tabular form.
-	 * 
+	 *
 	 * @see #SERVICES_TYPE for the details of the TabularType
-	 * 
+	 *
 	 * @return the tabular representation of the service state
 	 * @throws IOException
 	 *             If the operation fails
@@ -225,10 +229,12 @@ public interface ServiceStateMBean {
 	 *             if the service indicated does not exist
 	 */
 	TabularData listServices() throws IOException;
+	TabularData listServices(String clazz, String filter) throws IOException;
+    TabularData listServices(String clazz, String filter, String [] serviceTypeItems) throws IOException;
 
 	/**
 	 * Answer the list of identifiers of the bundles that use the service
-	 * 
+	 *
 	 * @param serviceId
 	 *            the identifier of the service
 	 * @return the list of bundle identifiers

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=1195917&r1=1195916&r2=1195917&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  1 10:29:25 2011
@@ -34,6 +34,7 @@ import javax.management.MBeanServer;
 import javax.management.Notification;
 import javax.management.NotificationBroadcasterSupport;
 import javax.management.ObjectName;
+import javax.management.openmbean.CompositeData;
 import javax.management.openmbean.TabularData;
 import javax.management.openmbean.TabularDataSupport;
 
@@ -55,7 +56,7 @@ import org.osgi.service.log.LogService;
 /**
  * Implementation of <code>ServiceStateMBean</code> which emits JMX <code>Notification</code> for framework
  * <code>ServiceEvent</code> events
- * 
+ *
  * @version $Rev$ $Date$
  */
 public class ServiceState extends NotificationBroadcasterSupport implements ServiceStateMBean, MBeanRegistration {
@@ -148,6 +149,27 @@ public class ServiceState extends Notifi
     }
 
     /**
+     * @see org.osgi.jmx.framework.ServiceStateMBean#getServiceIds()
+     */
+    public long[] getServiceIds() throws IOException {
+        try {
+            ServiceReference<?>[] refs = bundleContext.getAllServiceReferences(null, null);
+            long[] ids = new long[refs.length];
+            for (int i=0; i < refs.length; i++) {
+                ServiceReference<?> ref = refs[i];
+                long id = (Long) ref.getProperty(Constants.SERVICE_ID);
+                ids[i] = id;
+            }
+
+            return ids;
+        } catch (InvalidSyntaxException e) {
+            IOException ioe = new IOException();
+            ioe.initCause(e);
+            throw ioe;
+        }
+    }
+
+    /**
      * @see javax.management.MBeanRegistration#postDeregister()
      */
     public void postDeregister() {
@@ -218,7 +240,7 @@ public class ServiceState extends Notifi
                // ignore
             }
         }
-        if (eventDispatcher != null) {  
+        if (eventDispatcher != null) {
             eventDispatcher.shutdown();
         }
     }
@@ -230,4 +252,26 @@ public class ServiceState extends Notifi
         return eventDispatcher;
     }
 
+    ////// TODO these
+
+    public CompositeData getService(long serviceId) throws IOException {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
+    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;
+    }
+
+    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=1195917&r1=1195916&r2=1195917&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  1 10:29:25 2011
@@ -66,6 +66,9 @@ 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 ),
+
                         PaxRunnerOptions.rawPaxRunnerOption("config", "classpath:ss-runner.properties"),
                         CoreOptions.equinox().version("3.7.0.v20110613"),
                         paxLogging("INFO"),
@@ -110,10 +113,7 @@ public class ServiceStateMBeanTest exten
                                 		",org.osgi.service.cm")
                                 .set(Constants.BUNDLE_ACTIVATOR,
                                         org.apache.aries.jmx.test.bundleb.Activator.class.getName())
-                                .build(withBnd()))//,
-                                /* For debugging, uncomment the next two lines */
-//                              vmOption("-Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=7777"),
-//                              waitForFrameworkStartup()
+                                .build(withBnd()))
                         );
     }
 
@@ -183,9 +183,10 @@ public class ServiceStateMBeanTest exten
 
         // listServices
 
+        ServiceReference<?>[] allSvsRefs = bundleContext.getAllServiceReferences(null, null);
         TabularData allServices = mbean.listServices();
         assertNotNull(allServices);
-        assertEquals(bundleContext.getAllServiceReferences(null, null).length, allServices.values().size());
+        assertEquals(allSvsRefs.length, allServices.values().size());
 
         // notifications
 
@@ -222,4 +223,18 @@ public class ServiceStateMBeanTest exten
 
     }
 
+    @Test
+    public void testGetServiceIds() throws Exception {
+        ServiceStateMBean mbean = getMBean(ServiceStateMBean.OBJECTNAME, ServiceStateMBean.class);
+
+        ServiceReference<?>[] allSvsRefs = bundleContext.getAllServiceReferences(null, null);
+        long[] expectedServiceIds = new long[allSvsRefs.length];
+        for (int i=0; i < allSvsRefs.length; i++) {
+            expectedServiceIds[i] = (Long) allSvsRefs[i].getProperty(Constants.SERVICE_ID);
+        }
+        long[] actualServiceIds = mbean.getServiceIds();
+        Arrays.sort(expectedServiceIds);
+        Arrays.sort(actualServiceIds);
+        assertTrue(Arrays.equals(expectedServiceIds, actualServiceIds));
+    }
 }