summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: ae736fa)
raw | patch | inline | side by side (parent: ae736fa)
author | Florian Forster <octo@leeloo.lan.home.verplant.org> | |
Sun, 22 Feb 2009 12:07:26 +0000 (13:07 +0100) | ||
committer | Florian Forster <octo@leeloo.lan.home.verplant.org> | |
Sun, 22 Feb 2009 12:07:26 +0000 (13:07 +0100) |
bindings/java/org/collectd/api/CollectdAPI.java | patch | blob | history | |
src/java.c | patch | blob | history |
diff --git a/bindings/java/org/collectd/api/CollectdAPI.java b/bindings/java/org/collectd/api/CollectdAPI.java
index 8cbefdcc0e198ded6c28f36191cda48ddd073f5b..9e76e0efb6cdd03cd3d3213f41ad46e481aba777 100644 (file)
*/
native public static int RegisterRead (String name,
CollectdReadInterface obj);
+
+ /**
+ * Java representation of collectd/src/plugin.h:plugin_register_write
+ */
+ native public static int RegisterWrite (String name,
+ CollectdWriteInterface obj);
} /* class CollectdAPI */
/* vim: set sw=2 sts=2 et fdm=marker : */
diff --git a/src/java.c b/src/java.c
index 72d3569cf8359f47a2dd46396a96e83d0724dd99..95af3d0941d29d0197c6213776a381bd693b414c 100644 (file)
--- a/src/java.c
+++ b/src/java.c
jmethodID m_config;
jmethodID m_init;
- jmethodID m_write;
jmethodID m_shutdown;
};
typedef struct java_plugin_s java_plugin_t;
*/
static void cjni_callback_info_destroy (void *arg);
static int cjni_read (user_data_t *user_data);
+static int cjni_write (const data_set_t *ds, const value_list_t *vl,
+ user_data_t *ud);
/*
* C to Java conversion functions
plugin_register_complex_read (c_name, cjni_read, &ud);
+ DEBUG ("java plugin: New read callback registered: %s", c_name);
+
(*jvm_env)->ReleaseStringUTFChars (jvm_env, o_name, c_name);
(*jvm_env)->DeleteLocalRef (jvm_env, o_read);
return (0);
} /* }}} jint cjni_api_register_read */
+static jint JNICALL cjni_api_register_write (JNIEnv *jvm_env, /* {{{ */
+ jobject this, jobject o_name, jobject o_read)
+{
+ const char *c_name;
+ user_data_t ud;
+ cjni_callback_info_t *cbi;
+
+ c_name = (*jvm_env)->GetStringUTFChars (jvm_env, o_name, 0);
+ if (c_name == NULL)
+ {
+ ERROR ("java plugin: cjni_api_register_write: GetStringUTFChars failed.");
+ return (-1);
+ }
+
+ cbi = cjni_callback_info_create (jvm_env, o_read,
+ "Write", "(Lorg/collectd/api/ValueList;)I");
+ if (cbi == NULL)
+ return (-1);
+
+ memset (&ud, 0, sizeof (ud));
+ ud.data = (void *) cbi;
+ ud.free_func = cjni_callback_info_destroy;
+
+ plugin_register_write (c_name, cjni_write, &ud);
+
+ DEBUG ("java plugin: New write callback registered: %s", c_name);
+
+ (*jvm_env)->ReleaseStringUTFChars (jvm_env, o_name, c_name);
+ (*jvm_env)->DeleteLocalRef (jvm_env, o_read);
+
+ return (0);
+} /* }}} jint cjni_api_register_write */
+
static JNINativeMethod jni_api_functions[] =
{
{ "DispatchValues",
{ "RegisterRead",
"(Ljava/lang/String;Lorg/collectd/api/CollectdReadInterface;)I",
- cjni_api_register_read }
+ cjni_api_register_read },
+
+ { "RegisterWrite",
+ "(Ljava/lang/String;Lorg/collectd/api/CollectdWriteInterface;)I",
+ cjni_api_register_write }
};
static size_t jni_api_functions_num = sizeof (jni_api_functions)
/ sizeof (jni_api_functions[0]);
jp->flags = 0;
jp->m_config = NULL;
jp->m_init = NULL;
- jp->m_write = NULL;
jp->m_shutdown = NULL;
java_plugins_num++;
return (0);
} /* }}} int cjni_config */
-static int cjni_write_one_plugin (JNIEnv *jvm_env, /* {{{ */
- java_plugin_t *jp, jobject vl_java)
-{
- int status;
-
- if ((jp == NULL)
- || ((jp->flags & CJNI_FLAG_ENABLED) == 0)
- || (jp->m_write == NULL))
- return (0);
-
- DEBUG ("java plugin: Calling: %s.Write(ValueList)", jp->class_name);
-
- status = (*jvm_env)->CallIntMethod (jvm_env, jp->object_ptr,
- jp->m_write, vl_java);
- if (status != 0)
- {
- ERROR ("java plugin: cjni_write_one_plugin: "
- "Calling `Write' on an `%s' object failed with status %i.",
- jp->class_name, status);
- return (-1);
- }
-
- return (0);
-} /* }}} int cjni_write_one_plugin */
-
static int cjni_write (const data_set_t *ds, const value_list_t *vl, /* {{{ */
- user_data_t __attribute__((unused)) *user_data)
+ user_data_t *ud)
{
JNIEnv *jvm_env;
- java_plugin_t *jp;
+ cjni_callback_info_t *cbi;
jobject vl_java;
int status;
@@ -1611,9 +1625,9 @@ static int cjni_write (const data_set_t *ds, const value_list_t *vl, /* {{{ */
return (-1);
}
- if ((user_data == NULL) || (user_data->data == NULL))
+ if ((ud == NULL) || (ud->data == NULL))
{
- ERROR ("java plugin: cjni_read: Invalid user data.");
+ ERROR ("java plugin: cjni_write: Invalid user data.");
return (-1);
}
@@ -1621,24 +1635,28 @@ static int cjni_write (const data_set_t *ds, const value_list_t *vl, /* {{{ */
if (jvm_env == NULL)
return (-1);
+ cbi = (cjni_callback_info_t *) ud->data;
+
vl_java = ctoj_value_list (jvm_env, ds, vl);
if (vl_java == NULL)
{
- ERROR ("java plugin: cjni_write_plugins: ctoj_value_list failed.");
+ ERROR ("java plugin: cjni_write: ctoj_value_list failed.");
return (-1);
}
- jp = (java_plugin_t *) user_data->data;
-
- cjni_write_one_plugin (jvm_env, jp, vl_java);
+ status = (*jvm_env)->CallIntMethod (jvm_env,
+ cbi->object, cbi->method, vl_java);
(*jvm_env)->DeleteLocalRef (jvm_env, vl_java);
status = cjni_thread_detach ();
if (status != 0)
+ {
+ ERROR ("java plugin: cjni_write: cjni_thread_detach failed.");
return (-1);
+ }
- return (0);
+ return (status);
} /* }}} int cjni_write */
static int cjni_shutdown_one_plugin (JNIEnv *jvm_env, /* {{{ */
status = (*jvm)->AttachCurrentThread (jvm, (void **) &jvm_env, &args);
if (status != 0)
{
- ERROR ("java plugin: cjni_read: AttachCurrentThread failed with status %i.",
+ ERROR ("java plugin: cjni_shutdown: AttachCurrentThread failed with status %i.",
status);
return (-1);
}
return (0);
} /* }}} int cjni_shutdown */
-static int cjni_read (user_data_t *user_data) /* {{{ */
+static int cjni_read (user_data_t *ud) /* {{{ */
{
JNIEnv *jvm_env;
cjni_callback_info_t *cbi;
return (-1);
}
- if ((user_data == NULL) || (user_data->data == NULL))
+ if ((ud == NULL) || (ud->data == NULL))
{
ERROR ("java plugin: cjni_read: Invalid user data.");
return (-1);
if (jvm_env == NULL)
return (-1);
- cbi = (cjni_callback_info_t *) user_data->data;
+ cbi = (cjni_callback_info_t *) ud->data;
status = (*jvm_env)->CallIntMethod (jvm_env, cbi->object,
cbi->method);
static int cjni_init_one_plugin (JNIEnv *jvm_env, java_plugin_t *jp) /* {{{ */
{
- char plugin_name[128];
jmethodID constructor_id;
int status;
@@ -1803,12 +1820,6 @@ static int cjni_init_one_plugin (JNIEnv *jvm_env, java_plugin_t *jp) /* {{{ */
"jp->class_name = %s; jp->m_init = %p;",
jp->class_name, (void *) jp->m_init);
- jp->m_write = (*jvm_env)->GetMethodID (jvm_env, jp->class_ptr,
- "Write", "(Lorg/collectd/api/ValueList;)I");
- DEBUG ("java plugin: cjni_init_one_plugin: "
- "jp->class_name = %s; jp->m_write = %p;",
- jp->class_name, (void *) jp->m_write);
-
jp->m_shutdown = (*jvm_env)->GetMethodID (jvm_env, jp->class_ptr,
"Shutdown", "()I");
DEBUG ("java plugin: cjni_init_one_plugin: "
@@ -1865,19 +1876,6 @@ static int cjni_init_one_plugin (JNIEnv *jvm_env, java_plugin_t *jp) /* {{{ */
}
jp->flags |= CJNI_FLAG_ENABLED;
- ssnprintf (plugin_name, sizeof (plugin_name), "java:%s", jp->class_name);
-
- if (jp->m_write != NULL)
- {
- user_data_t ud;
-
- memset (&ud, 0, sizeof (ud));
- ud.data = jp;
- ud.free_func = NULL;
-
- plugin_register_write (plugin_name, cjni_write, &ud);
- }
-
return (0);
} /* }}} int cjni_init_one_plugin */