Search in sources :

Example 16 with TabularType

use of javax.management.openmbean.TabularType in project deltaspike by apache.

the class DeltaSpikeConfigInfo method getConfigEntries.

@Override
public TabularData getConfigEntries() {
    ClassLoader originalCl = Thread.currentThread().getContextClassLoader();
    try {
        Thread.currentThread().setContextClassLoader(appConfigClassLoader);
        List<ConfigEntry> configEntries = calculateConfigEntries();
        String[] configArray = new String[configEntries.size()];
        for (int i = 0; i < configEntries.size(); i++) {
            ConfigEntry configEntry = configEntries.get(i);
            configArray[i] = configEntry.getKey() + " = " + configEntry.getValue() + " - picked up from: " + configEntry.getFromConfigSource();
        }
        String typeName = "ConfigEntries";
        OpenType<?>[] types = new OpenType<?>[] { SimpleType.STRING, SimpleType.STRING, SimpleType.STRING };
        String[] keys = new String[] { "Key", "Value", "fromConfigSource" };
        CompositeType ct = new CompositeType(typeName, typeName, keys, keys, types);
        TabularType type = new TabularType(typeName, typeName, ct, keys);
        TabularDataSupport configEntryInfo = new TabularDataSupport(type);
        ConfigSource[] configSources = ConfigResolver.getConfigSources();
        for (ConfigEntry configEntry : configEntries) {
            configEntryInfo.put(new CompositeDataSupport(ct, keys, new Object[] { configEntry.getKey(), configEntry.getValue(), configEntry.getFromConfigSource() }));
        }
        return configEntryInfo;
    } catch (OpenDataException e) {
        throw new RuntimeException(e);
    } finally {
        // set back the original TCCL
        Thread.currentThread().setContextClassLoader(originalCl);
    }
}
Also used : OpenType(javax.management.openmbean.OpenType) TabularType(javax.management.openmbean.TabularType) CompositeDataSupport(javax.management.openmbean.CompositeDataSupport) ConfigSource(org.apache.deltaspike.core.spi.config.ConfigSource) OpenDataException(javax.management.openmbean.OpenDataException) TabularDataSupport(javax.management.openmbean.TabularDataSupport) CompositeType(javax.management.openmbean.CompositeType)

Example 17 with TabularType

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

the class DefaultMXBeanMappingFactory method makeTabularMapping.

private MXBeanMapping makeTabularMapping(Type objType, boolean sortedMap, Type keyType, Type valueType, MXBeanMappingFactory factory) throws OpenDataException {
    final String objTypeName = typeName(objType);
    final MXBeanMapping keyMapping = factory.mappingForType(keyType, factory);
    final MXBeanMapping valueMapping = factory.mappingForType(valueType, factory);
    final OpenType<?> keyOpenType = keyMapping.getOpenType();
    final OpenType<?> valueOpenType = valueMapping.getOpenType();
    final CompositeType rowType = new CompositeType(objTypeName, objTypeName, keyValueArray, keyValueArray, new OpenType<?>[] { keyOpenType, valueOpenType });
    final TabularType tabularType = new TabularType(objTypeName, objTypeName, rowType, keyArray);
    return new TabularMapping(objType, sortedMap, tabularType, keyMapping, valueMapping);
}
Also used : TabularType(javax.management.openmbean.TabularType) CompositeType(javax.management.openmbean.CompositeType)

Example 18 with TabularType

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

the class AttributeResource method convertObject.

private Map<String, Object> convertObject(final TabularData td) {
    final TabularType type = td.getTabularType();
    final Map<String, Object> result = new HashMap<String, Object>();
    result.put(Constants.PROP_RESOURCE_SUPER_TYPE, Constants.TYPE_ATTRIBUTES);
    result.put(Constants.PROP_RESOURCE_TYPE, type.getTypeName());
    final Map<String, Map<String, Object>> rows = new LinkedHashMap<String, Map<String, Object>>();
    int rowIndex = 1;
    @SuppressWarnings("unchecked") final List<CompositeData> values = new ArrayList<CompositeData>((Collection<CompositeData>) td.values());
    Collections.sort(values, new Comparator<CompositeData>() {

        public int compare(final CompositeData o1, final CompositeData o2) {
            for (final String name : type.getIndexNames()) {
                final Object value1 = o1.get(name);
                final Object value2 = o2.get(name);
                final int result;
                if (value1 instanceof Comparable) {
                    result = ((Comparable) value1).compareTo(value2);
                } else {
                    result = value1.toString().compareTo(value2.toString());
                }
                if (result != 0) {
                    return result;
                }
            }
            return 0;
        }
    });
    for (final CompositeData data : values) {
        rows.put(String.valueOf(rowIndex), convertObject(data));
        rowIndex++;
    }
    result.put(Constants.RSRC_VALUE, rows);
    return result;
}
Also used : HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) TabularType(javax.management.openmbean.TabularType) CompositeData(javax.management.openmbean.CompositeData) ArrayList(java.util.ArrayList) LinkedHashMap(java.util.LinkedHashMap) ValueMap(org.apache.sling.api.resource.ValueMap) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) TreeMap(java.util.TreeMap)

