From: Florian Forster Date: Sat, 21 Feb 2009 10:39:25 +0000 (+0100) Subject: bindings/java: Moved the `PluginData' and `ValueList' classes. X-Git-Tag: collectd-4.7.0~127^2~39 X-Git-Url: https://git.octo.it/?p=collectd.git;a=commitdiff_plain;h=35b50aa3a8ba1b3b8abd2197a998c2622a763ac1 bindings/java: Moved the `PluginData' and `ValueList' classes. And implemented various (trivial) `Collectd*Interface' classes. --- diff --git a/bindings/java/org/collectd/api/CollectdAPI.java b/bindings/java/org/collectd/api/CollectdAPI.java index 67c8e6ad..89d9c169 100644 --- a/bindings/java/org/collectd/api/CollectdAPI.java +++ b/bindings/java/org/collectd/api/CollectdAPI.java @@ -22,8 +22,8 @@ package org.collectd.api; import java.util.List; -import org.collectd.protocol.ValueList; -import org.collectd.protocol.DataSource; +import org.collectd.api.ValueList; +import org.collectd.api.DataSource; public class CollectdAPI { diff --git a/bindings/java/org/collectd/api/CollectdConfigInterface.java b/bindings/java/org/collectd/api/CollectdConfigInterface.java new file mode 100644 index 00000000..fae4aa5a --- /dev/null +++ b/bindings/java/org/collectd/api/CollectdConfigInterface.java @@ -0,0 +1,27 @@ +/* + * collectd/java - org/collectd/api/CollectdConfigInterface.java + * Copyright (C) 2009 Florian octo Forster + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation; only version 2 of the License is applicable. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + * + * Authors: + * Florian octo Forster + */ + +package org.collectd.api; + +public interface CollectdConfigInterface +{ + int Config (OConfigItem ci); +} diff --git a/bindings/java/org/collectd/api/CollectdInitInterface.java b/bindings/java/org/collectd/api/CollectdInitInterface.java new file mode 100644 index 00000000..46379fe8 --- /dev/null +++ b/bindings/java/org/collectd/api/CollectdInitInterface.java @@ -0,0 +1,27 @@ +/* + * collectd/java - org/collectd/api/CollectdInitInterface.java + * Copyright (C) 2009 Florian octo Forster + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation; only version 2 of the License is applicable. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + * + * Authors: + * Florian octo Forster + */ + +package org.collectd.api; + +public interface CollectdInitInterface +{ + int Init (); +} diff --git a/bindings/java/org/collectd/api/CollectdReadInterface.java b/bindings/java/org/collectd/api/CollectdReadInterface.java new file mode 100644 index 00000000..6b3e1ad8 --- /dev/null +++ b/bindings/java/org/collectd/api/CollectdReadInterface.java @@ -0,0 +1,27 @@ +/* + * collectd/java - org/collectd/api/CollectdReadInterface.java + * Copyright (C) 2009 Florian octo Forster + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation; only version 2 of the License is applicable. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + * + * Authors: + * Florian octo Forster + */ + +package org.collectd.api; + +public interface CollectdReadInterface +{ + int Read (); +} diff --git a/bindings/java/org/collectd/api/CollectdShutdownInterface.java b/bindings/java/org/collectd/api/CollectdShutdownInterface.java new file mode 100644 index 00000000..909f849e --- /dev/null +++ b/bindings/java/org/collectd/api/CollectdShutdownInterface.java @@ -0,0 +1,27 @@ +/* + * collectd/java - org/collectd/api/CollectdShutdownInterface.java + * Copyright (C) 2009 Florian octo Forster + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation; only version 2 of the License is applicable. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + * + * Authors: + * Florian octo Forster + */ + +package org.collectd.api; + +public interface CollectdShutdownInterface +{ + int Shutdown (); +} diff --git a/bindings/java/org/collectd/api/CollectdWriteInterface.java b/bindings/java/org/collectd/api/CollectdWriteInterface.java new file mode 100644 index 00000000..dd76f2c0 --- /dev/null +++ b/bindings/java/org/collectd/api/CollectdWriteInterface.java @@ -0,0 +1,27 @@ +/* + * collectd/java - org/collectd/api/CollectdWriteInterface.java + * Copyright (C) 2009 Florian octo Forster + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation; only version 2 of the License is applicable. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + * + * Authors: + * Florian octo Forster + */ + +package org.collectd.api; + +public interface CollectdWriteInterface +{ + public int Write (ValueList vl); +} diff --git a/bindings/java/org/collectd/api/DataSet.java b/bindings/java/org/collectd/api/DataSet.java new file mode 100644 index 00000000..ff5107de --- /dev/null +++ b/bindings/java/org/collectd/api/DataSet.java @@ -0,0 +1,132 @@ +/* + * collectd/java - org/collectd/api/OConfigItem.java + * Copyright (C) 2009 Florian octo Forster + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation; only version 2 of the License is applicable. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + * + * Authors: + * Florian octo Forster + */ + +package org.collectd.api; + +import java.util.List; +import java.util.ArrayList; + +public class DataSet +{ + private String _type; + private List _ds; + + private DataSet () + { + this._type = null; + this._ds = new ArrayList (); + } + + public DataSet (String type) + { + this._type = type; + this._ds = new ArrayList (); + } + + public DataSet (String type, DataSource dsrc) + { + this._type = type; + this._ds = new ArrayList (); + this._ds.add (dsrc); + } + + public DataSet (String type, List ds) + { + this._type = type; + this._ds = ds; + } + + public void setType (String type) + { + this._type = type; + } + + public String getType () + { + return (this._type); + } + + public void addDataSource (DataSource dsrc) + { + this._ds.add (dsrc); + } + + public List getDataSources () + { + return (this._ds); + } + + public String toString () + { + StringBuffer sb = new StringBuffer (); + int i; + + sb.append (this._type); + for (i = 0; i < this._ds.size (); i++) + { + if (i == 0) + sb.append ("\t"); + else + sb.append (", "); + sb.append (this._ds.get (i).toString ()); + } + + return (sb.toString ()); + } + + static public DataSet parseDataSet (String str) + { + DataSet ds = new DataSet (); + String[] fields; + int i; + + str = str.trim(); + if (str.length() == 0) { + return (null); + } + if (str.charAt(0) == '#') { + return (null); + } + + fields = str.split ("\\s+"); + if (fields.length < 2) + return (null); + + ds._type = fields[0]; + + for (i = 1; i < fields.length; i++) { + DataSource dsrc; + + dsrc = DataSource.parseDataSource (fields[i]); + if (dsrc == null) + break; + + ds._ds.add (dsrc); + } + + if (i < fields.length) + return (null); + + return (ds); + } /* DataSet parseDataSet */ +} /* class DataSet */ + +/* vim: set sw=4 sts=4 et : */ diff --git a/bindings/java/org/collectd/api/DataSource.java b/bindings/java/org/collectd/api/DataSource.java new file mode 100644 index 00000000..bfe8e2d0 --- /dev/null +++ b/bindings/java/org/collectd/api/DataSource.java @@ -0,0 +1,145 @@ +/* + * jcollectd + * Copyright (C) 2009 Hyperic, Inc. + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation; only version 2 of the License is applicable. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ + +package org.collectd.api; + +/** + * Java representation of collectd/src/plugin.h:data_source_t structure. + */ +public class DataSource { + public static final int TYPE_COUNTER = 0; + public static final int TYPE_GAUGE = 1; + + static final String COUNTER = "COUNTER"; + static final String GAUGE = "GAUGE"; + + static final String NAN = "U"; + private static final String[] TYPES = { COUNTER, GAUGE }; + + String _name; + int _type; + double _min; + double _max; + + public DataSource (String name, int type, double min, double max) { + this._name = name; + this._type = TYPE_GAUGE; + if (type == TYPE_COUNTER) + this._type = TYPE_COUNTER; + this._min = min; + this._max = max; + } + + /* Needed in parseDataSource below. Other code should use the above + * constructor or `parseDataSource'. */ + private DataSource () { + this._type = TYPE_GAUGE; + } + + public String getName() { + return _name; + } + + public void setName(String name) { + _name = name; + } + + public int getType() { + return _type; + } + + public void setType(int type) { + _type = type; + } + + public double getMin() { + return _min; + } + + public void setMin(double min) { + _min = min; + } + + public double getMax() { + return _max; + } + + public void setMax(double max) { + _max = max; + } + + static double toDouble(String val) { + if (val.equals(NAN)) { + return Double.NaN; + } + else { + return Double.parseDouble(val); + } + } + + private String asString(double val) { + if (Double.isNaN(val)) { + return NAN; + } + else { + return String.valueOf(val); + } + } + + public String toString() { + StringBuffer sb = new StringBuffer(); + final char DLM = ':'; + sb.append(_name).append(DLM); + sb.append(TYPES[_type]).append(DLM); + sb.append(asString(_min)).append(DLM); + sb.append(asString(_max)); + return sb.toString(); + } + + static public DataSource parseDataSource (String str) + { + String[] fields; + int str_len = str.length (); + DataSource dsrc = new DataSource (); + + /* Ignore trailing commas. This makes it easier for parsing code. */ + if (str.charAt (str_len - 1) == ',') { + str = str.substring (0, str_len - 1); + } + + fields = str.split(":"); + if (fields.length != 4) + return (null); + + dsrc._name = fields[0]; + + if (fields[1].equals (DataSource.GAUGE)) { + dsrc._type = TYPE_GAUGE; + } + else { + dsrc._type = TYPE_COUNTER; + } + + dsrc._min = toDouble (fields[2]); + dsrc._max = toDouble (fields[3]); + + return (dsrc); + } /* DataSource parseDataSource */ +} + +/* vim: set sw=4 sts=4 et : */ diff --git a/bindings/java/org/collectd/api/Notification.java b/bindings/java/org/collectd/api/Notification.java new file mode 100644 index 00000000..cd2fed58 --- /dev/null +++ b/bindings/java/org/collectd/api/Notification.java @@ -0,0 +1,81 @@ +/* + * jcollectd + * Copyright (C) 2009 Hyperic, Inc. + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation; only version 2 of the License is applicable. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ + +package org.collectd.api; + +/** + * Java representation of collectd/src/plugin.h:notfication_t structure. + */ +public class Notification extends PluginData { + public static final int FAILURE = 1; + public static final int WARNING = 2; + public static final int OKAY = 4; + + public static String[] SEVERITY = { + "FAILURE", + "WARNING", + "OKAY", + "UNKNOWN" + }; + + private int _severity; + private String _message; + + public Notification (PluginData pd) { + super (pd); + } + + public void setSeverity (int severity) { + if ((severity == FAILURE) + || (severity == WARNING) + || (severity == OKAY)) + this._severity = severity; + } + + public int getSeverity() { + return _severity; + } + + public String getSeverityString() { + switch (_severity) { + case FAILURE: + return SEVERITY[0]; + case WARNING: + return SEVERITY[1]; + case OKAY: + return SEVERITY[2]; + default: + return SEVERITY[3]; + } + } + + public void setMessage (String message) { + this._message = message; + } + + public String getMessage() { + return _message; + } + + public String toString() { + StringBuffer sb = new StringBuffer(super.toString()); + sb.append(" [").append(getSeverityString()).append("] "); + sb.append(_message); + return sb.toString(); + } +} diff --git a/bindings/java/org/collectd/api/PluginData.java b/bindings/java/org/collectd/api/PluginData.java new file mode 100644 index 00000000..45cd8362 --- /dev/null +++ b/bindings/java/org/collectd/api/PluginData.java @@ -0,0 +1,127 @@ +/* + * jcollectd + * Copyright (C) 2009 Hyperic, Inc. + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation; only version 2 of the License is applicable. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ + +package org.collectd.api; + +import java.util.Date; + +/** + * Shared members of value_list_t and notification_t structures. + */ +public class PluginData { + + protected long _time; + protected String _host; + protected String _plugin; + protected String _pluginInstance = ""; + protected String _type = ""; + protected String _typeInstance = ""; + + public PluginData() { + + } + + public PluginData(PluginData pd) { + _time = pd._time; + _host = pd._host; + _plugin = pd._plugin; + _pluginInstance = pd._pluginInstance; + _type = pd._type; + _typeInstance = pd._typeInstance; + } + + public long getTime() { + return _time; + } + + public void setTime(long time) { + _time = time; + } + + public String getHost() { + return _host; + } + + public void setHost(String host) { + _host = host; + } + + public String getPlugin() { + return _plugin; + } + + public void setPlugin(String plugin) { + _plugin = plugin; + } + + public String getPluginInstance() { + return _pluginInstance; + } + + public void setPluginInstance(String pluginInstance) { + _pluginInstance = pluginInstance; + } + + public String getType() { + return _type; + } + + public void setType(String type) { + _type = type; + } + + public String getTypeInstance() { + return _typeInstance; + } + + public void setTypeInstance(String typeInstance) { + _typeInstance = typeInstance; + } + + public boolean defined(String val) { + return (val != null) && (val.length() > 0); + } + + public String getSource() { + final char DLM = '/'; + StringBuffer sb = new StringBuffer(); + if (defined(_host)) { + sb.append(_host); + } + if (defined(_plugin)) { + sb.append(DLM).append(_plugin); + } + if (defined(_pluginInstance)) { + sb.append(DLM).append(_pluginInstance); + } + if (defined(_type)) { + sb.append(DLM).append(_type); + } + if (defined(_typeInstance)) { + sb.append(DLM).append(_typeInstance); + } + return sb.toString(); + } + + public String toString() { + StringBuffer sb = new StringBuffer(); + sb.append('[').append(new Date(_time)).append("] "); + sb.append(getSource()); + return sb.toString(); + } +} diff --git a/bindings/java/org/collectd/api/ValueList.java b/bindings/java/org/collectd/api/ValueList.java new file mode 100644 index 00000000..61cfdd79 --- /dev/null +++ b/bindings/java/org/collectd/api/ValueList.java @@ -0,0 +1,109 @@ +/* + * jcollectd + * Copyright (C) 2009 Hyperic, Inc. + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation; only version 2 of the License is applicable. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ + +package org.collectd.api; + +import java.util.ArrayList; +import java.util.List; + +/** + * Java representation of collectd/src/plugin.h:value_list_t structure. + */ +public class ValueList extends PluginData { + + List _values = new ArrayList(); + List _ds = new ArrayList(); + + long _interval; + + public ValueList() { + + } + + public ValueList(PluginData pd) { + super(pd); + } + + public ValueList(ValueList vl) { + this((PluginData)vl); + _interval = vl._interval; + _values.addAll(vl.getValues()); + _ds.addAll(vl._ds); + } + + public List getValues() { + return _values; + } + + public void setValues(List values) { + _values = values; + } + + public void addValue(Number value) { + _values.add(value); + } + + /* Used by the network parsing code */ + public void clearValues () { + _values.clear (); + } + + public List getDataSource() { + if (_ds.size() > 0) { + return _ds; + } + else { + return null; + } + } + + public void setDataSource(List ds) { + _ds = ds; + } + + public long getInterval() { + return _interval; + } + + public void setInterval(long interval) { + _interval = interval; + } + + public String toString() { + StringBuffer sb = new StringBuffer(super.toString()); + sb.append("=["); + List ds = getDataSource(); + int size = _values.size(); + for (int i=0; i 0); - } - - public String getSource() { - final char DLM = '/'; - StringBuffer sb = new StringBuffer(); - if (defined(_host)) { - sb.append(_host); - } - if (defined(_plugin)) { - sb.append(DLM).append(_plugin); - } - if (defined(_pluginInstance)) { - sb.append(DLM).append(_pluginInstance); - } - if (defined(_type)) { - sb.append(DLM).append(_type); - } - if (defined(_typeInstance)) { - sb.append(DLM).append(_typeInstance); - } - return sb.toString(); - } - - public String toString() { - StringBuffer sb = new StringBuffer(); - sb.append('[').append(new Date(_time)).append("] "); - sb.append(getSource()); - return sb.toString(); - } -} diff --git a/bindings/java/org/collectd/protocol/ValueList.java b/bindings/java/org/collectd/protocol/ValueList.java deleted file mode 100644 index 7ae2d3dc..00000000 --- a/bindings/java/org/collectd/protocol/ValueList.java +++ /dev/null @@ -1,105 +0,0 @@ -/* - * jcollectd - * Copyright (C) 2009 Hyperic, Inc. - * - * This program is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License as published by the - * Free Software Foundation; only version 2 of the License is applicable. - * - * This program is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - */ - -package org.collectd.protocol; - -import java.util.ArrayList; -import java.util.List; - -/** - * Java representation of collectd/src/plugin.h:value_list_t structure. - */ -public class ValueList extends PluginData { - - List _values = new ArrayList(); - List _ds = new ArrayList(); - - long _interval; - - public ValueList() { - - } - - public ValueList(PluginData pd) { - super(pd); - } - - public ValueList(ValueList vl) { - this((PluginData)vl); - _interval = vl._interval; - _values.addAll(vl.getValues()); - _ds.addAll(vl._ds); - } - - public List getValues() { - return _values; - } - - public void setValues(List values) { - _values = values; - } - - public void addValue(Number value) { - _values.add(value); - } - - public List getDataSource() { - if (_ds.size() > 0) { - return _ds; - } - else { - TypesDB db = TypesDB.getInstance(); - return db.getType(_type); - } - } - - public void setDataSource(List ds) { - _ds = ds; - } - - public long getInterval() { - return _interval; - } - - public void setInterval(long interval) { - _interval = interval; - } - - public String toString() { - StringBuffer sb = new StringBuffer(super.toString()); - sb.append("=["); - List ds = getDataSource(); - int size = _values.size(); - for (int i=0; i