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