From: Caden Date: Tue, 22 Jan 2019 23:10:25 +0000 (-0800) Subject: obey contrib format X-Git-Tag: collectd-5.11.0~15^2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=73ba929d7d5cedda586a6f4a47e17181a950b996;p=thirdparty%2Fcollectd.git obey contrib format --- diff --git a/bindings/java/org/collectd/java/GenericJMXConfValue.java b/bindings/java/org/collectd/java/GenericJMXConfValue.java index c175dd5b3..2827daa58 100644 --- a/bindings/java/org/collectd/java/GenericJMXConfValue.java +++ b/bindings/java/org/collectd/java/GenericJMXConfValue.java @@ -65,80 +65,62 @@ import org.collectd.api.OConfigItem; * * @see GenericJMXConfMBean */ -class GenericJMXConfValue -{ - private String _ds_name; - private DataSet _ds; - private List _attributes; - private String _instance_prefix; - private List _instance_from; - private String _plugin_name; - private boolean _is_table; +class GenericJMXConfValue { +private + String _ds_name; +private + DataSet _ds; +private + List _attributes; +private + String _instance_prefix; +private + List _instance_from; +private + String _plugin_name; +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) /* {{{ */ +private + Number genericObjectToNumber(Object obj, int ds_type) /* {{{ */ { - if (obj instanceof String) - { - String str = (String) obj; - - try - { + if (obj instanceof String) { + String str = (String)obj; + + try { if (ds_type == DataSource.TYPE_GAUGE) - return (new Double (str)); + return (new Double(str)); else - return (new Long (str)); - } - catch (NumberFormatException e) - { + return (new Long(str)); + } catch (NumberFormatException e) { 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)); - } - else if (obj instanceof Long) - { - 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)); - } - else if (obj instanceof AtomicInteger) - { - return (new Integer(((AtomicInteger) obj).get())); - } - else if (obj instanceof AtomicLong) - { - return (new Long(((AtomicLong) obj).get())); - } - else if (obj instanceof Boolean) { + } 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)); + } else if (obj instanceof Long) { + 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)); + } else if (obj instanceof AtomicInteger) { + return (new Integer(((AtomicInteger)obj).get())); + } else if (obj instanceof AtomicLong) { + return (new Long(((AtomicLong)obj).get())); + } else if (obj instanceof Boolean) { return (Boolean)obj ? 1 : 0; } return (null); @@ -149,21 +131,21 @@ class GenericJMXConfValue * * Returns null if one or more objects could not be converted. */ - private List genericListToNumber (List objects) /* {{{ */ +private + List genericListToNumber(List objects) /* {{{ */ { - List ret = new ArrayList (); - List dsrc = this._ds.getDataSources (); + List ret = new ArrayList(); + List dsrc = this._ds.getDataSources(); - assert (objects.size () == dsrc.size ()); + assert(objects.size() == dsrc.size()); - for (int i = 0; i < objects.size (); i++) - { + for (int i = 0; i < objects.size(); i++) { Number n; - n = genericObjectToNumber (objects.get (i), dsrc.get (i).getType ()); + n = genericObjectToNumber(objects.get(i), dsrc.get(i).getType()); if (n == null) return (null); - ret.add (n); + ret.add(n); } return (ret); @@ -177,321 +159,292 @@ class GenericJMXConfValue * CompositeData doesn't have the specified key or one returned * object cannot converted to a number then the function will return null. */ - private List genericCompositeToNumber (List cdlist, /* {{{ */ - String key) - { - List objects = new ArrayList (); +private + List genericCompositeToNumber(List cdlist, /* {{{ */ + String key) { + List objects = new ArrayList(); - for (int i = 0; i < cdlist.size (); i++) - { + for (int i = 0; i < cdlist.size(); i++) { CompositeData cd; Object value; - cd = cdlist.get (i); - try - { - value = cd.get (key); - } - catch (InvalidKeyException e) - { + cd = cdlist.get(i); + try { + value = cd.get(key); + } catch (InvalidKeyException e) { return (null); } - objects.add (value); + objects.add(value); } - return (genericListToNumber (objects)); + return (genericListToNumber(objects)); } /* }}} List genericCompositeToNumber */ - private void submitTable (List objects, ValueList vl, /* {{{ */ - String instancePrefix) - { +private + void submitTable(List objects, ValueList vl, /* {{{ */ + String instancePrefix) { List cdlist; Set keySet = null; Iterator keyIter; - cdlist = new ArrayList (); - for (int i = 0; i < objects.size (); i++) - { + cdlist = new ArrayList(); + for (int i = 0; i < objects.size(); i++) { Object obj; - obj = objects.get (i); - if (obj instanceof CompositeData) - { + obj = objects.get(i); + if (obj instanceof CompositeData) { CompositeData cd; - cd = (CompositeData) obj; + cd = (CompositeData)obj; if (i == 0) - keySet = cd.getCompositeType ().keySet (); - - cdlist.add (cd); - } - else - { - Collectd.logError ("GenericJMXConfValue: At least one of the " - + "attributes was not of type `CompositeData', as required " - + "when table is set to `true'."); + keySet = cd.getCompositeType().keySet(); + + cdlist.add(cd); + } else { + Collectd.logError( + "GenericJMXConfValue: At least one of the " + + "attributes was not of type `CompositeData', as required " + + "when table is set to `true'."); return; } } - assert (keySet != null); + assert(keySet != null); - keyIter = keySet.iterator (); - while (keyIter.hasNext ()) - { + keyIter = keySet.iterator(); + while (keyIter.hasNext()) { String key; List values; - key = keyIter.next (); - values = genericCompositeToNumber (cdlist, key); - if (values == null) - { - Collectd.logError ("GenericJMXConfValue: Cannot build a list of " - + "numbers for key " + key + ". Most likely not all attributes " - + "have this key."); + key = keyIter.next(); + values = genericCompositeToNumber(cdlist, key); + if (values == null) { + Collectd.logError("GenericJMXConfValue: Cannot build a list of " + + "numbers for key " + key + + ". Most likely not all attributes " + + "have this key."); continue; } if (instancePrefix == null) - vl.setTypeInstance (key); + vl.setTypeInstance(key); else - vl.setTypeInstance (instancePrefix + key); - vl.setValues (values); + vl.setTypeInstance(instancePrefix + key); + vl.setValues(values); - Collectd.dispatchValues (vl); + Collectd.dispatchValues(vl); } } /* }}} void submitTable */ - private void submitScalar (List objects, ValueList vl, /* {{{ */ - String instancePrefix) - { +private + void submitScalar(List objects, ValueList vl, /* {{{ */ + String instancePrefix) { List values; - values = genericListToNumber (objects); - if (values == null) - { - Collectd.logError ("GenericJMXConfValue: Cannot convert list of " - + "objects to numbers."); + values = genericListToNumber(objects); + if (values == null) { + Collectd.logError("GenericJMXConfValue: Cannot convert list of " + + "objects to numbers."); return; } if (instancePrefix == null) - vl.setTypeInstance (""); + vl.setTypeInstance(""); else - vl.setTypeInstance (instancePrefix); - vl.setValues (values); + vl.setTypeInstance(instancePrefix); + vl.setValues(values); - Collectd.dispatchValues (vl); + Collectd.dispatchValues(vl); } /* }}} void submitScalar */ - private Object queryAttributeRecursive (CompositeData parent, /* {{{ */ - List attrName) - { +private + Object queryAttributeRecursive(CompositeData parent, /* {{{ */ + List attrName) { String key; Object value; - key = attrName.remove (0); + key = attrName.remove(0); - try - { - value = parent.get (key); - } - catch (InvalidKeyException e) - { + try { + value = parent.get(key); + } catch (InvalidKeyException e) { return (null); } - if (attrName.size () == 0) - { + if (attrName.size() == 0) { return (value); - } - else - { + } else { if (value instanceof CompositeData) - return (queryAttributeRecursive ((CompositeData) value, attrName)); + return (queryAttributeRecursive((CompositeData)value, attrName)); else if (value instanceof TabularData) - return (queryAttributeRecursive ((TabularData) value, attrName)); + return (queryAttributeRecursive((TabularData)value, attrName)); else return (null); } } /* }}} queryAttributeRecursive */ - private Object queryAttributeRecursive (TabularData parent, /* {{{ */ - List attrName) - { +private + Object queryAttributeRecursive(TabularData parent, /* {{{ */ + List attrName) { String key; Object value = null; - key = attrName.remove (0); + key = attrName.remove(0); - @SuppressWarnings("unchecked") - Collection table = (Collection) parent.values(); - for (CompositeData compositeData : table) - { - if (key.equals(compositeData.get("key"))) - { + @SuppressWarnings("unchecked") Collection table = + (Collection)parent.values(); + for (CompositeData compositeData : table) { + if (key.equals(compositeData.get("key"))) { value = compositeData.get("value"); } } - if (null == value) - { + if (null == value) { return (null); } - if (attrName.size () == 0) - { + if (attrName.size() == 0) { return (value); - } - else - { + } else { if (value instanceof CompositeData) - return (queryAttributeRecursive ((CompositeData) value, attrName)); + return (queryAttributeRecursive((CompositeData)value, attrName)); else if (value instanceof TabularData) - return (queryAttributeRecursive ((TabularData) value, attrName)); + return (queryAttributeRecursive((TabularData)value, attrName)); else return (null); } } /* }}} queryAttributeRecursive */ - private Object queryAttribute (MBeanServerConnection conn, /* {{{ */ - ObjectName objName, String attrName) - { +private + Object queryAttribute(MBeanServerConnection conn, /* {{{ */ + ObjectName objName, String attrName) { List attrNameList; String key; Object value; String[] attrNameArray; - attrNameList = new ArrayList (); + attrNameList = new ArrayList(); - attrNameArray = attrName.split ("\\."); + attrNameArray = attrName.split("\\."); key = attrNameArray[0]; for (int i = 1; i < attrNameArray.length; i++) - attrNameList.add (attrNameArray[i]); - - try - { - try - { - value = conn.getAttribute (objName, key); - } - catch (javax.management.AttributeNotFoundException e) - { - value = conn.invoke (objName, key, /* args = */ null, /* types = */ null); + attrNameList.add(attrNameArray[i]); + + try { + try { + value = conn.getAttribute(objName, key); + } catch (javax.management.AttributeNotFoundException e) { + value = + conn.invoke(objName, key, /* args = */ null, /* types = */ null); } - } - catch (Exception e) - { - Collectd.logError ("GenericJMXConfValue.query: getAttribute failed: " - + e); + } catch (Exception e) { + Collectd.logError("GenericJMXConfValue.query: getAttribute failed: " + e); return (null); } - if (attrNameList.size () == 0) - { + if (attrNameList.size() == 0) { return (value); - } - else - { + } else { if (value instanceof CompositeData) - return (queryAttributeRecursive((CompositeData) value, attrNameList)); + return (queryAttributeRecursive((CompositeData)value, attrNameList)); else if (value instanceof TabularData) - return (queryAttributeRecursive((TabularData) value, attrNameList)); - else if (value instanceof OpenType) - { - OpenType ot = (OpenType) value; - Collectd.logNotice ("GenericJMXConfValue: Handling of OpenType \"" - + ot.getTypeName () + "\" is not yet implemented."); + return (queryAttributeRecursive((TabularData)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. " + attrName + " " + ((value == null)?"null":value.getClass().getName())); + } else { + Collectd.logError( + "GenericJMXConfValue: Received object of " + "unknown class. " + + attrName + " " + + ((value == null) ? "null" : value.getClass().getName())); return (null); } } } /* }}} Object queryAttribute */ - private String join (String separator, List list) /* {{{ */ +private + String join(String separator, List list) /* {{{ */ { StringBuffer sb; - sb = new StringBuffer (); + sb = new StringBuffer(); - for (int i = 0; i < list.size (); i++) - { + for (int i = 0; i < list.size(); i++) { if (i > 0) - sb.append ("-"); - sb.append (list.get (i)); + sb.append("-"); + sb.append(list.get(i)); } - return (sb.toString ()); + return (sb.toString()); } /* }}} String join */ - private String getConfigString (OConfigItem ci) /* {{{ */ +private + String getConfigString(OConfigItem ci) /* {{{ */ { List values; OConfigValue v; - values = ci.getValues (); - if (values.size () != 1) - { - Collectd.logError ("GenericJMXConfValue: The " + ci.getKey () - + " configuration option needs exactly one string argument."); + values = ci.getValues(); + if (values.size() != 1) { + Collectd.logError( + "GenericJMXConfValue: The " + ci.getKey() + + " configuration option needs exactly one string argument."); return (null); } - v = values.get (0); - if (v.getType () != OConfigValue.OCONFIG_TYPE_STRING) - { - Collectd.logError ("GenericJMXConfValue: The " + ci.getKey () - + " configuration option needs exactly one string argument."); + v = values.get(0); + if (v.getType() != OConfigValue.OCONFIG_TYPE_STRING) { + Collectd.logError( + "GenericJMXConfValue: The " + ci.getKey() + + " configuration option needs exactly one string argument."); return (null); } - return (v.getString ()); + return (v.getString()); } /* }}} String getConfigString */ - private Boolean getConfigBoolean (OConfigItem ci) /* {{{ */ +private + Boolean getConfigBoolean(OConfigItem ci) /* {{{ */ { List values; OConfigValue v; Boolean b; - values = ci.getValues (); - if (values.size () != 1) - { - Collectd.logError ("GenericJMXConfValue: The " + ci.getKey () - + " configuration option needs exactly one boolean argument."); + values = ci.getValues(); + if (values.size() != 1) { + Collectd.logError( + "GenericJMXConfValue: The " + ci.getKey() + + " configuration option needs exactly one boolean argument."); return (null); } - v = values.get (0); - if (v.getType () != OConfigValue.OCONFIG_TYPE_BOOLEAN) - { - Collectd.logError ("GenericJMXConfValue: The " + ci.getKey () - + " configuration option needs exactly one boolean argument."); + v = values.get(0); + if (v.getType() != OConfigValue.OCONFIG_TYPE_BOOLEAN) { + Collectd.logError( + "GenericJMXConfValue: The " + ci.getKey() + + " configuration option needs exactly one boolean argument."); return (null); } - return (new Boolean (v.getBoolean ())); + return (new Boolean(v.getBoolean())); } /* }}} String getConfigBoolean */ /** * Constructs a new value with the configured properties. */ - public GenericJMXConfValue (OConfigItem ci) /* {{{ */ - throws IllegalArgumentException - { +public + GenericJMXConfValue(OConfigItem ci) /* {{{ */ + throws IllegalArgumentException { List children; Iterator iter; this._ds_name = null; this._ds = null; - this._attributes = new ArrayList (); + this._attributes = new ArrayList(); this._instance_prefix = null; - this._instance_from = new ArrayList (); + this._instance_from = new ArrayList(); this._plugin_name = null; this._is_table = false; @@ -506,57 +459,44 @@ class GenericJMXConfValue * InstancePrefix "heap-" * */ - children = ci.getChildren (); - iter = children.iterator (); - while (iter.hasNext ()) - { - OConfigItem child = iter.next (); - - if (child.getKey ().equalsIgnoreCase ("Type")) - { - String tmp = getConfigString (child); + children = ci.getChildren(); + iter = children.iterator(); + while (iter.hasNext()) { + OConfigItem child = iter.next(); + + if (child.getKey().equalsIgnoreCase("Type")) { + String tmp = getConfigString(child); if (tmp != null) this._ds_name = tmp; - } - else if (child.getKey ().equalsIgnoreCase ("Table")) - { - Boolean tmp = getConfigBoolean (child); + } else if (child.getKey().equalsIgnoreCase("Table")) { + Boolean tmp = getConfigBoolean(child); if (tmp != null) - this._is_table = tmp.booleanValue (); - } - else if (child.getKey ().equalsIgnoreCase ("Attribute")) - { - String tmp = getConfigString (child); + this._is_table = tmp.booleanValue(); + } else if (child.getKey().equalsIgnoreCase("Attribute")) { + String tmp = getConfigString(child); if (tmp != null) - this._attributes.add (tmp); - } - else if (child.getKey ().equalsIgnoreCase ("InstancePrefix")) - { - String tmp = getConfigString (child); + this._attributes.add(tmp); + } else if (child.getKey().equalsIgnoreCase("InstancePrefix")) { + String tmp = getConfigString(child); if (tmp != null) this._instance_prefix = tmp; - } - else if (child.getKey ().equalsIgnoreCase ("InstanceFrom")) - { - String tmp = getConfigString (child); + } else if (child.getKey().equalsIgnoreCase("InstanceFrom")) { + String tmp = getConfigString(child); if (tmp != null) - this._instance_from.add (tmp); - } - else if (child.getKey ().equalsIgnoreCase ("PluginName")) - { - String tmp = getConfigString (child); + this._instance_from.add(tmp); + } else if (child.getKey().equalsIgnoreCase("PluginName")) { + String tmp = getConfigString(child); if (tmp != null) this._plugin_name = tmp; - } - else - throw (new IllegalArgumentException ("Unknown option: " - + child.getKey ())); + } else + throw( + new IllegalArgumentException("Unknown option: " + child.getKey())); } 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.")); + throw(new IllegalArgumentException("No data set was defined.")); + else if (this._attributes.size() == 0) + throw(new IllegalArgumentException("No attribute was defined.")); } /* }}} GenericJMXConfValue (OConfigItem ci) */ /** @@ -568,98 +508,90 @@ class GenericJMXConfValue * @param pd Preset naming components. The members host, plugin and * plugin instance will be used. */ - public void query (MBeanServerConnection conn, ObjectName objName, /* {{{ */ - PluginData pd) - { +public + void query(MBeanServerConnection conn, ObjectName objName, /* {{{ */ + PluginData pd) { ValueList vl; List dsrc; List values; List instanceList; String instancePrefix; - if (this._ds == null) - { - this._ds = Collectd.getDS (this._ds_name); - if (this._ds == null) - { - Collectd.logError ("GenericJMXConfValue: Unknown type: " - + this._ds_name); + if (this._ds == null) { + this._ds = Collectd.getDS(this._ds_name); + if (this._ds == null) { + Collectd.logError("GenericJMXConfValue: Unknown type: " + + this._ds_name); return; } } - dsrc = this._ds.getDataSources (); - if (dsrc.size () != this._attributes.size ()) - { - Collectd.logError ("GenericJMXConfValue.query: The data set " - + this._ds_name + " has " + this._ds.getDataSources ().size () - + " data sources, but there were " + this._attributes.size () - + " attributes configured. This doesn't match!"); + dsrc = this._ds.getDataSources(); + if (dsrc.size() != this._attributes.size()) { + Collectd.logError( + "GenericJMXConfValue.query: The data set " + 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; return; } - vl = new ValueList (pd); - vl.setType (this._ds_name); - if (this._plugin_name != null) - { - vl.setPlugin (this._plugin_name); + vl = new ValueList(pd); + vl.setType(this._ds_name); + if (this._plugin_name != null) { + vl.setPlugin(this._plugin_name); } /* * Build the instnace prefix from the fixed string prefix and the * properties of the objName. */ - instanceList = new ArrayList (); - for (int i = 0; i < this._instance_from.size (); i++) - { + instanceList = new ArrayList(); + for (int i = 0; i < this._instance_from.size(); i++) { String propertyName; String propertyValue; - propertyName = this._instance_from.get (i); - propertyValue = objName.getKeyProperty (propertyName); - if (propertyValue == null) - { - Collectd.logError ("GenericJMXConfMBean: " - + "No such property in object name: " + propertyName); - } - else - { - instanceList.add (propertyValue); + propertyName = this._instance_from.get(i); + propertyValue = objName.getKeyProperty(propertyName); + if (propertyValue == null) { + Collectd.logError("GenericJMXConfMBean: " + + "No such property in object name: " + propertyName); + } else { + instanceList.add(propertyValue); } } if (this._instance_prefix != null) - instancePrefix = new String (this._instance_prefix - + join ("-", instanceList)); + instancePrefix = + new String(this._instance_prefix + join("-", instanceList)); else - instancePrefix = join ("-", instanceList); + instancePrefix = join("-", instanceList); /* * Build a list of `Object's which is then passed to `submitTable' and * `submitScalar'. */ - values = new ArrayList (); - assert (dsrc.size () == this._attributes.size ()); - for (int i = 0; i < this._attributes.size (); i++) - { + values = new ArrayList(); + assert(dsrc.size() == this._attributes.size()); + for (int i = 0; i < this._attributes.size(); i++) { Object v; - v = queryAttribute (conn, objName, this._attributes.get (i)); - if (v == null) - { - Collectd.logError ("GenericJMXConfValue.query: " - + "Querying attribute " + this._attributes.get (i) + " failed."); + v = queryAttribute(conn, objName, this._attributes.get(i)); + if (v == null) { + Collectd.logError( + "GenericJMXConfValue.query: " + "Querying attribute " + + this._attributes.get(i) + " failed."); return; } - values.add (v); + values.add(v); } if (this._is_table) - submitTable (values, vl, instancePrefix); + submitTable(values, vl, instancePrefix); else - submitScalar (values, vl, instancePrefix); + submitScalar(values, vl, instancePrefix); } /* }}} void query */ } /* class GenericJMXConfValue */