use of javax.management.openmbean.OpenType 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.OpenType in project geode by apache.
the class OpenTypeConverter method makeCompositeConverter.
/**
* @return the open type converrter for a given type
*/
private static OpenTypeConverter makeCompositeConverter(Class c) throws OpenDataException {
final List<Method> methods = Arrays.asList(c.getMethods());
final SortedMap<String, Method> getterMap = OpenTypeUtil.newSortedMap();
for (Method method : methods) {
final String propertyName = propertyName(method);
if (propertyName == null)
continue;
Method old = getterMap.put(OpenTypeUtil.decapitalize(propertyName), method);
if (old != null) {
final String msg = "Class " + c.getName() + " has method name clash: " + old.getName() + ", " + method.getName();
throw new OpenDataException(msg);
}
}
final int nitems = getterMap.size();
if (nitems == 0) {
throw new OpenDataException("Can't map " + c.getName() + " to an open data type");
}
final Method[] getters = new Method[nitems];
final String[] itemNames = new String[nitems];
final OpenType[] openTypes = new OpenType[nitems];
int i = 0;
for (Map.Entry<String, Method> entry : getterMap.entrySet()) {
itemNames[i] = entry.getKey();
final Method getter = entry.getValue();
getters[i] = getter;
final Type retType = getter.getGenericReturnType();
openTypes[i] = toConverter(retType).getOpenType();
i++;
}
CompositeType compositeType = new // field
CompositeType(// field
c.getName(), // field
c.getName(), // field
itemNames, // field descriptions
itemNames, openTypes);
return new CompositeConverter(c, compositeType, itemNames, getters);
}
use of javax.management.openmbean.OpenType in project geode by apache.
the class OpenTypeConverter method makeArrayOrCollectionConverter.
private static OpenTypeConverter makeArrayOrCollectionConverter(Type collectionType, Type elementType) throws OpenDataException {
final OpenTypeConverter elementConverter = toConverter(elementType);
final OpenType elementOpenType = elementConverter.getOpenType();
final ArrayType openType = new ArrayType(1, elementOpenType);
final Class elementOpenClass = elementConverter.getOpenClass();
final Class openArrayClass;
final String openArrayClassName;
if (elementOpenClass.isArray())
openArrayClassName = "[" + elementOpenClass.getName();
else
openArrayClassName = "[L" + elementOpenClass.getName() + ";";
try {
openArrayClass = Class.forName(openArrayClassName);
} catch (ClassNotFoundException e) {
throw openDataException("Cannot obtain array class", e);
}
if (collectionType instanceof ParameterizedType) {
return new CollectionConverter(collectionType, openType, openArrayClass, elementConverter);
} else {
if (elementConverter.isIdentity()) {
return new IdentityConverter(collectionType, openType, openArrayClass);
} else {
return new ArrayConverter(collectionType, openType, openArrayClass, elementConverter);
}
}
}
use of javax.management.openmbean.OpenType in project karaf by apache.
the class InstanceToTableMapper method createRowType.
private static CompositeType createRowType() throws OpenDataException {
String desc = "This type describes Karaf instance";
OpenType<?>[] itemTypes = new OpenType[] { SimpleType.INTEGER, SimpleType.STRING, SimpleType.BOOLEAN, SimpleType.INTEGER, SimpleType.STRING, SimpleType.INTEGER, SimpleType.STRING, SimpleType.INTEGER, SimpleType.STRING, SimpleType.STRING, SimpleType.STRING, SimpleType.STRING };
String[] descriptions = new String[] { "The Process ID of the instance or 0 if not running", "The name of the instance", "Whether the instance is root", "The SSH port that can be used to connect to the instance", "The host address where the SSH server is listening", "The RMI registry port that can be used to manage the instance", "The host address where the RMI registry is listening", "The RMI server port that can be used to manage the instance", "The host address where the RMI server is listening", "The state of the instance", "The location of the instance", "The Java options of the instance" };
CompositeType comp = new CompositeType("Instances", desc, InstancesMBean.INSTANCE, descriptions, itemTypes);
return comp;
}
use of javax.management.openmbean.OpenType in project karaf by apache.
the class JmxReference method createReferenceType.
private static CompositeType createReferenceType() {
try {
String description = "This type encapsulates Scr references";
String[] itemNames = ScrServiceMBean.REFERENCE;
OpenType[] itemTypes = new OpenType[itemNames.length];
String[] itemDescriptions = new String[itemNames.length];
itemTypes[0] = SimpleType.STRING;
itemTypes[1] = SimpleType.BOOLEAN;
itemTypes[2] = SimpleType.STRING;
itemTypes[3] = SimpleType.STRING;
itemTypes[4] = SimpleType.STRING;
itemTypes[5] = new ArrayType(1, SimpleType.STRING);
itemDescriptions[0] = "The name of the reference";
itemDescriptions[1] = "The state of the reference";
itemDescriptions[2] = "The cardinality of the reference";
itemDescriptions[3] = "The availability of the reference";
itemDescriptions[4] = "The policy of the reference";
itemDescriptions[5] = "The bound services";
return new CompositeType("Reference", description, itemNames, itemDescriptions, itemTypes);
} catch (OpenDataException e) {
throw new IllegalStateException("Unable to build reference type", e);
}
}
Aggregations