Search in sources :

Example 66 with CompositeDataSupport

use of javax.management.openmbean.CompositeDataSupport 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 67 with CompositeDataSupport

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

the class JMXAccessorTask method createProperty.

/**
 * create result as property with name from property prefix When result is
 * an array and isSeparateArrayResults is true, resultproperty used as
 * prefix (<code>resultproperty.0-array.length</code> and store the
 * result array length at <code>resultproperty.length</code>. Other
 * option is that you delimit your result with a delimiter
 * (java.util.StringTokenizer is used).
 *
 * @param propertyPrefix Prefix for the property
 * @param result The result
 */
protected void createProperty(String propertyPrefix, Object result) {
    if (propertyPrefix == null) {
        propertyPrefix = "";
    }
    if (result instanceof CompositeDataSupport) {
        CompositeDataSupport data = (CompositeDataSupport) result;
        CompositeType compositeType = data.getCompositeType();
        Set<String> keys = compositeType.keySet();
        for (String key : keys) {
            Object value = data.get(key);
            OpenType<?> type = compositeType.getType(key);
            if (type instanceof SimpleType<?>) {
                setProperty(propertyPrefix + "." + key, value);
            } else {
                createProperty(propertyPrefix + "." + key, value);
            }
        }
    } else if (result instanceof TabularDataSupport) {
        TabularDataSupport data = (TabularDataSupport) result;
        for (Object key : data.keySet()) {
            for (Object key1 : ((List<?>) key)) {
                CompositeData valuedata = data.get(new Object[] { key1 });
                Object value = valuedata.get("value");
                OpenType<?> type = valuedata.getCompositeType().getType("value");
                if (type instanceof SimpleType<?>) {
                    setProperty(propertyPrefix + "." + key1, value);
                } else {
                    createProperty(propertyPrefix + "." + key1, value);
                }
            }
        }
    } else if (result.getClass().isArray()) {
        if (isSeparatearrayresults()) {
            int size = 0;
            for (int i = 0; i < Array.getLength(result); i++) {
                if (setProperty(propertyPrefix + "." + size, Array.get(result, i))) {
                    size++;
                }
            }
            if (size > 0) {
                setProperty(propertyPrefix + ".Length", Integer.toString(size));
            }
        }
    } else {
        String delim = getDelimiter();
        if (delim != null) {
            StringTokenizer tokenizer = new StringTokenizer(result.toString(), delim);
            int size = 0;
            for (; tokenizer.hasMoreTokens(); ) {
                String token = tokenizer.nextToken();
                if (setProperty(propertyPrefix + "." + size, token)) {
                    size++;
                }
            }
            if (size > 0) {
                setProperty(propertyPrefix + ".Length", Integer.toString(size));
            }
        } else {
            setProperty(propertyPrefix, result.toString());
        }
    }
}
Also used : OpenType(javax.management.openmbean.OpenType) CompositeDataSupport(javax.management.openmbean.CompositeDataSupport) CompositeData(javax.management.openmbean.CompositeData) SimpleType(javax.management.openmbean.SimpleType) StringTokenizer(java.util.StringTokenizer) TabularDataSupport(javax.management.openmbean.TabularDataSupport) List(java.util.List) CompositeType(javax.management.openmbean.CompositeType)

Example 68 with CompositeDataSupport

use of javax.management.openmbean.CompositeDataSupport in project druid by alibaba.

the class JdbcStatManager method getSqlList.

@Override
public TabularData getSqlList() throws JMException {
    CompositeType rowType = JdbcSqlStat.getCompositeType();
    String[] indexNames = rowType.keySet().toArray(new String[rowType.keySet().size()]);
    TabularType tabularType = new TabularType("SqlListStatistic", "SqlListStatistic", rowType, indexNames);
    TabularData data = new TabularDataSupport(tabularType);
    JdbcDataSourceStat globalStat = JdbcDataSourceStat.getGlobal();
    if (globalStat != null) {
        Map<String, JdbcSqlStat> statMap = globalStat.getSqlStatMap();
        for (Map.Entry<String, JdbcSqlStat> entry : statMap.entrySet()) {
            if (entry.getValue().getExecuteCount() == 0 && entry.getValue().getRunningCount() == 0) {
                continue;
            }
            Map<String, Object> map = entry.getValue().getData();
            map.put("URL", globalStat.getUrl());
            data.put(new CompositeDataSupport(JdbcSqlStat.getCompositeType(), map));
        }
    }
    for (DataSourceProxyImpl dataSource : DruidDriver.getProxyDataSources().values()) {
        JdbcDataSourceStat druidDataSourceStat = dataSource.getDataSourceStat();
        if (druidDataSourceStat == globalStat) {
            continue;
        }
        Map<String, JdbcSqlStat> statMap = druidDataSourceStat.getSqlStatMap();
        for (Map.Entry<String, JdbcSqlStat> entry : statMap.entrySet()) {
            if (entry.getValue().getExecuteCount() == 0 && entry.getValue().getRunningCount() == 0) {
                continue;
            }
            Map<String, Object> map = entry.getValue().getData();
            map.put("URL", dataSource.getUrl());
            data.put(new CompositeDataSupport(JdbcSqlStat.getCompositeType(), map));
        }
    }
    for (DruidDataSource dataSource : DruidDataSourceStatManager.getDruidDataSourceInstances()) {
        JdbcDataSourceStat druidDataSourceStat = dataSource.getDataSourceStat();
        if (druidDataSourceStat == globalStat) {
            continue;
        }
        Map<String, JdbcSqlStat> statMap = druidDataSourceStat.getSqlStatMap();
        for (Map.Entry<String, JdbcSqlStat> entry : statMap.entrySet()) {
            if (entry.getValue().getExecuteCount() == 0 && entry.getValue().getRunningCount() == 0) {
                continue;
            }
            Map<String, Object> map = entry.getValue().getData();
            map.put("URL", dataSource.getUrl());
            data.put(new CompositeDataSupport(JdbcSqlStat.getCompositeType(), map));
        }
    }
    return data;
}
Also used : DataSourceProxyImpl(com.alibaba.druid.proxy.jdbc.DataSourceProxyImpl) TabularType(javax.management.openmbean.TabularType) CompositeDataSupport(javax.management.openmbean.CompositeDataSupport) DruidDataSource(com.alibaba.druid.pool.DruidDataSource) TabularData(javax.management.openmbean.TabularData) TabularDataSupport(javax.management.openmbean.TabularDataSupport) ConcurrentMap(java.util.concurrent.ConcurrentMap) Map(java.util.Map) CompositeType(javax.management.openmbean.CompositeType)

