summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 92f3813)
raw | patch | inline | side by side (parent: 92f3813)
author | Florian Forster <octo@leeloo.lan.home.verplant.org> | |
Sun, 22 Feb 2009 10:29:12 +0000 (11:29 +0100) | ||
committer | Florian Forster <octo@leeloo.lan.home.verplant.org> | |
Sun, 22 Feb 2009 10:31:49 +0000 (11:31 +0100) |
diff --git a/bindings/java/org/collectd/api/CollectdAPI.java b/bindings/java/org/collectd/api/CollectdAPI.java
index 89d9c1699cb35549da89a6abd5060c27ca00022f..167112f9cca919e0adeec95af06be5869b78a8fd 100644 (file)
package org.collectd.api;
-import java.util.List;
-import org.collectd.api.ValueList;
-import org.collectd.api.DataSource;
-
public class CollectdAPI
{
native public static int DispatchValues (ValueList vl);
- native public static List<DataSource> GetDS (String type);
+ native public static DataSet GetDS (String type);
} /* class CollectdAPI */
/* vim: set sw=2 sts=2 et fdm=marker : */
diff --git a/bindings/java/org/collectd/api/DataSet.java b/bindings/java/org/collectd/api/DataSet.java
index ff5107de7beab2db4ed6e0ea98fd9b25a27141f6..98230730280ca44426048e8fefda316ccd9e809e 100644 (file)
import java.util.List;
import java.util.ArrayList;
+/**
+ * Java representation of collectd/src/plugin.h:data_set_t structure.
+ *
+ * @author Florian Forster <octo at verplant.org>
+ */
public class DataSet
{
private String _type;
diff --git a/bindings/java/org/collectd/api/OConfigItem.java b/bindings/java/org/collectd/api/OConfigItem.java
index 781af0904b65736219815505179059fcc0b6e47f..4c6a778d0c31123a7e4d6f37daa855a4bbe27eb6 100644 (file)
import java.util.List;
import java.util.ArrayList;
+/**
+ * Java representation of collectd/src/liboconfig/oconfig.h:oconfig_item_t structure.
+ *
+ * @author Florian Forster <octo at verplant.org>
+ */
public class OConfigItem
{
private String _key = null;
diff --git a/bindings/java/org/collectd/api/OConfigValue.java b/bindings/java/org/collectd/api/OConfigValue.java
index 5b40e6668cf4963ab7c725de9014d77c16905bdf..1ebafff7a066d63942fb2db23405edc3d0fc76b7 100644 (file)
package org.collectd.api;
+/**
+ * Java representation of collectd/src/liboconfig/oconfig.h:oconfig_value_t structure.
+ *
+ * @author Florian Forster <octo at verplant.org>
+ */
public class OConfigValue
{
public static final int OCONFIG_TYPE_STRING = 0;
diff --git a/bindings/java/org/collectd/api/ValueList.java b/bindings/java/org/collectd/api/ValueList.java
index 61cfdd7954d33c01c3b2553c24fc535d3e7a7239..4ba301880390db4c22211cea61f9e98eba15f4f9 100644 (file)
*/
public class ValueList extends PluginData {
- List<Number> _values = new ArrayList<Number>();
- List<DataSource> _ds = new ArrayList<DataSource>();
+ private List<Number> _values = new ArrayList<Number>();
+ private DataSet _ds;
- long _interval;
+ private long _interval;
public ValueList() {
this((PluginData)vl);
_interval = vl._interval;
_values.addAll(vl.getValues());
- _ds.addAll(vl._ds);
+ _ds = vl._ds;
}
public List<Number> getValues() {
_values.clear ();
}
+ /**
+ * @deprecated Use {@link #getDataSet()} instead.
+ */
public List<DataSource> getDataSource() {
- if (_ds.size() > 0) {
- return _ds;
- }
- else {
+ if (_ds == null)
return null;
- }
+ return _ds.getDataSources ();
+ }
+
+ public DataSet getDataSet () {
+ return _ds;
}
- public void setDataSource(List<DataSource> ds) {
+ public void setDataSet (DataSet ds) {
_ds = ds;
}
+ /**
+ * @deprecated Use {@link #setDataSet(DataSet)} instead.
+ */
+ public void setDataSource(List<DataSource> dsrc) {
+ _ds = new DataSet (_type, dsrc);
+ }
+
public long getInterval() {
return _interval;
}
return sb.toString();
}
}
+
+/* vim: set sw=4 sts=4 et : */
diff --git a/src/java.c b/src/java.c
index e871bbfc010c4550cf6c9bf308a6425cb0fa0225..6d9b753b6625c35987709c5907eac8abbf7b5005 100644 (file)
--- a/src/java.c
+++ b/src/java.c
/* Decrease reference counter on the java.lang.String object. */
(*jvm_env)->DeleteLocalRef (jvm_env, o_string);
- DEBUG ("java plugin: ctoj_string: ->%s (%s);",
- method_name, (string != NULL) ? string : "");
-
return (0);
} /* }}} int ctoj_string */
(*jvm_env)->CallVoidMethod (jvm_env, object_ptr, m_set, value);
- DEBUG ("java plugin: ctoj_int: ->%s (%i);",
- method_name, (int) value);
-
return (0);
} /* }}} int ctoj_int */
(*jvm_env)->CallVoidMethod (jvm_env, object_ptr, m_set, value);
- DEBUG ("java plugin: ctoj_long: ->%s (%"PRIi64");",
- method_name, (int64_t) value);
-
return (0);
} /* }}} int ctoj_long */
(*jvm_env)->CallVoidMethod (jvm_env, object_ptr, m_set, value);
- DEBUG ("java plugin: ctoj_double: ->%s (%g);",
- method_name, (double) value);
-
return (0);
} /* }}} int ctoj_double */
return (o_ocitem);
} /* }}} jobject ctoj_oconfig_item */
-/* Convert a data_set_t to a java.util.List<DataSource> */
+/* Convert a data_set_t to a org.collectd.api.DataSet */
static jobject ctoj_data_set (JNIEnv *jvm_env, const data_set_t *ds) /* {{{ */
{
- jclass c_arraylist;
+ jclass c_dataset;
jmethodID m_constructor;
jmethodID m_add;
+ jobject o_type;
jobject o_dataset;
int i;
- /* Look up the java.util.ArrayList class */
- c_arraylist = (*jvm_env)->FindClass (jvm_env, "java.util.ArrayList");
- if (c_arraylist == NULL)
+ /* Look up the org.collectd.api.DataSet class */
+ c_dataset = (*jvm_env)->FindClass (jvm_env, "org.collectd.api.DataSet");
+ if (c_dataset == NULL)
{
ERROR ("java plugin: ctoj_data_set: Looking up the "
- "java.util.ArrayList class failed.");
+ "org.collectd.api.DataSet class failed.");
return (NULL);
}
- /* Search for the `ArrayList (int capacity)' constructor. */
+ /* Search for the `DataSet (String type)' constructor. */
m_constructor = (*jvm_env)->GetMethodID (jvm_env,
- c_arraylist, "<init>", "()V");
+ c_dataset, "<init>", "(Ljava.lang.String;)V");
if (m_constructor == NULL)
{
ERROR ("java plugin: ctoj_data_set: Looking up the "
- "`ArrayList (void)' constructor failed.");
+ "`DataSet (String)' constructor failed.");
return (NULL);
}
- /* Search for the `boolean add (Object element)' method. */
+ /* Search for the `void addDataSource (DataSource)' method. */
m_add = (*jvm_env)->GetMethodID (jvm_env,
- c_arraylist, "add", "(Ljava/lang/Object;)Z");
+ c_dataset, "addDataSource", "(Lorg.collectd.api.DataSource;)V");
if (m_add == NULL)
{
ERROR ("java plugin: ctoj_data_set: Looking up the "
- "`add (Object)' method failed.");
+ "`addDataSource (DataSource)' method failed.");
return (NULL);
}
- o_dataset = (*jvm_env)->NewObject (jvm_env, c_arraylist, m_constructor);
+ o_type = (*jvm_env)->NewStringUTF (jvm_env, ds->type);
+ if (o_type == NULL)
+ {
+ ERROR ("java plugin: ctoj_data_set: Creating a String object failed.");
+ return (NULL);
+ }
+
+ o_dataset = (*jvm_env)->NewObject (jvm_env,
+ c_dataset, m_constructor, o_type);
if (o_dataset == NULL)
{
- ERROR ("java plugin: ctoj_data_set: "
- "Creating an ArrayList object failed.");
+ ERROR ("java plugin: ctoj_data_set: Creating a DataSet object failed.");
+ (*jvm_env)->DeleteLocalRef (jvm_env, o_type);
return (NULL);
}
+ /* Decrease reference counter on the java.lang.String object. */
+ (*jvm_env)->DeleteLocalRef (jvm_env, o_type);
+
for (i = 0; i < ds->ds_num; i++)
{
jobject o_datasource;
- jboolean status;
o_datasource = ctoj_data_source (jvm_env, ds->ds + i);
if (o_datasource == NULL)
return (NULL);
}
- status = (*jvm_env)->CallBooleanMethod (jvm_env,
- o_dataset, m_add, o_datasource);
- if (!status)
- {
- ERROR ("java plugin: ctoj_data_set: ArrayList.add returned FALSE.");
- (*jvm_env)->DeleteLocalRef (jvm_env, o_datasource);
- (*jvm_env)->DeleteLocalRef (jvm_env, o_dataset);
- return (NULL);
- }
+ (*jvm_env)->CallVoidMethod (jvm_env, o_dataset, m_add, o_datasource);
(*jvm_env)->DeleteLocalRef (jvm_env, o_datasource);
} /* for (i = 0; i < ds->ds_num; i++) */
static int ctoj_value_list_add_data_set (JNIEnv *jvm_env, /* {{{ */
jclass c_valuelist, jobject o_valuelist, const data_set_t *ds)
{
- jmethodID m_setdatasource;
+ jmethodID m_setdataset;
jobject o_dataset;
/* Look for the `void setDataSource (List<DataSource> ds)' method. */
- m_setdatasource = (*jvm_env)->GetMethodID (jvm_env, c_valuelist,
- "setDataSource", "(Ljava/util/List;)V");
- if (m_setdatasource == NULL)
+ m_setdataset = (*jvm_env)->GetMethodID (jvm_env, c_valuelist,
+ "setDataSet", "(Lorg.collectd.api.DataSet;)V");
+ if (m_setdataset == NULL)
{
ERROR ("java plugin: ctoj_value_list_add_data_set: "
- "Cannot find the `void setDataSource (List<DataSource> ds)' method.");
+ "Cannot find the `void setDataSet (DataSet)' method.");
return (-1);
}
- /* Create a List<DataSource> object. */
+ /* Create a DataSet object. */
o_dataset = ctoj_data_set (jvm_env, ds);
if (o_dataset == NULL)
{
/* Actually call the method. */
(*jvm_env)->CallVoidMethod (jvm_env,
- o_valuelist, m_setdatasource, o_dataset);
+ o_valuelist, m_setdataset, o_dataset);
/* Decrease reference counter on the List<DataSource> object. */
(*jvm_env)->DeleteLocalRef (jvm_env, o_dataset);
return (-1);
}
- DEBUG ("java plugin: jtoc_string: ->%s() = %s", method_name, c_str);
-
sstrncpy (buffer, c_str, buffer_size);
(*jvm_env)->ReleaseStringUTFChars (jvm_env, string_obj, c_str);
*ret_value = (*jvm_env)->CallLongMethod (jvm_env, object_ptr, method_id);
- DEBUG ("java plugin: jtoc_long: ->%s() = %li",
- method_name, (long int) *ret_value);
-
return (0);
} /* }}} int jtoc_long */
*ret_value = (*jvm_env)->CallDoubleMethod (jvm_env, object_ptr, method_id);
- DEBUG ("java plugin: jtoc_double: ->%s() = %g",
- method_name, (double) *ret_value);
-
return (0);
} /* }}} int jtoc_double */
static JNINativeMethod jni_api_functions[] =
{
{ "DispatchValues", "(Lorg/collectd/api/ValueList;)I", cjni_api_dispatch_values },
- { "GetDS", "(Ljava/lang/String;)Ljava/util/List;", cjni_api_get_ds }
+ { "GetDS", "(Ljava/lang/String;)Lorg/collectd/api/DataSet;", cjni_api_get_ds }
};
static size_t jni_api_functions_num = sizeof (jni_api_functions)
/ sizeof (jni_api_functions[0]);