Merge branch 'collectd-4.7'
[collectd.git] / bindings / java / org / collectd / java / GenericJMXConfValue.java
index 0fcf31a..cdca02f 100644 (file)
@@ -27,8 +27,12 @@ import java.util.Set;
 import java.util.Iterator;
 import java.util.ArrayList;
 
+import java.math.BigDecimal;
+import java.math.BigInteger;
+
 import javax.management.MBeanServerConnection;
 import javax.management.ObjectName;
+import javax.management.openmbean.OpenType;
 import javax.management.openmbean.CompositeData;
 import javax.management.openmbean.InvalidKeyException;
 
@@ -54,12 +58,17 @@ import org.collectd.api.OConfigItem;
  */
 class GenericJMXConfValue
 {
-  private String ds_name;
+  private String _ds_name;
   private DataSet _ds;
   private List<String> _attributes;
   private String _instance_prefix;
   private boolean _is_table;
 
+  /**
+   * Converts a generic (OpenType) object to a number.
+   *
+   * Returns null if a conversion is not possible or not implemented.
+   */
   private Number genericObjectToNumber (Object obj, int ds_type) /* {{{ */
   {
     if (obj instanceof String)
@@ -78,6 +87,14 @@ class GenericJMXConfValue
         return (null);
       }
     }
+    else if (obj instanceof Byte)
+    {
+      return (new Byte ((Byte) obj));
+    }
+    else if (obj instanceof Short)
+    {
+      return (new Short ((Short) obj));
+    }
     else if (obj instanceof Integer)
     {
       return (new Integer ((Integer) obj));
@@ -86,10 +103,22 @@ class GenericJMXConfValue
     {
       return (new Long ((Long) obj));
     }
+    else if (obj instanceof Float)
+    {
+      return (new Float ((Float) obj));
+    }
     else if (obj instanceof Double)
     {
       return (new Double ((Double) obj));
     }
+    else if (obj instanceof BigDecimal)
+    {
+      return (BigDecimal.ZERO.add ((BigDecimal) obj));
+    }
+    else if (obj instanceof BigInteger)
+    {
+      return (BigInteger.ZERO.add ((BigInteger) obj));
+    }
 
     return (null);
   } /* }}} Number genericObjectToNumber */
@@ -283,9 +312,20 @@ class GenericJMXConfValue
     else
     {
       if (value instanceof CompositeData)
-        return (queryAttributeRecursive ((CompositeData) value, attrNameList));
+        return (queryAttributeRecursive((CompositeData) value, attrNameList));
+      else if (value instanceof OpenType)
+      {
+        OpenType ot = (OpenType) value;
+        Collectd.logNotice ("GenericJMXConfValue: Handling of OpenType \""
+            + ot.getTypeName () + "\" is not yet implemented.");
+        return (null);
+      }
       else
+      {
+        Collectd.logError ("GenericJMXConfValue: Received object of "
+            + "unknown class.");
         return (null);
+      }
     }
   } /* }}} Object queryAttribute */
 
@@ -347,7 +387,7 @@ class GenericJMXConfValue
     List<OConfigItem> children;
     Iterator<OConfigItem> iter;
 
-    this.ds_name = null;
+    this._ds_name = null;
     this._ds = null;
     this._attributes = new ArrayList<String> ();
     this._instance_prefix = null;
@@ -374,7 +414,7 @@ class GenericJMXConfValue
       {
         String tmp = getConfigString (child);
         if (tmp != null)
-          this.ds_name = tmp;
+          this._ds_name = tmp;
       }
       else if (child.getKey ().equalsIgnoreCase ("Table"))
       {
@@ -399,7 +439,7 @@ class GenericJMXConfValue
               + child.getKey ()));
     }
 
-    if (this.ds_name == null)
+    if (this._ds_name == null)
       throw (new IllegalArgumentException ("No data set was defined."));
     else if (this._attributes.size () == 0)
       throw (new IllegalArgumentException ("No attribute was defined."));
@@ -423,11 +463,11 @@ class GenericJMXConfValue
 
     if (this._ds == null)
     {
-      this._ds = Collectd.getDS (this.ds_name);
+      this._ds = Collectd.getDS (this._ds_name);
       if (this._ds == null)
       {
         Collectd.logError ("GenericJMXConfValue: Unknown type: "
-            + this.ds_name);
+            + this._ds_name);
         return;
       }
     }
@@ -436,7 +476,7 @@ class GenericJMXConfValue
     if (dsrc.size () != this._attributes.size ())
     {
       Collectd.logError ("GenericJMXConfValue.query: The data set "
-          + ds_name + " has " + this._ds.getDataSources ().size ()
+          + this._ds_name + " has " + this._ds.getDataSources ().size ()
           + " data sources, but there were " + this._attributes.size ()
           + " attributes configured. This doesn't match!");
       this._ds = null;
@@ -444,7 +484,7 @@ class GenericJMXConfValue
     }
 
     vl = new ValueList (pd);
-    vl.setType (this.ds_name);
+    vl.setType (this._ds_name);
     vl.setTypeInstance (this._instance_prefix);
 
     values = new ArrayList<Object> ();