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/08 15:10:10 UTC
svn commit: r1199252 - in /aries/trunk/sandbox/jmx-next:
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/jmx/framework/
Author: davidb
Date: Tue Nov 8 14:10:10 2011
New Revision: 1199252
URL: http://svn.apache.org/viewvc?rev=1199252&view=rev
Log:
Implement ServiceStateMBean.getService()
Modified:
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-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=1199252&r1=1199251&r2=1199252&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 14:10:10 2011
@@ -41,7 +41,7 @@ import org.osgi.jmx.framework.ServiceSta
* <tt>ServiceData</tt> represents Service Type @see {@link ServiceStateMBean#SERVICE_TYPE}. It is a codec for the
* <code>CompositeData</code> representing an OSGi <code>ServiceReference</code>.
* </p>
- *
+ *
* @version $Rev$ $Date$
*/
public class ServiceData {
@@ -50,23 +50,23 @@ public class ServiceData {
* @see ServiceStateMBean#IDENTIFIER_ITEM
*/
private long serviceId;
-
+
/**
* @see ServiceStateMBean#BUNDLE_IDENTIFIER_ITEM
*/
private long bundleId;
-
+
/**
* @see ServiceStateMBean#OBJECT_CLASS_ITEM
*/
private String[] serviceInterfaces;
-
+
// keep properties for next version of the spec
///**
// * @see ServiceStateMBean#PROPERTIES_ITEM
// */
//private List<PropertyData<? extends Object>> properties = new ArrayList<PropertyData<? extends Object>>();
-
+
/**
* @see ServiceStateMBean#USING_BUNDLES_ITEM
*/
@@ -116,7 +116,7 @@ public class ServiceData {
/**
* Constructs a <code>ServiceData</code> object from the given <code>CompositeData</code>
- *
+ *
* @param compositeData
* @return
* @throws IlleglArugmentException
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=1199252&r1=1199251&r2=1199252&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:10:10 2011
@@ -119,6 +119,22 @@ 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;
+ }
+ }
+
+ /**
* @see org.osgi.jmx.framework.ServiceStateMBean#listServices()
*/
public TabularData listServices() throws IOException {
@@ -254,11 +270,6 @@ public class ServiceState extends Notifi
////// 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;
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=1199252&r1=1199251&r2=1199252&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:10:10 2011
@@ -31,11 +31,14 @@ import static org.ops4j.pax.swissbox.tin
import java.io.InputStream;
import java.util.ArrayList;
import java.util.Arrays;
+import java.util.HashSet;
import java.util.List;
+import java.util.Set;
import javax.management.Notification;
import javax.management.NotificationListener;
import javax.management.ObjectName;
+import javax.management.openmbean.CompositeData;
import javax.management.openmbean.TabularData;
import org.apache.aries.jmx.AbstractIntegrationTest;
@@ -47,7 +50,9 @@ 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;
@@ -66,8 +71,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"),
@@ -237,4 +242,22 @@ public class ServiceStateMBeanTest exten
Arrays.sort(actualServiceIds);
assertTrue(Arrays.equals(expectedServiceIds, actualServiceIds));
}
+
+ @Test
+ public void testGetService() throws Exception {
+ ServiceStateMBean mbean = getMBean(ServiceStateMBean.OBJECTNAME, ServiceStateMBean.class);
+
+ ServiceReference<InterfaceA> sref = bundleContext.getServiceReference(InterfaceA.class);
+ Long serviceID = (Long) sref.getProperty(Constants.SERVICE_ID);
+
+ CompositeData svcData = mbean.getService(serviceID);
+ assertEquals(serviceID, svcData.get(ServiceStateMBean.IDENTIFIER));
+ assertEquals(sref.getBundle().getBundleId(), svcData.get(ServiceStateMBean.BUNDLE_IDENTIFIER));
+ Set<String> expectedClasses = new HashSet<String>(Arrays.asList(InterfaceA.class.getName(), ManagedService.class.getName()));
+ Set<String> actualClasses = new HashSet<String>(Arrays.asList((String []) svcData.get(ServiceStateMBean.OBJECT_CLASS)));
+ assertEquals(expectedClasses, actualClasses);
+ Bundle[] ub = sref.getUsingBundles();
+ assertEquals("Precondition", 1, ub.length);
+ assertTrue(Arrays.equals(new Long[] {ub[0].getBundleId()}, (Long[]) svcData.get("UsingBundles")));
+ }
}