aries-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dav...@apache.org
Subject svn commit: r1190411 - 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/ jmx-itests/src/test/java/org/apache/aries/jmx/framework/
Date Fri, 28 Oct 2011 15:57:35 GMT
Author: davidb
Date: Fri Oct 28 15:57:35 2011
New Revision: 1190411

URL: http://svn.apache.org/viewvc?rev=1190411&view=rev
Log:
Add more content to the result of BundleRevisiontStateMBean.getCurrentWiring().

Modified:
    aries/trunk/sandbox/jmx-next/jmx-core/src/main/java/org/apache/aries/jmx/codec/BundleWiringData.java
    aries/trunk/sandbox/jmx-next/jmx-core/src/main/java/org/apache/aries/jmx/framework/BundleRevisionsState.java
    aries/trunk/sandbox/jmx-next/jmx-itests/pom.xml
    aries/trunk/sandbox/jmx-next/jmx-itests/src/test/java/org/apache/aries/jmx/framework/BundleRevisionsStateMBeanTest.java
    aries/trunk/sandbox/jmx-next/jmx-itests/src/test/java/org/apache/aries/jmx/framework/BundleStateMBeanTest.java

Modified: aries/trunk/sandbox/jmx-next/jmx-core/src/main/java/org/apache/aries/jmx/codec/BundleWiringData.java
URL: http://svn.apache.org/viewvc/aries/trunk/sandbox/jmx-next/jmx-core/src/main/java/org/apache/aries/jmx/codec/BundleWiringData.java?rev=1190411&r1=1190410&r2=1190411&view=diff
==============================================================================
--- aries/trunk/sandbox/jmx-next/jmx-core/src/main/java/org/apache/aries/jmx/codec/BundleWiringData.java
(original)
+++ aries/trunk/sandbox/jmx-next/jmx-core/src/main/java/org/apache/aries/jmx/codec/BundleWiringData.java
Fri Oct 28 15:57:35 2011
@@ -19,9 +19,11 @@ package org.apache.aries.jmx.codec;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
+import java.util.Set;
 
 import javax.management.openmbean.CompositeData;
 import javax.management.openmbean.CompositeDataSupport;
+import javax.management.openmbean.CompositeType;
 import javax.management.openmbean.OpenDataException;
 import javax.management.openmbean.TabularData;
 import javax.management.openmbean.TabularDataSupport;
@@ -34,12 +36,10 @@ import org.osgi.jmx.framework.BundleRevi
 public class BundleWiringData {
     private final long bundleId;
     private final List<BundleCapability> capabilities;
-    private final String namespace;
     private final List<BundleRequirement> requirements;
 
-    public BundleWiringData(long bundleId, String namespace, List<BundleCapability>
capabilities, List<BundleRequirement> requirements, List<BundleWire> requiredWires)
{
+    public BundleWiringData(long bundleId, List<BundleCapability> capabilities, List<BundleRequirement>
requirements, List<BundleWire> requiredWires) {
         this.bundleId = bundleId;
-        this.namespace = namespace;
         this.capabilities = capabilities;
         this.requirements = requirements;
     }
@@ -50,41 +50,8 @@ public class BundleWiringData {
             items.put(BundleRevisionsStateMBean.BUNDLE_ID, bundleId);
             items.put(BundleRevisionsStateMBean.BUNDLE_REVISION_ID, null);
 
-
-            CompositeData [] reqData = new CompositeData[requirements.size()];
-            for (int i=0; i < requirements.size(); i++) {
-                BundleRequirement requirement = requirements.get(i);
-                Map<String, Object> reqItems = new HashMap<String, Object>();
-
-                TabularData attributes = new TabularDataSupport(BundleRevisionsStateMBean.ATTRIBUTES_TYPE);
-                for (Map.Entry<String, Object> entry : requirement.getAttributes().entrySet())
{
-                    PropertyData<?> pd = PropertyData.newInstance(entry.getKey(), entry.getValue());
-                    attributes.put(pd.toCompositeData());
-                }
-                reqItems.put(BundleRevisionsStateMBean.ATTRIBUTES, attributes);
-
-                TabularData directives = new TabularDataSupport(BundleRevisionsStateMBean.DIRECTIVES_TYPE);
-                for (Map.Entry<String, String> entry : requirement.getDirectives().entrySet())
{
-                    CompositeData directive = new CompositeDataSupport(BundleRevisionsStateMBean.DIRECTIVE_TYPE,
-                        new String[] { BundleRevisionsStateMBean.KEY, BundleRevisionsStateMBean.VALUE
},
-                        new Object[] { entry.getKey(), entry.getValue() });
-                    directives.put(directive);
-                }
-                reqItems.put(BundleRevisionsStateMBean.DIRECTIVES, directives);
-                reqItems.put(BundleRevisionsStateMBean.NAMESPACE, requirement.getNamespace());
-
-                CompositeData req = new CompositeDataSupport(BundleRevisionsStateMBean.BUNDLE_REQUIREMENT_TYPE,
reqItems);
-                reqData[i] = req;
-            }
-
-//            CompositeDataSupport directive = new CompositeDataSupport(BundleRevisionsStateMBean.DIRECTIVE_TYPE,
new String [] {"Key", "Value"}, new Object [] {"Foo", "Bar"});
-//            directives.put(directive);
-//            reqItems.put(BundleRevisionsStateMBean.DIRECTIVES, directives);
-//            reqItems.put(BundleRevisionsStateMBean.NAMESPACE, namespace);
-//            CompositeDataSupport requirements = new CompositeDataSupport(BundleRevisionsStateMBean.BUNDLE_REQUIREMENT_TYPE,
reqItems);
-
-            items.put(BundleRevisionsStateMBean.REQUIREMENTS, reqData);
-            items.put(BundleRevisionsStateMBean.CAPABILITIES, null);
+            items.put(BundleRevisionsStateMBean.REQUIREMENTS, getRequirements());
+            items.put(BundleRevisionsStateMBean.CAPABILITIES, getCapabilities());
             items.put(BundleRevisionsStateMBean.BUNDLE_WIRES_TYPE, null);
 
             return new CompositeDataSupport(BundleRevisionsStateMBean.BUNDLE_WIRING_TYPE,
items);
@@ -92,4 +59,48 @@ public class BundleWiringData {
             throw new IllegalStateException("Can't create CompositeData" + e);
         }
     }
