Permalink
Browse files

MBeanAttributeInfo.getDescriptor requires 1.6+

  • Loading branch information...
1 parent ec7b21c commit b617b499fc13ae12ab5bed5ea976085c9ab0a15f @dougm dougm committed Mar 18, 2009
Showing with 17 additions and 2 deletions.
  1. +17 −2 src/main/java/org/collectd/mx/MBeanCollector.java
@@ -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;
@@ -42,15 +43,27 @@
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;
}
@@ -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)) {

0 comments on commit b617b49

Please sign in to comment.