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;
*/
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)
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));
{
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 */
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 */
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;
{
String tmp = getConfigString (child);
if (tmp != null)
- this.ds_name = tmp;
+ this._ds_name = tmp;
}
else if (child.getKey ().equalsIgnoreCase ("Table"))
{
+ 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."));
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;
}
}
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;
}
vl = new ValueList (pd);
- vl.setType (this.ds_name);
+ vl.setType (this._ds_name);
vl.setTypeInstance (this._instance_prefix);
values = new ArrayList<Object> ();