aries-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dav...@apache.org
Subject svn commit: r1210960 - in /aries/trunk/sandbox/jmx-next: jmx-api/src/main/java/org/osgi/jmx/framework/wiring/ jmx-core/src/main/java/org/apache/aries/jmx/codec/ jmx-core/src/main/java/org/apache/aries/jmx/framework/wiring/ jmx-itests/src/test/java/org/...
Date Tue, 06 Dec 2011 15:04:49 GMT
Author: davidb
Date: Tue Dec  6 15:04:49 2011
New Revision: 1210960

URL: http://svn.apache.org/viewvc?rev=1210960&view=rev
Log:
Support for BundleWiringStateMBeanTest.getRevisionsDeclaredRequirements() and BundleWiringStateMBeanTest.getRevisionsDeclaredCapabilities()


Modified:
    aries/trunk/sandbox/jmx-next/jmx-api/src/main/java/org/osgi/jmx/framework/wiring/BundleWiringStateMBean.java
    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/wiring/BundleWiringState.java
    aries/trunk/sandbox/jmx-next/jmx-itests/src/test/java/org/apache/aries/jmx/framework/wiring/BundleWiringStateMBeanTest.java

Modified: aries/trunk/sandbox/jmx-next/jmx-api/src/main/java/org/osgi/jmx/framework/wiring/BundleWiringStateMBean.java
URL: http://svn.apache.org/viewvc/aries/trunk/sandbox/jmx-next/jmx-api/src/main/java/org/osgi/jmx/framework/wiring/BundleWiringStateMBean.java?rev=1210960&r1=1210959&r2=1210960&view=diff
==============================================================================
--- aries/trunk/sandbox/jmx-next/jmx-api/src/main/java/org/osgi/jmx/framework/wiring/BundleWiringStateMBean.java
(original)
+++ aries/trunk/sandbox/jmx-next/jmx-api/src/main/java/org/osgi/jmx/framework/wiring/BundleWiringStateMBean.java
Tue Dec  6 15:04:49 2011
@@ -166,11 +166,37 @@ public interface BundleWiringStateMBean 
             "The bundle requirements of a bundle revision wiring",
             REQUIREMENT_TYPE_ARRAY);
 
+    CompositeType REVISION_REQUIREMENTS_TYPE =
+        Item.compositeType("REVISION_REQUIREMENTS",
+            "Describes the requirements for a bundle revision",
+            BUNDLE_ID_ITEM,
+            BUNDLE_REVISION_ID_ITEM,
+            REQUIREMENTS_ITEM);
+
+    TabularType REVISIONS_REQUIREMENTS_TYPE =
+        Item.tabularType("REVISIONS_REQUIREMENTS",
+            "The bundle requirements for all bundle revisions",
+            REVISION_REQUIREMENTS_TYPE,
+            BUNDLE_ID, BUNDLE_REVISION_ID);
+
     String CAPABILITIES = "Capabilities";
     Item CAPABILITIES_ITEM = new Item(CAPABILITIES,
             "The bundle capabilities of a bundle revision wiring",
             CAPABILITY_TYPE_ARRAY);
 
+    CompositeType REVISION_CAPABILITIES_TYPE =
+        Item.compositeType("REVISION_CAPABILITIES",
+            "Describes the capabilities for a bundle revision",
+            BUNDLE_ID_ITEM,
+            BUNDLE_REVISION_ID_ITEM,
+            CAPABILITIES_ITEM);
+
+    TabularType REVISIONS_CAPABILITIES_TYPE =
+        Item.tabularType("REVISIONS_CAPABILITIES",
+            "The bundle capabilities for all bundle revisions",
+            REVISION_CAPABILITIES_TYPE,
+            BUNDLE_ID, BUNDLE_REVISION_ID);
+
     String PROVIDED_WIRES = "ProvidedWires";
     Item PROVIDED_WIRES_ITEM = new Item(PROVIDED_WIRES,
             "The bundle wires to the capabilities provided by this bundle wiring.",
@@ -202,8 +228,8 @@ public interface BundleWiringStateMBean 
 
     TabularType BUNDLE_WIRING_CLOSURE_TYPE = Item.tabularType("BUNDLE_WIRING_CLOSURE",
             "A table of bundle wirings describing a full wiring closure",
-            BundleWiringStateMBean.BUNDLE_WIRING_TYPE,
-            BundleWiringStateMBean.BUNDLE_ID, BundleWiringStateMBean.BUNDLE_REVISION_ID);
+            BUNDLE_WIRING_TYPE,
+            BUNDLE_ID, BUNDLE_REVISION_ID);
 
     /**
      * Returns the requirements for the current bundle revision.
@@ -265,7 +291,7 @@ public interface BundleWiringStateMBean 
      * @return the declared requirements for all revisions of <code>bundleId</code>
      *
      */
