Search in sources :

Example 31 with TabularData

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

the class JMXJsonServlet method writeObject.

private void writeObject(JsonGenerator jg, Object value) throws IOException {
    if (value == null) {
        jg.writeNull();
    } else {
        Class<?> c = value.getClass();
        if (c.isArray()) {
            jg.writeStartArray();
            int len = Array.getLength(value);
            for (int j = 0; j < len; j++) {
                Object item = Array.get(value, j);
                writeObject(jg, item);
            }
            jg.writeEndArray();
        } else if (value instanceof Number) {
            Number n = (Number) value;
            jg.writeNumber(n.toString());
        } else if (value instanceof Boolean) {
            Boolean b = (Boolean) value;
            jg.writeBoolean(b);
        } else if (value instanceof CompositeData) {
            CompositeData cds = (CompositeData) value;
            CompositeType comp = cds.getCompositeType();
            Set<String> keys = comp.keySet();
            jg.writeStartObject();
            for (String key : keys) {
                writeAttribute(jg, key, cds.get(key));
            }
            jg.writeEndObject();
        } else if (value instanceof TabularData) {
            TabularData tds = (TabularData) value;
            jg.writeStartArray();
            for (Object entry : tds.values()) {
                writeObject(jg, entry);
            }
            jg.writeEndArray();
        } else {
            jg.writeString(value.toString());
        }
    }
}
Also used : Set(java.util.Set) CompositeData(javax.management.openmbean.CompositeData) CompositeType(javax.management.openmbean.CompositeType) TabularData(javax.management.openmbean.TabularData)

Example 32 with TabularData

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

the class JdbcStatManager method getConnectionList.

public TabularData getConnectionList() throws JMException {
    CompositeType rowType = JdbcConnectionStat.Entry.getCompositeType();
    String[] indexNames = rowType.keySet().toArray(new String[rowType.keySet().size()]);
    TabularType tabularType = new TabularType("ConnectionList", "ConnectionList", rowType, indexNames);
    TabularData data = new TabularDataSupport(tabularType);
    final ConcurrentMap<String, DataSourceProxyImpl> dataSources = DruidDriver.getProxyDataSources();
    for (DataSourceProxyImpl dataSource : dataSources.values()) {
        JdbcDataSourceStat dataSourceStat = dataSource.getDataSourceStat();
        ConcurrentMap<Long, JdbcConnectionStat.Entry> connections = dataSourceStat.getConnections();
        for (Map.Entry<Long, JdbcConnectionStat.Entry> entry : connections.entrySet()) {
            data.put(entry.getValue().getCompositeData());
        }
    }
    for (DruidDataSource instance : DruidDataSourceStatManager.getDruidDataSourceInstances()) {
        JdbcDataSourceStat dataSourceStat = instance.getDataSourceStat();
        ConcurrentMap<Long, JdbcConnectionStat.Entry> connections = dataSourceStat.getConnections();
        for (Map.Entry<Long, JdbcConnectionStat.Entry> entry : connections.entrySet()) {
            data.put(entry.getValue().getCompositeData());
        }
    }
    return data;
}
Also used : DataSourceProxyImpl(com.alibaba.druid.proxy.jdbc.DataSourceProxyImpl) TabularType(javax.management.openmbean.TabularType) DruidDataSource(com.alibaba.druid.pool.DruidDataSource) TabularData(javax.management.openmbean.TabularData) TabularDataSupport(javax.management.openmbean.TabularDataSupport) AtomicLong(java.util.concurrent.atomic.AtomicLong) ConcurrentMap(java.util.concurrent.ConcurrentMap) Map(java.util.Map) CompositeType(javax.management.openmbean.CompositeType)

Example 33 with TabularData

use of javax.management.openmbean.TabularData 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 34 with TabularData

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

the class DruidDataSourceStatManager method getDataSourceList.

public TabularData getDataSourceList() throws JMException {
    CompositeType rowType = getDruidDataSourceCompositeType();
    String[] indexNames = rowType.keySet().toArray(new String[rowType.keySet().size()]);
    TabularType tabularType = new TabularType("DruidDataSourceStat", "DruidDataSourceStat", rowType, indexNames);
    TabularData data = new TabularDataSupport(tabularType);
    final Set<Object> dataSources = getInstances().keySet();
    for (Object dataSource : dataSources) {
        data.put(getCompositeData(dataSource));
    }
    return data;
}
Also used : TabularDataSupport(javax.management.openmbean.TabularDataSupport) TabularType(javax.management.openmbean.TabularType) CompositeType(javax.management.openmbean.CompositeType) TabularData(javax.management.openmbean.TabularData)

Example 35 with TabularData

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

the class TestIdle method setUp.

protected void setUp() throws Exception {
    TabularData dataSourceList = DruidDataSourceStatManager.getInstance().getDataSourceList();
    if (dataSourceList.size() > 0) {
        DruidDataSource first = DruidDataSourceStatManager.getInstance().getDruidDataSourceInstances().iterator().next();
        System.out.println(first.getInitStackTrace());
    }
    Assert.assertEquals(0, dataSourceList.size());
}
Also used : DruidDataSource(com.alibaba.druid.pool.DruidDataSource) TabularData(javax.management.openmbean.TabularData)

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