Skip to content

Commit

Permalink
MBeanAttributeInfo.getDescriptor requires 1.6+
Browse files Browse the repository at this point in the history
  • Loading branch information
dougm committed Mar 18, 2009
1 parent ec7b21c commit b617b49
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions src/main/java/org/collectd/mx/MBeanCollector.java
Expand Up @@ -18,6 +18,7 @@

package org.collectd.mx;

import java.lang.reflect.Method;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
Expand All @@ -42,15 +43,27 @@ public class MBeanCollector implements Runnable {

private static final Logger _log =
Logger.getLogger(MBeanCollector.class.getName());
private static final boolean _useDescriptors =
private static boolean _useDescriptors =
"true".equals(Network.getProperty("mx.descriptors", "true"));
private static Method _getDescriptor;
private static final String _metricTypeField =
Network.getProperty("mx.metricTypeField", "metricType");
private MBeanSender _sender;
private long _interval = 60;
private Map<String,MBeanQuery> _queries =
new HashMap<String,MBeanQuery>();

static {
if (_useDescriptors) {
try {
_getDescriptor = //1.6+
MBeanAttributeInfo.class.getMethod("getDescriptor",
(Class[])null);
} catch (Exception e) {
_useDescriptors = false;
}
}
}
public MBeanSender getSender() {
return _sender;
}
Expand Down Expand Up @@ -190,7 +203,9 @@ public void collect(MBeanQuery query, ObjectName name) throws Exception {
if (_useDescriptors) {
//e.g. spring @ManagedMetric(metricType = MetricType.COUNTER)
try {
Descriptor descriptor = attrInfo.get(attrName).getDescriptor();
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)) {
Expand Down

0 comments on commit b617b49

Please sign in to comment.