Search in sources :

Example 61 with TabularData

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

the class BundleState method listBundles.

private TabularData listBundles(Collection<String> items) throws IOException {
    Bundle[] containerBundles = bundleContext.getBundles();
    List<BundleData> bundleDatas = new ArrayList<BundleData>();
    if (containerBundles != null) {
        for (Bundle containerBundle : containerBundles) {
            bundleDatas.add(new BundleData(bundleContext, containerBundle, packageAdmin, startLevel));
        }
    }
    TabularData bundleTable = new TabularDataSupport(BUNDLES_TYPE);
    for (BundleData bundleData : bundleDatas) {
        bundleTable.put(bundleData.toCompositeData(items));
    }
    return bundleTable;
}
Also used : Bundle(org.osgi.framework.Bundle) FrameworkUtils.resolveBundle(org.apache.aries.jmx.util.FrameworkUtils.resolveBundle) FrameworkUtils.getServicesInUseByBundle(org.apache.aries.jmx.util.FrameworkUtils.getServicesInUseByBundle) TabularDataSupport(javax.management.openmbean.TabularDataSupport) ArrayList(java.util.ArrayList) BundleData(org.apache.aries.jmx.codec.BundleData) TabularData(javax.management.openmbean.TabularData)

Example 62 with TabularData

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

the class BundleState method getHeaders.

private TabularData getHeaders(Dictionary<String, String> bundleHeaders) {
    List<Header> headers = new ArrayList<Header>();
    Enumeration<String> keys = bundleHeaders.keys();
    while (keys.hasMoreElements()) {
        String key = keys.nextElement();
        headers.add(new Header(key, bundleHeaders.get(key)));
    }
    TabularData headerTable = new TabularDataSupport(HEADERS_TYPE);
    for (Header header : headers) {
        headerTable.put(header.toCompositeData());
    }
    return headerTable;
}
Also used : Header(org.apache.aries.jmx.codec.BundleData.Header) TabularDataSupport(javax.management.openmbean.TabularDataSupport) ArrayList(java.util.ArrayList) TabularData(javax.management.openmbean.TabularData)

Example 63 with TabularData

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

the class BundleData method from.

/**
     * Constructs a <code>BundleData</code> object from the given <code>CompositeData</code>
     *
     * @param compositeData
     * @return
     * @throws IlleglArgumentException
     *             if compositeData is null or not of type {@link BundleStateMBean#BUNDLE_TYPE}
     */
@SuppressWarnings("unchecked")
public static BundleData from(CompositeData compositeData) throws IllegalArgumentException {
    if (compositeData == null) {
        throw new IllegalArgumentException("Argument compositeData cannot be null");
    }
    if (!compositeData.getCompositeType().equals(BUNDLE_TYPE)) {
        throw new IllegalArgumentException("Invalid CompositeType [" + compositeData.getCompositeType() + "]");
    }
    BundleData bundleData = new BundleData();
    bundleData.exportedPackages = (String[]) compositeData.get(EXPORTED_PACKAGES);
    bundleData.fragment = (Boolean) compositeData.get(FRAGMENT);
    bundleData.fragments = toPrimitive((Long[]) compositeData.get(FRAGMENTS));
    bundleData.hosts = toPrimitive((Long[]) compositeData.get(HOSTS));
    bundleData.identifier = (Long) compositeData.get(IDENTIFIER);
    bundleData.importedPackages = (String[]) compositeData.get(IMPORTED_PACKAGES);
    bundleData.lastModified = (Long) compositeData.get(LAST_MODIFIED);
    bundleData.location = (String) compositeData.get(LOCATION);
    bundleData.persistentlyStarted = (Boolean) compositeData.get(PERSISTENTLY_STARTED);
    bundleData.registeredServices = toPrimitive((Long[]) compositeData.get(REGISTERED_SERVICES));
    bundleData.removalPending = (Boolean) compositeData.get(REMOVAL_PENDING);
    bundleData.required = (Boolean) compositeData.get(REQUIRED);
    bundleData.requiredBundles = toPrimitive((Long[]) compositeData.get(REQUIRED_BUNDLES));
    bundleData.requiringBundles = toPrimitive((Long[]) compositeData.get(REQUIRING_BUNDLES));
    bundleData.servicesInUse = toPrimitive((Long[]) compositeData.get(SERVICES_IN_USE));
    bundleData.bundleStartLevel = (Integer) compositeData.get(START_LEVEL);
    bundleData.state = (String) compositeData.get(STATE);
    bundleData.symbolicName = (String) compositeData.get(SYMBOLIC_NAME);
    bundleData.version = (String) compositeData.get(VERSION);
    TabularData headerTable = (TabularData) compositeData.get(HEADERS);
    Collection<CompositeData> headerData = (Collection<CompositeData>) headerTable.values();
    for (CompositeData headerRow : headerData) {
        bundleData.headers.add(Header.from(headerRow));
    }
    return bundleData;
}
Also used : CompositeData(javax.management.openmbean.CompositeData) Collection(java.util.Collection) TabularData(javax.management.openmbean.TabularData)

