use of javax.management.openmbean.CompositeDataSupport 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.CompositeDataSupport in project tomcat by apache.
the class JMXAccessorTask method createProperty.
/**
* create result as property with name from property prefix When result is
* an array and isSeparateArrayResults is true, resultproperty used as
* prefix (<code>resultproperty.0-array.length</code> and store the
* result array length at <code>resultproperty.length</code>. Other
* option is that you delimit your result with a delimiter
* (java.util.StringTokenizer is used).
*
* @param propertyPrefix Prefix for the property
* @param result The result
*/
protected void createProperty(String propertyPrefix, Object result) {
if (propertyPrefix == null) {
propertyPrefix = "";
}
if (result instanceof CompositeDataSupport) {
CompositeDataSupport data = (CompositeDataSupport) result;
CompositeType compositeType = data.getCompositeType();
Set<String> keys = compositeType.keySet();
for (String key : keys) {
Object value = data.get(key);
OpenType<?> type = compositeType.getType(key);
if (type instanceof SimpleType<?>) {
setProperty(propertyPrefix + "." + key, value);
} else {
createProperty(propertyPrefix + "." + key, value);
}
}
} else if (result instanceof TabularDataSupport) {
TabularDataSupport data = (TabularDataSupport) result;
for (Object key : data.keySet()) {
for (Object key1 : ((List<?>) key)) {
CompositeData valuedata = data.get(new Object[] { key1 });
Object value = valuedata.get("value");
OpenType<?> type = valuedata.getCompositeType().getType("value");
if (type instanceof SimpleType<?>) {
setProperty(propertyPrefix + "." + key1, value);
} else {
createProperty(propertyPrefix + "." + key1, value);
}
}
}
} else if (result.getClass().isArray()) {
if (isSeparatearrayresults()) {
int size = 0;
for (int i = 0; i < Array.getLength(result); i++) {
if (setProperty(propertyPrefix + "." + size, Array.get(result, i))) {
size++;
}
}
if (size > 0) {
setProperty(propertyPrefix + ".Length", Integer.toString(size));
}
}
} else {
String delim = getDelimiter();
if (delim != null) {
StringTokenizer tokenizer = new StringTokenizer(result.toString(), delim);
int size = 0;
for (; tokenizer.hasMoreTokens(); ) {
String token = tokenizer.nextToken();
if (setProperty(propertyPrefix + "." + size, token)) {
size++;
}
}
if (size > 0) {
setProperty(propertyPrefix + ".Length", Integer.toString(size));
}
} else {
setProperty(propertyPrefix, result.toString());
}
}
}
use of javax.management.openmbean.CompositeDataSupport in project druid by alibaba.
the class JdbcStatManager method getSqlList.
@Override
public TabularData getSqlList() throws JMException {
CompositeType rowType = JdbcSqlStat.getCompositeType();
String[] indexNames = rowType.keySet().toArray(new String[rowType.keySet().size()]);
TabularType tabularType = new TabularType("SqlListStatistic", "SqlListStatistic", rowType, indexNames);
TabularData data = new TabularDataSupport(tabularType);
JdbcDataSourceStat globalStat = JdbcDataSourceStat.getGlobal();
if (globalStat != null) {
Map<String, JdbcSqlStat> statMap = globalStat.getSqlStatMap();
for (Map.Entry<String, JdbcSqlStat> entry : statMap.entrySet()) {
if (entry.getValue().getExecuteCount() == 0 && entry.getValue().getRunningCount() == 0) {
continue;
}
Map<String, Object> map = entry.getValue().getData();
map.put("URL", globalStat.getUrl());
data.put(new CompositeDataSupport(JdbcSqlStat.getCompositeType(), map));
}
}
for (DataSourceProxyImpl dataSource : DruidDriver.getProxyDataSources().values()) {
JdbcDataSourceStat druidDataSourceStat = dataSource.getDataSourceStat();
if (druidDataSourceStat == globalStat) {
continue;
}
Map<String, JdbcSqlStat> statMap = druidDataSourceStat.getSqlStatMap();
for (Map.Entry<String, JdbcSqlStat> entry : statMap.entrySet()) {
if (entry.getValue().getExecuteCount() == 0 && entry.getValue().getRunningCount() == 0) {
continue;
}
Map<String, Object> map = entry.getValue().getData();
map.put("URL", dataSource.getUrl());
data.put(new CompositeDataSupport(JdbcSqlStat.getCompositeType(), map));
}
}
for (DruidDataSource dataSource : DruidDataSourceStatManager.getDruidDataSourceInstances()) {
JdbcDataSourceStat druidDataSourceStat = dataSource.getDataSourceStat();
if (druidDataSourceStat == globalStat) {
continue;
}
Map<String, JdbcSqlStat> statMap = druidDataSourceStat.getSqlStatMap();
for (Map.Entry<String, JdbcSqlStat> entry : statMap.entrySet()) {
if (entry.getValue().getExecuteCount() == 0 && entry.getValue().getRunningCount() == 0) {
continue;
}
Map<String, Object> map = entry.getValue().getData();
map.put("URL", dataSource.getUrl());
data.put(new CompositeDataSupport(JdbcSqlStat.getCompositeType(), map));
}
}
return data;
}
use of javax.management.openmbean.CompositeDataSupport in project aries by apache.
the class BundleEventDataTest method testFrom.
@Test
public void testFrom() throws Exception {
Map<String, Object> items = new HashMap<String, Object>();
items.put(IDENTIFIER, new Long(7));
items.put(SYMBOLIC_NAME, "t");
items.put(LOCATION, "l");
items.put(EVENT, BundleEvent.RESOLVED);
CompositeData compositeData = new CompositeDataSupport(BUNDLE_EVENT_TYPE, items);
BundleEventData event = BundleEventData.from(compositeData);
assertEquals(7, event.getBundleId());
assertEquals("t", event.getBundleSymbolicName());
assertEquals("l", event.getLocation());
assertEquals(BundleEvent.RESOLVED, event.getEventType());
}
use of javax.management.openmbean.CompositeDataSupport in project aries by apache.
the class ServiceEventDataTest method testFrom.
@Test
public void testFrom() throws Exception {
Map<String, Object> items = new HashMap<String, Object>();
items.put(IDENTIFIER, new Long(7));
items.put(BUNDLE_IDENTIFIER, new Long(67));
items.put(BUNDLE_LOCATION, "string");
items.put(BUNDLE_SYMBOLIC_NAME, "test");
items.put(OBJECT_CLASS, new String[] { "org.apache.aries.jmx.Mock" });
items.put(EVENT, ServiceEvent.MODIFIED);
CompositeData compositeData = new CompositeDataSupport(SERVICE_EVENT_TYPE, items);
ServiceEventData event = ServiceEventData.from(compositeData);
assertEquals(7, event.getServiceId());
assertEquals(67, event.getBundleId());
assertArrayEquals(new String[] { "org.apache.aries.jmx.Mock" }, event.getServiceInterfaces());
assertEquals("test", event.getBundleSymbolicName());
assertEquals("string", event.getBundleLocation());
assertEquals(ServiceEvent.MODIFIED, event.getEventType());
}
Aggregations