+
+    private CompositeData[] getCapabilities() throws OpenDataException {
+        CompositeData[] capData = new CompositeData[capabilities.size()];
+        for (int i=0; i < capabilities.size(); i++) {
+            BundleCapability capability = capabilities.get(i);
+            capData[i] = getCapReqCompositeData(BundleRevisionsStateMBean.BUNDLE_CAPABILITY_TYPE,
+                capability.getNamespace(), capability.getAttributes().entrySet(), capability.getDirectives().entrySet());
+        }
+        return capData;
+    }
+
+    private CompositeData[] getRequirements() throws OpenDataException {
+        CompositeData [] reqData = new CompositeData[requirements.size()];
+        for (int i=0; i < requirements.size(); i++) {
+            BundleRequirement requirement = requirements.get(i);
+            reqData[i] = getCapReqCompositeData(BundleRevisionsStateMBean.BUNDLE_REQUIREMENT_TYPE,
+                    requirement.getNamespace(), requirement.getAttributes().entrySet(), requirement.getDirectives().entrySet());
+        }
+        return reqData;
+    }
+
+    private CompositeData getCapReqCompositeData(CompositeType type, String namespace, Set<Map.Entry<String,Object>>
attributeSet, Set<Map.Entry<String,String>> directiveSet) throws OpenDataException
{
+        Map<String, Object> reqItems = new HashMap<String, Object>();
+
+        TabularData attributes = new TabularDataSupport(BundleRevisionsStateMBean.ATTRIBUTES_TYPE);
+        for (Map.Entry<String, Object> entry : attributeSet) {
+            PropertyData<?> pd = PropertyData.newInstance(entry.getKey(), entry.getValue());
+            attributes.put(pd.toCompositeData());
+        }
+        reqItems.put(BundleRevisionsStateMBean.ATTRIBUTES, attributes);
+
+        TabularData directives = new TabularDataSupport(BundleRevisionsStateMBean.DIRECTIVES_TYPE);
+        for (Map.Entry<String, String> entry : directiveSet) {
+            CompositeData directive = new CompositeDataSupport(BundleRevisionsStateMBean.DIRECTIVE_TYPE,
+                new String[] { BundleRevisionsStateMBean.KEY, BundleRevisionsStateMBean.VALUE
},
+                new Object[] { entry.getKey(), entry.getValue() });
+            directives.put(directive);
+        }
+        reqItems.put(BundleRevisionsStateMBean.DIRECTIVES, directives);
+        reqItems.put(BundleRevisionsStateMBean.NAMESPACE, namespace);
+
+        CompositeData req = new CompositeDataSupport(type, reqItems);
+        return req;
+    }
 }

Modified: aries/trunk/sandbox/jmx-next/jmx-core/src/main/java/org/apache/aries/jmx/framework/BundleRevisionsState.java
URL: http://svn.apache.org/viewvc/aries/trunk/sandbox/jmx-next/jmx-core/src/main/java/org/apache/aries/jmx/framework/BundleRevisionsState.java?rev=1190411&r1=1190410&r2=1190411&view=diff
==============================================================================
--- aries/trunk/sandbox/jmx-next/jmx-core/src/main/java/org/apache/aries/jmx/framework/BundleRevisionsState.java
(original)
+++ aries/trunk/sandbox/jmx-next/jmx-core/src/main/java/org/apache/aries/jmx/framework/BundleRevisionsState.java
Fri Oct 28 15:57:35 2011
@@ -72,11 +72,8 @@ public class BundleRevisionsState implem
         List<BundleRequirement> requirements = wiring.getRequirements(namespace);
         List<BundleWire> requiredWires = wiring.getRequiredWires(namespace);
 
