Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

MBeanAttributeInfo.getDescriptor requires 1.6+

  • Loading branch information...
commit b617b499fc13ae12ab5bed5ea976085c9ab0a15f 1 parent ec7b21c
Doug MacEachern authored March 17, 2009
19  src/main/java/org/collectd/mx/MBeanCollector.java
@@ -18,6 +18,7 @@
18 18
 
19 19
 package org.collectd.mx;
20 20
 
  21
+import java.lang.reflect.Method;
21 22
 import java.util.HashMap;
22 23
 import java.util.Map;
23 24
 import java.util.Set;
@@ -42,8 +43,9 @@
42 43
 
43 44
     private static final Logger _log =
44 45
         Logger.getLogger(MBeanCollector.class.getName());
45  
-    private static final boolean _useDescriptors =
  46
+    private static boolean _useDescriptors =
46 47
         "true".equals(Network.getProperty("mx.descriptors", "true"));
  48
+    private static Method _getDescriptor;
47 49
     private static final String _metricTypeField =
48 50
         Network.getProperty("mx.metricTypeField", "metricType");
49 51
     private MBeanSender _sender;
@@ -51,6 +53,17 @@
51 53
     private Map<String,MBeanQuery> _queries =
52 54
         new HashMap<String,MBeanQuery>();
53 55
 
  56
+    static {
  57
+        if (_useDescriptors) {
  58
+            try {
  59
+                _getDescriptor = //1.6+
  60
+                    MBeanAttributeInfo.class.getMethod("getDescriptor",
  61
+                                                       (Class[])null);
  62
+            } catch (Exception e) {
  63
+                _useDescriptors = false;
  64
+            }
  65
+        }
  66
+    }
54 67
     public MBeanSender getSender() {
55 68
         return _sender;
56 69
     }
@@ -190,7 +203,9 @@ public void collect(MBeanQuery query, ObjectName name) throws Exception {
190 203
             if (_useDescriptors) {
191 204
                 //e.g. spring @ManagedMetric(metricType = MetricType.COUNTER)
192 205
                 try {
193  
-                    Descriptor descriptor = attrInfo.get(attrName).getDescriptor();
  206
+                    Descriptor descriptor =
  207
+                        (Descriptor)_getDescriptor.invoke(attrInfo.get(attrName),
  208
+                                                          (Object[])null);
194 209
                     Object type = descriptor.getFieldValue(_metricTypeField);
195 210
                     if (TypesDB.NAME_COUNTER.equals(type)) {
196 211
                         if (attr.getTypeName().equals(TypesDB.NAME_GAUGE)) {

0 notes on commit b617b49

Please sign in to comment.
Something went wrong with that request. Please try again.