Search in sources :

Example 36 with CompositeDataSupport

use of javax.management.openmbean.CompositeDataSupport in project karaf by apache.

the class ServicesMBeanImpl method getServices.

public TabularData getServices(long bundleId, boolean inUse) throws MBeanException {
    try {
        CompositeType serviceType = new CompositeType("Service", "OSGi Service", new String[] { "Interfaces", "Properties" }, new String[] { "Interfaces class name of the service", "Properties of the service" }, new OpenType[] { new ArrayType(1, SimpleType.STRING), new ArrayType(1, SimpleType.STRING) });
        TabularType tableType = new TabularType("Services", "Table of OSGi Services", serviceType, new String[] { "Interfaces", "Properties" });
        TabularData table = new TabularDataSupport(tableType);
        Bundle[] bundles;
        if (bundleId >= 0) {
            bundles = new Bundle[] { bundleContext.getBundle(bundleId) };
        } else {
            bundles = bundleContext.getBundles();
        }
        for (Bundle bundle : bundles) {
            try {
                ServiceReference[] serviceReferences;
                if (inUse) {
                    serviceReferences = bundle.getServicesInUse();
                } else {
                    serviceReferences = bundle.getRegisteredServices();
                }
                if (serviceReferences != null) {
                    for (ServiceReference reference : serviceReferences) {
                        String[] interfaces = (String[]) reference.getProperty("objectClass");
                        List<String> properties = new ArrayList<>();
                        for (String key : reference.getPropertyKeys()) {
                            properties.add(key + " = " + reference.getProperty(key));
                        }
                        CompositeData data = new CompositeDataSupport(serviceType, new String[] { "Interfaces", "Properties" }, new Object[] { interfaces, properties.toArray(new String[0]) });
                        table.put(data);
                    }
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
        return table;
    } catch (Exception e) {
        throw new MBeanException(null, e.toString());
    }
}
Also used : Bundle(org.osgi.framework.Bundle) TabularType(javax.management.openmbean.TabularType) CompositeData(javax.management.openmbean.CompositeData) CompositeDataSupport(javax.management.openmbean.CompositeDataSupport) ArrayList(java.util.ArrayList) NotCompliantMBeanException(javax.management.NotCompliantMBeanException) MBeanException(javax.management.MBeanException) TabularData(javax.management.openmbean.TabularData) ServiceReference(org.osgi.framework.ServiceReference) ArrayType(javax.management.openmbean.ArrayType) TabularDataSupport(javax.management.openmbean.TabularDataSupport) NotCompliantMBeanException(javax.management.NotCompliantMBeanException) MBeanException(javax.management.MBeanException) CompositeType(javax.management.openmbean.CompositeType)

Example 37 with CompositeDataSupport

use of javax.management.openmbean.CompositeDataSupport in project karaf by apache.

the class JmxFeature method getConfigElementTable.

static TabularData getConfigElementTable(Properties props) throws OpenDataException {
    TabularDataSupport table = new TabularDataSupport(FEATURE_CONFIG_ELEMENT_TABLE);
    for (Object key : props.keySet()) {
        String[] itemNames = FeaturesServiceMBean.FEATURE_CONFIG_ELEMENT;
        Object[] itemValues = { key, props.getProperty((String) key) };
        CompositeData element = new CompositeDataSupport(FEATURE_CONFIG_ELEMENT, itemNames, itemValues);
        table.put(element);
    }
    return table;
}
Also used : TabularDataSupport(javax.management.openmbean.TabularDataSupport) CompositeData(javax.management.openmbean.CompositeData) CompositeDataSupport(javax.management.openmbean.CompositeDataSupport)

Example 38 with CompositeDataSupport

use of javax.management.openmbean.CompositeDataSupport in project karaf by apache.

the class JmxRepository method getFeatureIdentifierTable.

static TabularData getFeatureIdentifierTable(List<Feature> features) throws OpenDataException {
    TabularDataSupport table = new TabularDataSupport(JmxFeature.FEATURE_IDENTIFIER_TABLE);
    for (Feature feature : features) {
        String[] itemNames = new String[] { FeaturesServiceMBean.FEATURE_NAME, FeaturesServiceMBean.FEATURE_VERSION };
        Object[] itemValues = new Object[] { feature.getName(), feature.getVersion() };
        CompositeData ident = new CompositeDataSupport(JmxFeature.FEATURE_IDENTIFIER, itemNames, itemValues);
        table.put(ident);
    }
    return table;
}
Also used : TabularDataSupport(javax.management.openmbean.TabularDataSupport) CompositeData(javax.management.openmbean.CompositeData) CompositeDataSupport(javax.management.openmbean.CompositeDataSupport) Feature(org.apache.karaf.features.Feature)

Example 39 with CompositeDataSupport

use of javax.management.openmbean.CompositeDataSupport in project sling by apache.

the class HealthCheckMBean method logData.

private TabularData logData(final Result er) throws OpenDataException {
    final TabularDataSupport result = new TabularDataSupport(LOG_TABLE_TYPE);
    int i = 1;
    for (final ResultLog.Entry e : er) {
        final Map<String, Object> data = new HashMap<String, Object>();
        data.put(INDEX_COLUMN, i++);
        data.put(LEVEL_COLUMN, e.getStatus().toString());
        data.put(MESSAGE_COLUMN, e.getMessage());
        result.put(new CompositeDataSupport(LOG_ROW_TYPE, data));
    }
    return result;
}
Also used : HashMap(java.util.HashMap) TabularDataSupport(javax.management.openmbean.TabularDataSupport) CompositeDataSupport(javax.management.openmbean.CompositeDataSupport) ResultLog(org.apache.sling.hc.api.ResultLog)

Example 40 with CompositeDataSupport

use of javax.management.openmbean.CompositeDataSupport in project jdk8u_jdk by JetBrains.

the class MonitorInfoCompositeData method getCompositeData.

protected CompositeData getCompositeData() {
    // CONTENTS OF THIS ARRAY MUST BE SYNCHRONIZED WITH
    // monitorInfoItemNames!
    int len = monitorInfoItemNames.length;
    Object[] values = new Object[len];
    CompositeData li = LockInfoCompositeData.toCompositeData(lock);
    for (int i = 0; i < len; i++) {
        String item = monitorInfoItemNames[i];
        if (item.equals(LOCKED_STACK_FRAME)) {
            StackTraceElement ste = lock.getLockedStackFrame();
            values[i] = (ste != null ? StackTraceElementCompositeData.toCompositeData(ste) : null);
        } else if (item.equals(LOCKED_STACK_DEPTH)) {
            values[i] = new Integer(lock.getLockedStackDepth());
        } else {
            values[i] = li.get(item);
        }
    }
    try {
        return new CompositeDataSupport(monitorInfoCompositeType, monitorInfoItemNames, values);
    } catch (OpenDataException e) {
        // Should never reach here
        throw new AssertionError(e);
    }
}
Also used : OpenDataException(javax.management.openmbean.OpenDataException) CompositeData(javax.management.openmbean.CompositeData) CompositeDataSupport(javax.management.openmbean.CompositeDataSupport)

Aggregations

CompositeDataSupport (javax.management.openmbean.CompositeDataSupport)92 CompositeData (javax.management.openmbean.CompositeData)68 TabularDataSupport (javax.management.openmbean.TabularDataSupport)60 CompositeType (javax.management.openmbean.CompositeType)55 TabularData (javax.management.openmbean.TabularData)43 OpenDataException (javax.management.openmbean.OpenDataException)25 HashMap (java.util.HashMap)21 Map (java.util.Map)19 TabularType (javax.management.openmbean.TabularType)19 OpenType (javax.management.openmbean.OpenType)10 Test (org.junit.Test)8 ObjectName (javax.management.ObjectName)7 EndpointUtilizationStatistics (org.apache.camel.spi.EndpointUtilizationStatistics)7 MBeanServer (javax.management.MBeanServer)6 IOException (java.io.IOException)5 MBeanException (javax.management.MBeanException)5 NotCompliantMBeanException (javax.management.NotCompliantMBeanException)5 ArrayList (java.util.ArrayList)3 MBeanInfo (javax.management.MBeanInfo)3 Bundle (org.osgi.framework.Bundle)3