Search in sources :

Example 56 with TabularData

use of javax.management.openmbean.TabularData in project aries by apache.

the class BundleWiringStateMBeanTest method getJmxAttributes.

@SuppressWarnings("unchecked")
private Map<String, Object> getJmxAttributes(CompositeData jmxCapReq) {
    TabularData jmxAttributes = (TabularData) jmxCapReq.get(BundleWiringStateMBean.ATTRIBUTES);
    Map<String, Object> aMap = new HashMap<String, Object>();
    for (CompositeData jmxAttr : (Collection<CompositeData>) jmxAttributes.values()) {
        PropertyData<Object> pd = PropertyData.from(jmxAttr);
        Object val = pd.getValue();
        if (val instanceof Object[]) {
            val = Arrays.asList((Object[]) val);
        }
        aMap.put(pd.getKey(), val);
    }
    return aMap;
}
Also used : HashMap(java.util.HashMap) CompositeData(javax.management.openmbean.CompositeData) Collection(java.util.Collection) TabularData(javax.management.openmbean.TabularData)

Example 57 with TabularData

use of javax.management.openmbean.TabularData in project aries by apache.

the class BundleWiringStateMBeanTest method getJmxDirectives.

@SuppressWarnings("unchecked")
private Map<String, String> getJmxDirectives(CompositeData jmxCapReq) {
    TabularData jmxDirectives = (TabularData) jmxCapReq.get(BundleWiringStateMBean.DIRECTIVES);
    Map<String, String> dMap = new HashMap<String, String>();
    for (CompositeData jmxDir : (Collection<CompositeData>) jmxDirectives.values()) {
        dMap.put((String) jmxDir.get(BundleWiringStateMBean.KEY), (String) jmxDir.get(BundleWiringStateMBean.VALUE));
    }
    return dMap;
}
Also used : HashMap(java.util.HashMap) CompositeData(javax.management.openmbean.CompositeData) Collection(java.util.Collection) TabularData(javax.management.openmbean.TabularData)

Example 58 with TabularData

use of javax.management.openmbean.TabularData in project aries by apache.

the class BundleWiringStateMBeanTest method testRevisionsWiring.

@Test
public void testRevisionsWiring() throws Exception {
    TabularData jmxWiringTable = brsMBean.getRevisionsWiring(bundleA.getBundleId(), BundleRevision.PACKAGE_NAMESPACE);
    Assert.assertEquals(1, jmxWiringTable.size());
    CompositeData jmxWiring = (CompositeData) jmxWiringTable.values().iterator().next();
    Assert.assertEquals(BundleWiringStateMBean.BUNDLE_WIRING_TYPE, jmxWiring.getCompositeType());
    Assert.assertEquals(bundleA.getBundleId(), jmxWiring.get(BundleWiringStateMBean.BUNDLE_ID));
    BundleWiring bw = (BundleWiring) bundleA.adapt(BundleWiring.class);
    assertBundleWiring(bw, jmxWiring);
}
Also used : CompositeData(javax.management.openmbean.CompositeData) BundleWiring(org.osgi.framework.wiring.BundleWiring) TabularData(javax.management.openmbean.TabularData) Test(org.junit.Test) AbstractIntegrationTest(org.apache.aries.jmx.AbstractIntegrationTest)

Example 59 with TabularData

use of javax.management.openmbean.TabularData in project aries by apache.

the class BundleWiringStateMBeanTest method testRevisionsWiringClosure.

@Test
public void testRevisionsWiringClosure() throws Exception {
    TabularData jmxWiringClosure = brsMBean.getRevisionsWiringClosure(bundleA.getBundleId(), BundleRevision.PACKAGE_NAMESPACE);
    CompositeData jmxWiringA = jmxWiringClosure.get(new Object[] { bundleA.getBundleId(), 0 });
    assertBundleWiring((BundleWiring) bundleA.adapt(BundleWiring.class), jmxWiringA);
    Bundle b = context().getBundleByName("org.apache.aries.jmx.test.bundleb");
    int bRevID = findRevisionID(jmxWiringA, b);
    CompositeData jmxWiringB = jmxWiringClosure.get(new Object[] { b.getBundleId(), bRevID });
    assertBundleWiring((BundleWiring) b.adapt(BundleWiring.class), jmxWiringB);
    Bundle cm = context().getBundleByName("org.apache.felix.configadmin");
    int cmRevID = findRevisionID(jmxWiringA, cm);
    CompositeData jmxWiringCM = jmxWiringClosure.get(new Object[] { cm.getBundleId(), cmRevID });
    assertBundleWiring((BundleWiring) cm.adapt(BundleWiring.class), jmxWiringCM);
    Bundle sb = context().getBundle(0);
    int sbRevID = findRevisionID(jmxWiringA, sb);
    CompositeData jmxWiringSB = jmxWiringClosure.get(new Object[] { sb.getBundleId(), sbRevID });
    assertBundleWiring((BundleWiring) sb.adapt(BundleWiring.class), jmxWiringSB);
}
Also used : Bundle(org.osgi.framework.Bundle) CompositeData(javax.management.openmbean.CompositeData) TabularData(javax.management.openmbean.TabularData) Test(org.junit.Test) AbstractIntegrationTest(org.apache.aries.jmx.AbstractIntegrationTest)

Example 60 with TabularData

use of javax.management.openmbean.TabularData in project aries by apache.

the class ServiceData method toCompositeData.

public CompositeData toCompositeData(Collection<String> itemNames) {
    Map<String, Object> items = new HashMap<String, Object>();
    items.put(IDENTIFIER, this.serviceId);
    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(JmxConstants.PROPERTIES_TYPE);
    for (PropertyData<? extends Object> propertyData : this.properties) {
        propertiesTable.put(propertyData.toCompositeData());
    }
    items.put(PROPERTIES, propertiesTable);
    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 {
        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);
    }
}
Also used : HashMap(java.util.HashMap) CompositeDataSupport(javax.management.openmbean.CompositeDataSupport) TabularData(javax.management.openmbean.TabularData) OpenDataException(javax.management.openmbean.OpenDataException) TabularDataSupport(javax.management.openmbean.TabularDataSupport)

Aggregations

TabularData (javax.management.openmbean.TabularData)183 CompositeData (javax.management.openmbean.CompositeData)91 TabularDataSupport (javax.management.openmbean.TabularDataSupport)67 ObjectName (javax.management.ObjectName)54 MBeanServer (javax.management.MBeanServer)50 CompositeType (javax.management.openmbean.CompositeType)47 CompositeDataSupport (javax.management.openmbean.CompositeDataSupport)43 Test (org.junit.Test)38 Map (java.util.Map)28 ArrayList (java.util.ArrayList)23 MockEndpoint (org.apache.camel.component.mock.MockEndpoint)21 HashMap (java.util.HashMap)20 TabularType (javax.management.openmbean.TabularType)17 Bundle (org.osgi.framework.Bundle)17 AbstractIntegrationTest (org.apache.aries.jmx.AbstractIntegrationTest)15 Collection (java.util.Collection)13 IOException (java.io.IOException)11 DruidDataSource (com.alibaba.druid.pool.DruidDataSource)9 List (java.util.List)8 ServiceReference (org.osgi.framework.ServiceReference)8