Example 19 with TabularType

use of javax.management.openmbean.TabularType in project scylla-jmx by scylladb.

the class FailureDetector method getPhiValues.

@Override
public TabularData getPhiValues() throws OpenDataException {
    final CompositeType ct = new CompositeType("Node", "Node", new String[] { "Endpoint", "PHI" }, new String[] { "IP of the endpoint", "PHI value" }, new OpenType[] { SimpleType.STRING, SimpleType.DOUBLE });
    final TabularDataSupport results = new TabularDataSupport(new TabularType("PhiList", "PhiList", ct, new String[] { "Endpoint" }));
    final JsonArray arr = client.getJsonArray("/failure_detector/endpoint_phi_values");
    for (JsonValue v : arr) {
        JsonObject o = (JsonObject) v;
        String endpoint = o.getString("endpoint");
        double phi = Double.parseDouble(o.getString("phi"));
        if (phi != Double.MIN_VALUE) {
            // returned values are scaled by PHI_FACTOR so that the are on
            // the same scale as PhiConvictThreshold
            final CompositeData data = new CompositeDataSupport(ct, new String[] { "Endpoint", "PHI" }, new Object[] { endpoint, phi * PHI_FACTOR });
            results.put(data);
        }
    }
    return results;
}
Also used : JsonArray(javax.json.JsonArray) TabularDataSupport(javax.management.openmbean.TabularDataSupport) TabularType(javax.management.openmbean.TabularType) CompositeData(javax.management.openmbean.CompositeData) CompositeDataSupport(javax.management.openmbean.CompositeDataSupport) JsonValue(javax.json.JsonValue) JsonObject(javax.json.JsonObject) CompositeType(javax.management.openmbean.CompositeType)

Example 20 with TabularType

use of javax.management.openmbean.TabularType in project tomee by apache.

the class LocalMBeanServer method tabularData.

public static TabularData tabularData(final String typeName, final String typeDescription, final String[] names, final Object[] values) {
    if (names.length == 0) {
        return null;
    }
    final OpenType<?>[] types = new OpenType<?>[names.length];
    for (int i = 0; i < types.length; i++) {
        types[i] = SimpleType.STRING;
    }
    try {
        final CompositeType ct = new CompositeType(typeName, typeDescription, names, names, types);
        final TabularType type = new TabularType(typeName, typeDescription, ct, names);
        final TabularDataSupport data = new TabularDataSupport(type);
        final CompositeData line = new CompositeDataSupport(ct, names, values);
        data.put(line);
        return data;
    } catch (final OpenDataException e) {
        return null;
    }
}
Also used : OpenType(javax.management.openmbean.OpenType) OpenDataException(javax.management.openmbean.OpenDataException) TabularDataSupport(javax.management.openmbean.TabularDataSupport) TabularType(javax.management.openmbean.TabularType) CompositeData(javax.management.openmbean.CompositeData) CompositeDataSupport(javax.management.openmbean.CompositeDataSupport) CompositeType(javax.management.openmbean.CompositeType)

Aggregations

TabularType (javax.management.openmbean.TabularType)42 TabularDataSupport (javax.management.openmbean.TabularDataSupport)37 CompositeType (javax.management.openmbean.CompositeType)26 OpenDataException (javax.management.openmbean.OpenDataException)22 CompositeDataSupport (javax.management.openmbean.CompositeDataSupport)20 TabularData (javax.management.openmbean.TabularData)18 CompositeData (javax.management.openmbean.CompositeData)14 Map (java.util.Map)8 OpenType (javax.management.openmbean.OpenType)8 NotCompliantMBeanException (javax.management.NotCompliantMBeanException)6 ConcurrentMap (java.util.concurrent.ConcurrentMap)5 MBeanException (javax.management.MBeanException)5 ObjectName (javax.management.ObjectName)4 Bundle (org.osgi.framework.Bundle)4 DruidDataSource (com.alibaba.druid.pool.DruidDataSource)3 DataSourceProxyImpl (com.alibaba.druid.proxy.jdbc.DataSourceProxyImpl)3 HashMap (java.util.HashMap)3 LinkedHashMap (java.util.LinkedHashMap)3 MBeanInfo (javax.management.MBeanInfo)3 Field (java.lang.reflect.Field)2