use of javax.management.openmbean.CompositeData 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.CompositeData in project jcollectd by collectd.
the class MBeanCollector method collect.
public void collect(MBeanQuery query, ObjectName name) throws Exception {
MBeanServerConnection conn = _sender.getMBeanServerConnection();
String plugin = query.getPlugin();
if (plugin == null) {
plugin = name.getDomain();
}
Map<String, MBeanAttributeInfo> attrInfo = null;
if (_useDescriptors) {
MBeanInfo info = conn.getMBeanInfo(name);
attrInfo = new HashMap<String, MBeanAttributeInfo>();
for (MBeanAttributeInfo ainfo : info.getAttributes()) {
attrInfo.put(ainfo.getName(), ainfo);
}
}
for (MBeanAttribute attr : query.getAttributes()) {
String attrName = attr.getAttributeName();
Object obj;
try {
obj = conn.getAttribute(name, attrName);
} catch (Exception e) {
//XXX remove attr for future collection e.g. UnsupportedOperation
continue;
}
if (_useDescriptors) {
//e.g. spring @ManagedMetric(metricType = MetricType.COUNTER)
try {
Descriptor descriptor = (Descriptor) _getDescriptor.invoke(attrInfo.get(attrName), (Object[]) null);
Object type = descriptor.getFieldValue(_metricTypeField);
if (TypesDB.NAME_COUNTER.equals(type)) {
if (attr.getTypeName().equals(TypesDB.NAME_GAUGE)) {
attr.setTypeName(TypesDB.NAME_COUNTER);
}
attr.setDataType(Network.DS_TYPE_COUNTER);
}
} catch (Exception e) {
}
}
if (obj instanceof CompositeData) {
CompositeData data = (CompositeData) obj;
String key = attr.getCompositeKey();
if (key == null) {
//no key specified; collect all
Set<String> keys = data.getCompositeType().keySet();
for (String ckey : keys) {
obj = data.get(ckey);
if (!isNumber(obj)) {
continue;
}
dispatch(query, plugin, attrName + "." + ckey, name, attr, (Number) obj);
}
continue;
} else {
obj = data.get(key);
}
}
if (!isNumber(obj)) {
continue;
}
dispatch(query, plugin, attr.getName(), name, attr, (Number) obj);
}
_sender.flush();
}
use of javax.management.openmbean.CompositeData in project hibernate-orm by hibernate.
the class HibernateStatsImpl method getQueryStats.
@Override
public TabularData getQueryStats() {
final List<CompositeData> result = new ArrayList<CompositeData>();
final Statistics statistics = getStatistics();
for (String query : statistics.getQueries()) {
final QueryStats queryStats = new QueryStats(query, statistics.getQueryStatistics(query));
result.add(queryStats.toCompositeData());
}
final TabularData td = QueryStats.newTabularDataInstance();
td.putAll(result.toArray(new CompositeData[result.size()]));
return td;
}
use of javax.management.openmbean.CompositeData in project hibernate-orm by hibernate.
the class HibernateStatsImpl method getCacheRegionStats.
@Override
public TabularData getCacheRegionStats() {
final List<CompositeData> list = new ArrayList<CompositeData>();
final Statistics statistics = getStatistics();
for (String region : statistics.getSecondLevelCacheRegionNames()) {
final CacheRegionStats l2CacheStats = new CacheRegionStats(region, statistics.getSecondLevelCacheStatistics(region));
list.add(l2CacheStats.toCompositeData());
}
final TabularData td = CacheRegionStats.newTabularDataInstance();
td.putAll(list.toArray(new CompositeData[list.size()]));
return td;
}
use of javax.management.openmbean.CompositeData in project neo4j by neo4j.
the class Dbinfo method compositeDataAsMap.
private Map<?, ?> compositeDataAsMap(CompositeData item) {
Map<String, Object> result = new HashMap<String, Object>();
CompositeData compositeData = (CompositeData) item;
for (String key : compositeData.getCompositeType().keySet()) {
result.put(key, compositeData.get(key));
}
return result;
}
Aggregations