-        System.out.println("******** getCurrentWiring: " + bundle);
-        BundleWiringData data = new BundleWiringData(bundle.getBundleId(), namespace, capabilities,
requirements, requiredWires);
-        CompositeData compositeData = data.toCompositeData();
-        System.out.println("######## " + compositeData);
-        return compositeData;
+        BundleWiringData data = new BundleWiringData(bundle.getBundleId(), capabilities,
requirements, requiredWires);
+        return data.toCompositeData();
     }
 
     /* (non-Javadoc)

Modified: aries/trunk/sandbox/jmx-next/jmx-itests/pom.xml
URL: http://svn.apache.org/viewvc/aries/trunk/sandbox/jmx-next/jmx-itests/pom.xml?rev=1190411&r1=1190410&r2=1190411&view=diff
==============================================================================
--- aries/trunk/sandbox/jmx-next/jmx-itests/pom.xml (original)
+++ aries/trunk/sandbox/jmx-next/jmx-itests/pom.xml Fri Oct 28 15:57:35 2011
@@ -64,6 +64,7 @@
         <dependency>
             <groupId>org.osgi</groupId>
             <artifactId>org.osgi.core</artifactId>
+            <version>4.3.0</version>
             <scope>provided</scope>
         </dependency>
         <dependency>

Modified: aries/trunk/sandbox/jmx-next/jmx-itests/src/test/java/org/apache/aries/jmx/framework/BundleRevisionsStateMBeanTest.java
URL: http://svn.apache.org/viewvc/aries/trunk/sandbox/jmx-next/jmx-itests/src/test/java/org/apache/aries/jmx/framework/BundleRevisionsStateMBeanTest.java?rev=1190411&r1=1190410&r2=1190411&view=diff
==============================================================================
--- aries/trunk/sandbox/jmx-next/jmx-itests/src/test/java/org/apache/aries/jmx/framework/BundleRevisionsStateMBeanTest.java
(original)
+++ aries/trunk/sandbox/jmx-next/jmx-itests/src/test/java/org/apache/aries/jmx/framework/BundleRevisionsStateMBeanTest.java
Fri Oct 28 15:57:35 2011
@@ -29,15 +29,15 @@ import javax.management.ObjectName;
 import javax.management.openmbean.CompositeData;
 
 import org.apache.aries.jmx.AbstractIntegrationTest;
+import org.junit.Assert;
 import org.junit.Test;
 import org.ops4j.pax.exam.CoreOptions;
 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.wiring.BundleWiring;
 import org.osgi.jmx.framework.BundleRevisionsStateMBean;
 import org.osgi.jmx.framework.PackageStateMBean;
 
@@ -51,8 +51,8 @@ public class BundleRevisionsStateMBeanTe
     @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"),
@@ -118,7 +118,13 @@ public class BundleRevisionsStateMBeanTe
         Bundle a = context().getBundleByName("org.apache.aries.jmx.test.bundlea");
 
         CompositeData wiring = brsMBean.getCurrentWiring(a.getBundleId(), BundleRevisionsStateMBean.PACKAGE_NAMESPACE);
-        System.out.println("*** "+wiring);
+
+        Assert.assertEquals(BundleRevisionsStateMBean.BUNDLE_WIRING_TYPE, wiring.getCompositeType());
+        Assert.assertEquals(a.getBundleId(), wiring.get(BundleRevisionsStateMBean.BUNDLE_ID));
+
+        BundleWiring bw = a.adapt(BundleWiring.class);
+        CompositeData[] capabilities = (CompositeData[]) wiring.get(BundleRevisionsStateMBean.CAPABILITIES);
+        Assert.assertEquals(bw.getCapabilities(BundleRevisionsStateMBean.PACKAGE_NAMESPACE).size(),
capabilities.length);
 
         /*
         PackageStateMBean packagaState = getMBean(PackageStateMBean.OBJECTNAME, PackageStateMBean.class);

Modified: aries/trunk/sandbox/jmx-next/jmx-itests/src/test/java/org/apache/aries/jmx/framework/BundleStateMBeanTest.java
URL: http://svn.apache.org/viewvc/aries/trunk/sandbox/jmx-next/jmx-itests/src/test/java/org/apache/aries/jmx/framework/BundleStateMBeanTest.java?rev=1190411&r1=1190410&r2=1190411&view=diff
==============================================================================
--- aries/trunk/sandbox/jmx-next/jmx-itests/src/test/java/org/apache/aries/jmx/framework/BundleStateMBeanTest.java
(original)
+++ aries/trunk/sandbox/jmx-next/jmx-itests/src/test/java/org/apache/aries/jmx/framework/BundleStateMBeanTest.java
Fri Oct 28 15:57:35 2011
@@ -43,9 +43,7 @@ import org.junit.Test;
 import org.ops4j.pax.exam.CoreOptions;
 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;
@@ -62,8 +60,8 @@ public class BundleStateMBeanTest extend
     @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"),



Mime
View raw message