use of javax.management.openmbean.TabularDataSupport 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 (Iterator<String> iter = keys.iterator(); iter.hasNext(); ) {
String key = iter.next();
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 (Iterator<Object> iter = data.keySet().iterator(); iter.hasNext(); ) {
Object key = iter.next();
for (Iterator<?> iter1 = ((List<?>) key).iterator(); iter1.hasNext(); ) {
Object key1 = iter1.next();
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.TabularDataSupport in project druid by alibaba.
the class JdbcStatManager method getConnectionList.
public TabularData getConnectionList() throws JMException {
CompositeType rowType = JdbcConnectionStat.Entry.getCompositeType();
String[] indexNames = rowType.keySet().toArray(new String[rowType.keySet().size()]);
TabularType tabularType = new TabularType("ConnectionList", "ConnectionList", rowType, indexNames);
TabularData data = new TabularDataSupport(tabularType);
final ConcurrentMap<String, DataSourceProxyImpl> dataSources = DruidDriver.getProxyDataSources();
for (DataSourceProxyImpl dataSource : dataSources.values()) {
JdbcDataSourceStat dataSourceStat = dataSource.getDataSourceStat();
ConcurrentMap<Long, JdbcConnectionStat.Entry> connections = dataSourceStat.getConnections();
for (Map.Entry<Long, JdbcConnectionStat.Entry> entry : connections.entrySet()) {
data.put(entry.getValue().getCompositeData());
}
}
for (DruidDataSource instance : DruidDataSourceStatManager.getDruidDataSourceInstances()) {
JdbcDataSourceStat dataSourceStat = instance.getDataSourceStat();
ConcurrentMap<Long, JdbcConnectionStat.Entry> connections = dataSourceStat.getConnections();
for (Map.Entry<Long, JdbcConnectionStat.Entry> entry : connections.entrySet()) {
data.put(entry.getValue().getCompositeData());
}
}
return data;
}
use of javax.management.openmbean.TabularDataSupport 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.TabularDataSupport in project druid by alibaba.
the class DruidDataSourceStatManager method getDataSourceList.
public TabularData getDataSourceList() throws JMException {
CompositeType rowType = getDruidDataSourceCompositeType();
String[] indexNames = rowType.keySet().toArray(new String[rowType.keySet().size()]);
TabularType tabularType = new TabularType("DruidDataSourceStat", "DruidDataSourceStat", rowType, indexNames);
TabularData data = new TabularDataSupport(tabularType);
final Set<Object> dataSources = getInstances().keySet();
for (Object dataSource : dataSources) {
data.put(getCompositeData(dataSource));
}
return data;
}
use of javax.management.openmbean.TabularDataSupport in project jmxtrans by jmxtrans.
the class JmxResultProcessor method getResult.
/**
* Populates the Result objects. This is a recursive function. Query
* contains the keys that we want to get the values of.
*/
private void getResult(Builder<Result> accumulator, String attributeName, CompositeData cds) {
CompositeType t = cds.getCompositeType();
Map<String, Object> values = newHashMap();
Set<String> keys = t.keySet();
for (String key : keys) {
Object value = cds.get(key);
if (value instanceof TabularDataSupport) {
TabularDataSupport tds = (TabularDataSupport) value;
processTabularDataSupport(accumulator, attributeName + "." + key, tds);
// continue because we added tabular contents within above, but need primitives at this level
} else if (value instanceof CompositeDataSupport) {
// now recursively go through everything.
CompositeDataSupport cds2 = (CompositeDataSupport) value;
getResult(accumulator, attributeName, cds2);
// because we don't want to add to the list yet.
return;
} else {
values.put(key, value);
}
}
Result r = getNewResultObject(attributeName, values);
accumulator.add(r);
}
Aggregations