Example 69 with CompositeDataSupport

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

the class BundleEventDataTest method testFrom.

@Test
public void testFrom() throws Exception {
    Map<String, Object> items = new HashMap<String, Object>();
    items.put(IDENTIFIER, new Long(7));
    items.put(SYMBOLIC_NAME, "t");
    items.put(LOCATION, "l");
    items.put(EVENT, BundleEvent.RESOLVED);
    CompositeData compositeData = new CompositeDataSupport(BUNDLE_EVENT_TYPE, items);
    BundleEventData event = BundleEventData.from(compositeData);
    assertEquals(7, event.getBundleId());
    assertEquals("t", event.getBundleSymbolicName());
    assertEquals("l", event.getLocation());
    assertEquals(BundleEvent.RESOLVED, event.getEventType());
}
Also used : HashMap(java.util.HashMap) CompositeData(javax.management.openmbean.CompositeData) CompositeDataSupport(javax.management.openmbean.CompositeDataSupport) Test(org.junit.Test)

Example 70 with CompositeDataSupport

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

the class ServiceEventDataTest method testFrom.

@Test
public void testFrom() throws Exception {
    Map<String, Object> items = new HashMap<String, Object>();
    items.put(IDENTIFIER, new Long(7));
    items.put(BUNDLE_IDENTIFIER, new Long(67));
    items.put(BUNDLE_LOCATION, "string");
    items.put(BUNDLE_SYMBOLIC_NAME, "test");
    items.put(OBJECT_CLASS, new String[] { "org.apache.aries.jmx.Mock" });
    items.put(EVENT, ServiceEvent.MODIFIED);
    CompositeData compositeData = new CompositeDataSupport(SERVICE_EVENT_TYPE, items);
    ServiceEventData event = ServiceEventData.from(compositeData);
    assertEquals(7, event.getServiceId());
    assertEquals(67, event.getBundleId());
    assertArrayEquals(new String[] { "org.apache.aries.jmx.Mock" }, event.getServiceInterfaces());
    assertEquals("test", event.getBundleSymbolicName());
    assertEquals("string", event.getBundleLocation());
    assertEquals(ServiceEvent.MODIFIED, event.getEventType());
}
Also used : HashMap(java.util.HashMap) CompositeData(javax.management.openmbean.CompositeData) CompositeDataSupport(javax.management.openmbean.CompositeDataSupport) Test(org.junit.Test)

Aggregations

CompositeDataSupport (javax.management.openmbean.CompositeDataSupport)166 CompositeData (javax.management.openmbean.CompositeData)107 CompositeType (javax.management.openmbean.CompositeType)105 TabularDataSupport (javax.management.openmbean.TabularDataSupport)78 OpenDataException (javax.management.openmbean.OpenDataException)66 TabularData (javax.management.openmbean.TabularData)46 HashMap (java.util.HashMap)36 TabularType (javax.management.openmbean.TabularType)30 Map (java.util.Map)26 OpenType (javax.management.openmbean.OpenType)15 ObjectName (javax.management.ObjectName)12 MBeanServer (javax.management.MBeanServer)8 Test (org.junit.Test)8 IOException (java.io.IOException)7 EndpointUtilizationStatistics (org.apache.camel.spi.EndpointUtilizationStatistics)7 MBeanException (javax.management.MBeanException)6 JsonArray (javax.json.JsonArray)5 JsonObject (javax.json.JsonObject)5 NotCompliantMBeanException (javax.management.NotCompliantMBeanException)5 ArrayList (java.util.ArrayList)4