Example 64 with TabularData

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

the class RoleData method toTabularData.

/**
     * Creates TabularData from Dictionary.
     *
     * @param props Dictionary instance.
     * @return TabularData instance.
     */
protected static TabularData toTabularData(Dictionary<String, Object> props) {
    if (props == null) {
        return null;
    }
    TabularData data = new TabularDataSupport(JmxConstants.PROPERTIES_TYPE);
    for (Enumeration<String> keys = props.keys(); keys.hasMoreElements(); ) {
        String key = keys.nextElement();
        data.put(PropertyData.newInstance(key, props.get(key)).toCompositeData());
    }
    return data;
}
Also used : TabularDataSupport(javax.management.openmbean.TabularDataSupport) TabularData(javax.management.openmbean.TabularData)

Example 65 with TabularData

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

the class ServiceDataTest method testToCompositeData.

@Test
public void testToCompositeData() throws Exception {
    ServiceReference<?> reference = mock(ServiceReference.class);
    Bundle bundle = mock(Bundle.class);
    String[] interfaces = new String[] { "org.apache.aries.jmx.Test", "org.apache.aries.jmx.Mock" };
    Bundle b1 = mock(Bundle.class);
    when(b1.getBundleId()).thenReturn(new Long(6));
    Bundle b2 = mock(Bundle.class);
    when(b2.getBundleId()).thenReturn(new Long(9));
    when(reference.getProperty(Constants.SERVICE_ID)).thenReturn(new Long(98));
    when(reference.getBundle()).thenReturn(bundle);
    when(bundle.getBundleId()).thenReturn(new Long(34));
    when(reference.getProperty(Constants.OBJECTCLASS)).thenReturn(interfaces);
    when(reference.getUsingBundles()).thenReturn(new Bundle[] { b1, b2 });
    when(reference.getPropertyKeys()).thenReturn(new String[] { "x.vendor", "x.domain", "x.index", "x.optimized" });
    when(reference.getProperty("x.vendor")).thenReturn("aries");
    when(reference.getProperty("x.domain")).thenReturn("test");
    when(reference.getProperty("x.index")).thenReturn(new Long(67));
    when(reference.getProperty("x.optimized")).thenReturn(true);
    ServiceData serviceData = new ServiceData(reference);
    CompositeData compositeData = serviceData.toCompositeData();
    assertEquals(new Long(98), compositeData.get(IDENTIFIER));
    assertEquals(new Long(34), compositeData.get(BUNDLE_IDENTIFIER));
    assertArrayEquals(new Long[] { new Long(6), new Long(9) }, (Long[]) compositeData.get(USING_BUNDLES));
    assertArrayEquals(interfaces, (String[]) compositeData.get(OBJECT_CLASS));
    TabularData propertiesTable = (TabularData) compositeData.get(PROPERTIES);
    @SuppressWarnings("unchecked") Collection<CompositeData> propertyData = (Collection<CompositeData>) propertiesTable.values();
    assertEquals(4, propertyData.size());
    for (CompositeData propertyRow : propertyData) {
        String key = (String) propertyRow.get(KEY);
        if (key.equals("x.vendor")) {
            assertEquals("aries", propertyRow.get(VALUE));
            assertEquals(STRING, propertyRow.get(TYPE));
        } else if (key.equals("x.domain")) {
            assertEquals("test", propertyRow.get(VALUE));
            assertEquals(STRING, propertyRow.get(TYPE));
        } else if (key.equals("x.index")) {
            assertEquals("67", propertyRow.get(VALUE));
            assertEquals(LONG, propertyRow.get(TYPE));
        } else if (key.equals("x.optimized")) {
            assertEquals("true", propertyRow.get(VALUE));
            assertEquals(BOOLEAN, propertyRow.get(TYPE));
        } else {
            fail("unknown key parsed from properties");
        }
    }
}
Also used : Bundle(org.osgi.framework.Bundle) CompositeData(javax.management.openmbean.CompositeData) Collection(java.util.Collection) TabularData(javax.management.openmbean.TabularData) Test(org.junit.Test)

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