use of javax.management.openmbean.CompositeType in project nhin-d by DirectProject.
the class DNSServer method registerMBean.
/**
* Register the MBean
*/
private void registerMBean(DNSServerSettings settings) {
String[] itemNames = { "Port", "Bind Address", "Max Request Size", "Max Outstanding Accepts", "Max Active Accepts", "Max Connection Backlog", "Read Buffer Size", "Send Timeout", "Receive Timeout", "Socket Close Timeout" };
String[] itemDesc = { "Port", "Bind Address", "Max Request Size", "Max Outstanding Accepts", "Max Active Accepts", "Max Connection Backlog", "Read Buffer Size", "Send Timeout", "Receive Timeout", "Socket Close Timeout" };
OpenType<?>[] types = { SimpleType.INTEGER, SimpleType.STRING, SimpleType.INTEGER, SimpleType.INTEGER, SimpleType.INTEGER, SimpleType.INTEGER, SimpleType.INTEGER, SimpleType.INTEGER, SimpleType.INTEGER, SimpleType.INTEGER };
Object[] settingsValues = { settings.getPort(), settings.getBindAddress(), settings.getMaxRequestSize(), settings.getMaxOutstandingAccepts(), settings.getMaxActiveRequests(), settings.getMaxConnectionBacklog(), settings.getReadBufferSize(), settings.getSendTimeout(), settings.getReceiveTimeout(), settings.getSocketCloseTimeout() };
try {
CompositeType settingsType = new CompositeType(DNSServerSettings.class.getSimpleName(), "DNS server settings.", itemNames, itemDesc, types);
settingsData = new CompositeDataSupport(settingsType, itemNames, settingsValues);
} catch (OpenDataException e) {
LOGGER.error("Failed to create settings composite type: " + e.getLocalizedMessage(), e);
return;
}
Class<?> clazz = this.getClass();
final StringBuilder objectNameBuilder = new StringBuilder(clazz.getPackage().getName());
objectNameBuilder.append(":type=").append(clazz.getSimpleName());
objectNameBuilder.append(",name=").append(UUID.randomUUID());
try {
final StandardMBean mbean = new StandardMBean(this, DNSServerMBean.class);
final MBeanServer mbeanServer = ManagementFactory.getPlatformMBeanServer();
mbeanServer.registerMBean(mbean, new ObjectName(objectNameBuilder.toString()));
} catch (JMException e) {
LOGGER.error("Unable to register the DNSServer MBean", e);
}
}
use of javax.management.openmbean.CompositeType in project jdk8u_jdk by JetBrains.
the class CompositeDataStringTest method main.
public static void main(String[] args) throws Exception {
CompositeType basicCT = new CompositeType("basicCT", "basic CompositeType", new String[] { "name", "value" }, new String[] { "name", "value" }, new OpenType<?>[] { SimpleType.STRING, SimpleType.INTEGER });
CompositeType ct = new CompositeType("noddy", "descr", new String[] { "strings", "ints", "cds" }, new String[] { "string array", "int array", "composite data array" }, new OpenType<?>[] { ArrayType.getArrayType(SimpleType.STRING), ArrayType.getPrimitiveArrayType(int[].class), ArrayType.getArrayType(basicCT) });
CompositeData basicCD1 = new CompositeDataSupport(basicCT, new String[] { "name", "value" }, new Object[] { "ceathar", 4 });
CompositeData basicCD2 = new CompositeDataSupport(basicCT, new String[] { "name", "value" }, new Object[] { "naoi", 9 });
CompositeData cd = new CompositeDataSupport(ct, new String[] { "strings", "ints", "cds" }, new Object[] { new String[] { "fred", "jim", "sheila" }, new int[] { 2, 3, 5, 7 }, new CompositeData[] { basicCD1, basicCD2 } });
String s = cd.toString();
System.out.println("CompositeDataSupport.toString(): " + s);
String[] expected = { "fred, jim, sheila", "2, 3, 5, 7", "ceathar", "naoi" };
boolean ok = true;
for (String expect : expected) {
if (s.contains(expect))
System.out.println("OK: string contains <" + expect + ">");
else {
ok = false;
System.out.println("NOT OK: string does not contain <" + expect + ">");
}
}
if (ok)
System.out.println("TEST PASSED");
else
throw new Exception("TEST FAILED: string did not contain expected substrings");
}
use of javax.management.openmbean.CompositeType in project tdi-studio-se by Talend.
the class AttributeContentProvider method addAttributeItems.
/**
* Adds the attribute to the given list.
*
* @param parent The parent attribute
* @param value The value
*/
private void addAttributeItems(AttributeNode parent, Object value) {
if (value instanceof CompositeData) {
CompositeData compositeData = (CompositeData) value;
CompositeType type = compositeData.getCompositeType();
for (String key : type.keySet()) {
AttributeNode attribute = new AttributeNode(key, parent);
parent.addChild(attribute);
addAttributeItems(attribute, compositeData.get(key));
}
} else if (value instanceof TabularData) {
TabularData tabularData = (TabularData) value;
for (Object keyList : tabularData.keySet()) {
@SuppressWarnings("unchecked") Object[] keys = ((List<Object>) keyList).toArray(new Object[0]);
AttributeNode attribute = new AttributeNode(String.valueOf(keys[0]), parent);
parent.addChild(attribute);
addAttributeItems(attribute, tabularData.get(keys));
}
} else if (value instanceof Long || value instanceof Integer || value instanceof Double) {
parent.setRgb(getRGB(parent.getQualifiedName()));
parent.setValidLeaf(true);
}
}
use of javax.management.openmbean.CompositeType in project deltaspike by apache.
the class DeltaSpikeConfigInfo method getConfigSources.
@Override
public TabularData getConfigSources() {
ClassLoader originalCl = Thread.currentThread().getContextClassLoader();
try {
Thread.currentThread().setContextClassLoader(appConfigClassLoader);
String typeName = "ConfigSources";
OpenType<?>[] types = new OpenType<?>[] { SimpleType.INTEGER, SimpleType.STRING };
String[] keys = new String[] { "Ordinal", "ConfigSource" };
CompositeType ct = new CompositeType(typeName, typeName, keys, keys, types);
TabularType type = new TabularType(typeName, typeName, ct, keys);
TabularDataSupport configSourceInfo = new TabularDataSupport(type);
ConfigSource[] configSources = ConfigResolver.getConfigSources();
for (ConfigSource configSource : configSources) {
configSourceInfo.put(new CompositeDataSupport(ct, keys, new Object[] { configSource.getOrdinal(), configSource.getConfigName() }));
}
return configSourceInfo;
} catch (OpenDataException e) {
throw new RuntimeException(e);
} finally {
// set back the original TCCL
Thread.currentThread().setContextClassLoader(originalCl);
}
}
use of javax.management.openmbean.CompositeType 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);
}
}
Aggregations