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);
}
}
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);
}
}
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;
}
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;
}
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);
}
}
Aggregations