-    ArrayType getRevisionsDeclaredRequirements(long bundleId,
+    TabularData getRevisionsDeclaredRequirements(long bundleId,
             String namespace) throws IOException;
 
     /**
@@ -278,7 +304,7 @@ public interface BundleWiringStateMBean 
      * @param namespace
      * @return the declared capabilities for all revisions of <code>bundleId</code>
      */
-    ArrayType getRevisionsDeclaredCapabilities(long bundleId,
+    TabularData getRevisionsDeclaredCapabilities(long bundleId,
             String namespace) throws IOException;
 
     /**

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=1210960&r1=1210959&r2=1210960&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
Tue Dec  6 15:04:49 2011
@@ -60,8 +60,8 @@ public class BundleWiringData {
             items.put(BundleWiringStateMBean.BUNDLE_ID, bundleId);
             items.put(BundleWiringStateMBean.BUNDLE_REVISION_ID, revisionId);
 
-            items.put(BundleWiringStateMBean.REQUIREMENTS, getRequirements());
-            items.put(BundleWiringStateMBean.CAPABILITIES, getCapabilities());
+            items.put(BundleWiringStateMBean.REQUIREMENTS, getRequirements(requirements));
+            items.put(BundleWiringStateMBean.CAPABILITIES, getCapabilities(capabilities));
             items.put(BundleWiringStateMBean.REQUIRED_WIRES, getRequiredWires());
             items.put(BundleWiringStateMBean.PROVIDED_WIRES, getProvidedWires());
 
@@ -71,26 +71,50 @@ public class BundleWiringData {
         }
     }
 
-    private CompositeData[] getCapabilities() throws OpenDataException {
-        CompositeData[] capData = new CompositeData[capabilities.size()];
-        for (int i=0; i < capabilities.size(); i++) {
-            BundleCapability capability = capabilities.get(i);
+    private static CompositeData[] getCapabilities(List<BundleCapability> capabilityList)
throws OpenDataException {
+        CompositeData[] capData = new CompositeData[capabilityList.size()];
+        for (int i=0; i < capabilityList.size(); i++) {
+            BundleCapability capability = capabilityList.get(i);
             capData[i] = getCapReqCompositeData(BundleWiringStateMBean.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);
+    private static CompositeData[] getRequirements(List<BundleRequirement> requirementList)
throws OpenDataException {
+        CompositeData [] reqData = new CompositeData[requirementList.size()];
+        for (int i=0; i < requirementList.size(); i++) {
+            BundleRequirement requirement = requirementList.get(i);
             reqData[i] = getCapReqCompositeData(BundleWiringStateMBean.BUNDLE_REQUIREMENT_TYPE,
                 requirement.getNamespace(), requirement.getAttributes().entrySet(), requirement.getDirectives().entrySet());
         }
         return reqData;
     }
 
+    public static CompositeData getRevisionCapabilities(long bundleId, int revisionId, List<BundleCapability>
bundleCapabilities) {
+        try {
+            Map<String, Object> items = new HashMap<String, Object>();
+            items.put(BundleWiringStateMBean.BUNDLE_ID, bundleId);
+            items.put(BundleWiringStateMBean.BUNDLE_REVISION_ID, revisionId);
+            items.put(BundleWiringStateMBean.CAPABILITIES, getCapabilities(bundleCapabilities));
+            return new CompositeDataSupport(BundleWiringStateMBean.REVISION_CAPABILITIES_TYPE,
items);
+        } catch (OpenDataException e) {
+            throw new IllegalStateException("Can't create CompositeData", e);
+        }
+    }
+
+    public static CompositeData getRevisionRequirements(long bundleId, int revisionId, List<BundleRequirement>
bundleRequirements) {
+        try {
+            Map<String, Object> items = new HashMap<String, Object>();
+            items.put(BundleWiringStateMBean.BUNDLE_ID, bundleId);
+            items.put(BundleWiringStateMBean.BUNDLE_REVISION_ID, revisionId);
+            items.put(BundleWiringStateMBean.REQUIREMENTS, getRequirements(bundleRequirements));
+            return new CompositeDataSupport(BundleWiringStateMBean.REVISION_REQUIREMENTS_TYPE,
items);
+        } catch (OpenDataException e) {
+            throw new IllegalStateException("Can't create CompositeData", e);
+        }
+    }
+
     public static CompositeData[] getCapabilitiesCompositeData(List<BundleCapability>
bundleCapabilities) {
         try {
             CompositeData[] data = new CompositeData[bundleCapabilities.size()];

Modified: aries/trunk/sandbox/jmx-next/jmx-core/src/main/java/org/apache/aries/jmx/framework/wiring/BundleWiringState.java
URL: http://svn.apache.org/viewvc/aries/trunk/sandbox/jmx-next/jmx-core/src/main/java/org/apache/aries/jmx/framework/wiring/BundleWiringState.java?rev=1210960&r1=1210959&r2=1210960&view=diff
==============================================================================
--- aries/trunk/sandbox/jmx-next/jmx-core/src/main/java/org/apache/aries/jmx/framework/wiring/BundleWiringState.java
(original)
+++ aries/trunk/sandbox/jmx-next/jmx-core/src/main/java/org/apache/aries/jmx/framework/wiring/BundleWiringState.java
Tue Dec  6 15:04:49 2011
@@ -35,6 +35,7 @@ import org.osgi.framework.BundleContext;
 import org.osgi.framework.wiring.BundleCapability;
 import org.osgi.framework.wiring.BundleRequirement;
 import org.osgi.framework.wiring.BundleRevision;
+import org.osgi.framework.wiring.BundleRevisions;
 import org.osgi.framework.wiring.BundleWire;
 import org.osgi.framework.wiring.BundleWiring;
 import org.osgi.jmx.framework.wiring.BundleWiringStateMBean;
@@ -109,7 +110,7 @@ public class BundleWiringState implement
     }
 
     private void populateTransitiveRevisions(String namespace, BundleRevision rootRevision,
Map<BundleRevision, Integer> allRevisions) {
-        allRevisions.put(rootRevision, rootRevision.hashCode());
+        allRevisions.put(rootRevision, System.identityHashCode(rootRevision));
         BundleWiring wiring = rootRevision.getWiring();
         List<BundleWire> wires = wiring.getRequiredWires(namespace);
         for (BundleWire wire : wires) {
@@ -134,17 +135,35 @@ public class BundleWiringState implement
     /* (non-Javadoc)
      * @see org.osgi.jmx.framework.BundleRevisionsStateMBean#getRevisionsDeclaredRequirements(long,
java.lang.String, boolean)
      */
-    public ArrayType getRevisionsDeclaredRequirements(long bundleId, String namespace) {
-        // TODO Auto-generated method stub
-        return null;
+    public TabularData getRevisionsDeclaredRequirements(long bundleId, String namespace)
throws IOException {
+        Bundle bundle = FrameworkUtils.resolveBundle(bundleContext, bundleId);
+        BundleRevisions revisions = bundle.adapt(BundleRevisions.class);
+
+        TabularData td = new TabularDataSupport(BundleWiringStateMBean.REVISIONS_REQUIREMENTS_TYPE);
+        for (BundleRevision revision : revisions.getRevisions()) {
+            td.put(BundleWiringData.getRevisionRequirements(
+                    revision.getBundle().getBundleId(),
+                    System.identityHashCode(revision),
+                    revision.getDeclaredRequirements(namespace)));
+        }
+        return td;
     }
 
     /* (non-Javadoc)
      * @see org.osgi.jmx.framework.BundleRevisionsStateMBean#getRevisionsDeclaredCapabilities(long,
java.lang.String, boolean)
      */
-    public ArrayType getRevisionsDeclaredCapabilities(long bundleId, String namespace) {
-        // TODO Auto-generated method stub
-        return null;
+    public TabularData getRevisionsDeclaredCapabilities(long bundleId, String namespace)
throws IOException {
+        Bundle bundle = FrameworkUtils.resolveBundle(bundleContext, bundleId);
+        BundleRevisions revisions = bundle.adapt(BundleRevisions.class);
+
+        TabularData td = new TabularDataSupport(BundleWiringStateMBean.REVISIONS_CAPABILITIES_TYPE);
+        for (BundleRevision revision : revisions.getRevisions()) {
+            td.put(BundleWiringData.getRevisionCapabilities(
+                    revision.getBundle().getBundleId(),
+                    System.identityHashCode(revision),
+                    revision.getDeclaredCapabilities(namespace)));
+        }
+        return td;
     }
 
     /* (non-Javadoc)

Modified: aries/trunk/sandbox/jmx-next/jmx-itests/src/test/java/org/apache/aries/jmx/framework/wiring/BundleWiringStateMBeanTest.java
URL: http://svn.apache.org/viewvc/aries/trunk/sandbox/jmx-next/jmx-itests/src/test/java/org/apache/aries/jmx/framework/wiring/BundleWiringStateMBeanTest.java?rev=1210960&r1=1210959&r2=1210960&view=diff
==============================================================================
--- aries/trunk/sandbox/jmx-next/jmx-itests/src/test/java/org/apache/aries/jmx/framework/wiring/BundleWiringStateMBeanTest.java
(original)
+++ aries/trunk/sandbox/jmx-next/jmx-itests/src/test/java/org/apache/aries/jmx/framework/wiring/BundleWiringStateMBeanTest.java
Tue Dec  6 15:04:49 2011
@@ -49,6 +49,7 @@ import org.osgi.framework.Constants;
 import org.osgi.framework.wiring.BundleCapability;
 import org.osgi.framework.wiring.BundleRequirement;
 import org.osgi.framework.wiring.BundleRevision;
+import org.osgi.framework.wiring.BundleRevisions;
 import org.osgi.framework.wiring.BundleWire;
 import org.osgi.framework.wiring.BundleWiring;
 import org.osgi.jmx.framework.PackageStateMBean;
@@ -58,8 +59,8 @@ public class BundleWiringStateMBeanTest 
     @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"),
@@ -150,6 +151,48 @@ public class BundleWiringStateMBeanTest 
     }
 
     @Test
+    public void testGetRevisionsDeclaredRequirements() throws IOException {
+        BundleWiringStateMBean brsMBean = getMBean(BundleWiringStateMBean.OBJECTNAME, BundleWiringStateMBean.class);
+
+        Bundle a = context().getBundleByName("org.apache.aries.jmx.test.bundlea");
+        BundleRevisions revisions = a.adapt(BundleRevisions.class);
+
+        Assert.assertEquals("Precondition", 1, revisions.getRevisions().size());
+
+        TabularData jmxRequirementsTable = brsMBean.getRevisionsDeclaredRequirements(a.getBundleId(),
BundleWiringStateMBean.PACKAGE_NAMESPACE);
+        Assert.assertEquals(1, jmxRequirementsTable.size());
+
+        List<BundleRequirement> requirements = revisions.getRevisions().iterator().next().getDeclaredRequirements(BundleRevision.PACKAGE_NAMESPACE);
+        CompositeData jmxRevRequirements = (CompositeData) jmxRequirementsTable.values().iterator().next();
+        CompositeData[] jmxRequirements = (CompositeData[]) jmxRevRequirements.get(BundleWiringStateMBean.REQUIREMENTS);
+
+        Map<Map<String, Object>, Map<String, String>> expectedRequirements
= requirementsToMap(requirements);
+        Map<Map<String, Object>, Map<String, String>> actualRequirements
= jmxCapReqToMap(jmxRequirements);
+        Assert.assertEquals(expectedRequirements, actualRequirements);
+    }
+
+    @Test
+    public void testGetRevisionsDeclaredCapabilities() throws IOException {
+        BundleWiringStateMBean brsMBean = getMBean(BundleWiringStateMBean.OBJECTNAME, BundleWiringStateMBean.class);
+
+        Bundle a = context().getBundleByName("org.apache.aries.jmx.test.bundlea");
+        BundleRevisions revisions = a.adapt(BundleRevisions.class);
+
+        Assert.assertEquals("Precondition", 1, revisions.getRevisions().size());
+
+        TabularData jmxCapabilitiesTable = brsMBean.getRevisionsDeclaredCapabilities(a.getBundleId(),
BundleWiringStateMBean.PACKAGE_NAMESPACE);
+        Assert.assertEquals(1, jmxCapabilitiesTable.size());
+
+        List<BundleCapability> capabilities = revisions.getRevisions().iterator().next().getDeclaredCapabilities(BundleRevision.PACKAGE_NAMESPACE);
+        CompositeData jmxRevCapabilities = (CompositeData) jmxCapabilitiesTable.values().iterator().next();
+        CompositeData[] jmxCapabilities = (CompositeData[]) jmxRevCapabilities.get(BundleWiringStateMBean.CAPABILITIES);
+
+        Map<Map<String, Object>, Map<String, String>> expectedCapabilities
= capabilitiesToMap(capabilities);
+        Map<Map<String, Object>, Map<String, String>> actualCapabilities
= jmxCapReqToMap(jmxCapabilities);
+        Assert.assertEquals(expectedCapabilities, actualCapabilities);
+    }
+
+    @Test
     public void testGetCurrentWiring() throws IOException {
         BundleWiringStateMBean brsMBean = getMBean(BundleWiringStateMBean.OBJECTNAME, BundleWiringStateMBean.class);
 



Mime
View raw message