Search in sources :

Example 91 with TabularData

use of javax.management.openmbean.TabularData in project jvm-tools by aragozin.

the class MBeanHelper method format.

private String format(Object v, String type) {
    if (type.equals("void")) {
        return null;
    } else if (v instanceof CompositeData[]) {
        CompositeData[] td = (CompositeData[]) v;
        if (td.length == 0) {
            return "";
        }
        List<String> header = new ArrayList<String>();
        for (String f : td[0].getCompositeType().keySet()) {
            if (!header.contains(f)) {
                header.add(f);
            }
        }
        List<String[]> content = new ArrayList<String[]>();
        content.add(header.toArray(new String[0]));
        for (Object row : td) {
            content.add(formatRow((CompositeData) row, header));
        }
        return formatTable(content, widthThresholdTable, true);
    } else if (v instanceof TabularData) {
        TabularData td = (TabularData) v;
        td.getTabularType().getIndexNames();
        List<String> header = new ArrayList<String>(td.getTabularType().getIndexNames());
        for (String f : td.getTabularType().getRowType().keySet()) {
            if (!header.contains(f)) {
                header.add(f);
            }
        }
        List<String[]> content = new ArrayList<String[]>();
        content.add(header.toArray(new String[0]));
        for (Object row : td.values()) {
            content.add(formatRow((CompositeData) row, header));
        }
        return formatTable(content, widthThresholdTable, true);
    } else if (v instanceof CompositeData) {
        CompositeData cd = (CompositeData) v;
        List<String[]> content = new ArrayList<String[]>();
        for (String field : cd.getCompositeType().keySet()) {
            String val = formatLine(cd.get(field), cd.getCompositeType().getType(field).getClassName());
            content.add(new String[] { field + ": ", val });
        }
        return formatTable(content, widthThresholdComposite, false);
    } else {
        return formatLine(v, type);
    }
}
Also used : CompositeData(javax.management.openmbean.CompositeData) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) TabularData(javax.management.openmbean.TabularData)

Example 92 with TabularData

use of javax.management.openmbean.TabularData in project jvm-tools by aragozin.

the class MBeanHelper method formatLine.

private String formatLine(Object v, String type) {
    if (v instanceof TabularData) {
        TabularData td = (TabularData) v;
        StringBuilder sb = new StringBuilder();
        for (Object c : td.values()) {
            sb.append(formatLine(c, td.getTabularType().getRowType().getClassName()));
            sb.append(",");
        }
        if (sb.length() > 0) {
            sb.setLength(sb.length() - 1);
        }
        return sb.toString();
    }
    if (v instanceof CompositeData[]) {
        CompositeData[] td = (CompositeData[]) v;
        StringBuilder sb = new StringBuilder();
        for (Object c : td) {
            sb.append(formatLine(c, ((CompositeData) c).getCompositeType().getClassName()));
            sb.append(",");
        }
        if (sb.length() > 0) {
            sb.setLength(sb.length() - 1);
        }
        return sb.toString();
    } else if (v instanceof CompositeData) {
        CompositeData cdata = (CompositeData) v;
        StringBuilder sb = new StringBuilder();
        sb.append("{");
        for (String attr : cdata.getCompositeType().keySet()) {
            sb.append(attr).append("=");
            sb.append(formatLine(cdata.get(attr), cdata.getCompositeType().getType(attr).getClassName()));
            sb.append(',');
        }
        if (sb.length() > 1) {
            sb.setLength(sb.length() - 1);
        }
        sb.append("}");
        return sb.toString();
    } else if (v instanceof Object[]) {
        return Arrays.toString((Object[]) v);
    } else if (v instanceof boolean[]) {
        return Arrays.toString((boolean[]) v);
    } else if (v instanceof byte[]) {
        return Arrays.toString((byte[]) v);
    } else if (v instanceof char[]) {
        return Arrays.toString((char[]) v);
    } else if (v instanceof short[]) {
        return Arrays.toString((short[]) v);
    } else if (v instanceof int[]) {
        return Arrays.toString((int[]) v);
    } else if (v instanceof long[]) {
        return Arrays.toString((long[]) v);
    } else if (v instanceof float[]) {
        return Arrays.toString((float[]) v);
    } else if (v instanceof double[]) {
        return Arrays.toString((double[]) v);
    } else {
        return String.valueOf(v);
    }
}
Also used : CompositeData(javax.management.openmbean.CompositeData) TabularData(javax.management.openmbean.TabularData)

Example 93 with TabularData

use of javax.management.openmbean.TabularData in project hibernate-orm by hibernate.

the class HibernateStatsImpl method getEntityStats.

@Override
public TabularData getEntityStats() {
    final List<CompositeData> result = new ArrayList<CompositeData>();
    final Statistics statistics = getStatistics();
    for (String entity : statistics.getEntityNames()) {
        final EntityStats entityStats = new EntityStats(entity, statistics.getEntityStatistics(entity));
        result.add(entityStats.toCompositeData());
    }
    final TabularData td = EntityStats.newTabularDataInstance();
    td.putAll(result.toArray(new CompositeData[result.size()]));
    return td;
}
Also used : CompositeData(javax.management.openmbean.CompositeData) ArrayList(java.util.ArrayList) Statistics(org.hibernate.stat.Statistics) TabularData(javax.management.openmbean.TabularData)

Example 94 with TabularData

use of javax.management.openmbean.TabularData in project hibernate-orm by hibernate.

the class HibernateStatsImpl method getCollectionStats.

@Override
public TabularData getCollectionStats() {
    final List<CompositeData> result = new ArrayList<CompositeData>();
    final Statistics statistics = getStatistics();
    for (String roleName : statistics.getCollectionRoleNames()) {
        final CollectionStats collectionStats = new CollectionStats(roleName, statistics.getCollectionStatistics(roleName));
        result.add(collectionStats.toCompositeData());
    }
    final TabularData td = CollectionStats.newTabularDataInstance();
    td.putAll(result.toArray(new CompositeData[result.size()]));
    return td;
}
Also used : CompositeData(javax.management.openmbean.CompositeData) ArrayList(java.util.ArrayList) Statistics(org.hibernate.stat.Statistics) TabularData(javax.management.openmbean.TabularData)

Example 95 with TabularData

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

the class ManagedAsyncProcessorAwaitManager method browse.

@Override
public TabularData browse() {
    try {
        TabularData answer = new TabularDataSupport(CamelOpenMBeanTypes.listAwaitThreadsTabularType());
        Collection<AsyncProcessorAwaitManager.AwaitThread> threads = manager.browse();
        for (AsyncProcessorAwaitManager.AwaitThread entry : threads) {
            CompositeType ct = CamelOpenMBeanTypes.listAwaitThreadsCompositeType();
            String id = "" + entry.getBlockedThread().getId();
            String name = entry.getBlockedThread().getName();
            String exchangeId = entry.getExchange().getExchangeId();
            String routeId = entry.getRouteId();
            String nodeId = entry.getNodeId();
            String duration = "" + entry.getWaitDuration();
            CompositeData data = new CompositeDataSupport(ct, new String[] { "id", "name", "exchangeId", "routeId", "nodeId", "duration" }, new Object[] { id, name, exchangeId, routeId, nodeId, duration });
            answer.put(data);
        }
        return answer;
    } catch (Exception e) {
        throw ObjectHelper.wrapRuntimeCamelException(e);
    }
}
Also used : TabularDataSupport(javax.management.openmbean.TabularDataSupport) CompositeData(javax.management.openmbean.CompositeData) CompositeDataSupport(javax.management.openmbean.CompositeDataSupport) AsyncProcessorAwaitManager(org.apache.camel.spi.AsyncProcessorAwaitManager) TabularData(javax.management.openmbean.TabularData) CompositeType(javax.management.openmbean.CompositeType)

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