summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 3f9f3d0)
raw | patch | inline | side by side (parent: 3f9f3d0)
author | Florian Forster <octo@leeloo.lan.home.verplant.org> | |
Sun, 22 Feb 2009 22:18:43 +0000 (23:18 +0100) | ||
committer | Florian Forster <octo@leeloo.lan.home.verplant.org> | |
Sun, 22 Feb 2009 22:18:43 +0000 (23:18 +0100) |
bindings/java/org/collectd/api/Collectd.java | patch | blob | history | |
bindings/java/org/collectd/api/CollectdLogInterface.java | [new file with mode: 0644] | patch | blob |
src/collectd-java.pod | patch | blob | history | |
src/java.c | patch | blob | history |
diff --git a/bindings/java/org/collectd/api/Collectd.java b/bindings/java/org/collectd/api/Collectd.java
index 3950b220642b27972139b015f8fd5d01a2231f21..eb96969a5c7161fec6bd4a379f6484fee95ff5c0 100644 (file)
*/
public class Collectd
{
- private static final int LOG_ERR = 3;
- private static final int LOG_WARNING = 4;
- private static final int LOG_NOTICE = 5;
- private static final int LOG_INFO = 6;
- private static final int LOG_DEBUG = 7;
+ public static final int LOG_ERR = 3;
+ public static final int LOG_WARNING = 4;
+ public static final int LOG_NOTICE = 5;
+ public static final int LOG_INFO = 6;
+ public static final int LOG_DEBUG = 7;
/**
* Java representation of collectd/src/plugin.h:plugin_register_config
native public static int registerShutdown (String name,
CollectdShutdownInterface object);
+ /**
+ * Java representation of collectd/src/plugin.h:plugin_register_log
+ */
+ native public static int registerLog (String name,
+ CollectdLogInterface object);
+
/**
* Java representation of collectd/src/plugin.h:plugin_dispatch_values
*/
diff --git a/bindings/java/org/collectd/api/CollectdLogInterface.java b/bindings/java/org/collectd/api/CollectdLogInterface.java
--- /dev/null
@@ -0,0 +1,27 @@
+/*
+ * collectd/java - org/collectd/api/CollectdLogInterface.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 <octo at verplant.org>
+ */
+
+package org.collectd.api;
+
+public interface CollectdLogInterface
+{
+ public void log (int severity, String message);
+}
diff --git a/src/collectd-java.pod b/src/collectd-java.pod
index c4f4ef7f2a4ca1c7f3146d2d5334589f82c85ca6..14e542d89d68dbb15a660eef3083132f24b0603b 100644 (file)
--- a/src/collectd-java.pod
+++ b/src/collectd-java.pod
To signal success, this method has to return zero. Anything else will be
considered an error condition and cause an appropriate message to be logged.
+=head2 log callback
+
+Interface: B<org.collectd.api.CollectdLogInterface>
+
+Signature: I<void> B<log> (I<int> severity, I<String> message)
+
+This callback can be used to receive log messages from the daemon.
+
+The argument I<severity> is one of:
+
+=over 4
+
+=item *
+
+org.collectd.api.Collectd.LOG_ERR
+
+=item *
+
+org.collectd.api.Collectd.LOG_WARNING
+
+=item *
+
+org.collectd.api.Collectd.LOG_NOTICE
+
+=item *
+
+org.collectd.api.Collectd.LOG_INFO
+
+=item *
+
+org.collectd.api.Collectd.LOG_DEBUG
+
+=back
+
+The function does not return any value.
+
=head2 Example
This short example demonstrates how to register a read callback with the
Returns zero upon success and non-zero when an error occurred.
+=head2 registerLog
+
+Signature: I<int> B<registerLog> (I<String> name,
+I<CollectdLogInterface> object);
+
+Registers the B<log> function of I<object> with the daemon.
+
+Returns zero upon success and non-zero when an error occurred.
+
=head2 dispatchValues
Signature: I<int> B<dispatchValues> (I<ValueList>)
diff --git a/src/java.c b/src/java.c
index 39311c8b7f1365733c21bf042ad23ebb4298483a..fc332e50587bc25be8cad182831e3f059ac7733c 100644 (file)
--- a/src/java.c
+++ b/src/java.c
#define CB_TYPE_WRITE 4
#define CB_TYPE_FLUSH 5
#define CB_TYPE_SHUTDOWN 6
+#define CB_TYPE_LOG 7
struct cjni_callback_info_s /* {{{ */
{
char *name;
static int cjni_write (const data_set_t *ds, const value_list_t *vl,
user_data_t *ud);
static int cjni_flush (int timeout, const char *identifier, user_data_t *ud);
+static void cjni_log (int severity, const char *message, user_data_t *ud);
/*
* C to Java conversion functions
CB_TYPE_SHUTDOWN));
} /* }}} jint cjni_api_register_shutdown */
+static jint JNICALL cjni_api_register_log (JNIEnv *jvm_env, /* {{{ */
+ jobject this, jobject o_name, jobject o_log)
+{
+ user_data_t ud;
+ cjni_callback_info_t *cbi;
+
+ cbi = cjni_callback_info_create (jvm_env, o_name, o_log, CB_TYPE_LOG);
+ if (cbi == NULL)
+ return (-1);
+
+ DEBUG ("java plugin: Registering new log callback: %s", cbi->name);
+
+ memset (&ud, 0, sizeof (ud));
+ ud.data = (void *) cbi;
+ ud.free_func = cjni_callback_info_destroy;
+
+ plugin_register_log (cbi->name, cjni_log, &ud);
+
+ (*jvm_env)->DeleteLocalRef (jvm_env, o_log);
+
+ return (0);
+} /* }}} jint cjni_api_register_log */
+
static void JNICALL cjni_api_log (JNIEnv *jvm_env, /* {{{ */
jobject this, jint severity, jobject o_message)
{
"(Ljava/lang/String;Lorg/collectd/api/CollectdShutdownInterface;)I",
cjni_api_register_shutdown },
+ { "registerLog",
+ "(Ljava/lang/String;Lorg/collectd/api/CollectdLogInterface;)I",
+ cjni_api_register_log },
+
{ "log",
"(ILjava/lang/String;)V",
cjni_api_log },
@@ -1390,6 +1419,11 @@ static cjni_callback_info_t *cjni_callback_info_create (JNIEnv *jvm_env, /* {{{
method_signature = "()I";
break;
+ case CB_TYPE_LOG:
+ method_name = "log";
+ method_signature = "(ILjava/lang/String;)V";
+ break;
+
default:
ERROR ("java plugin: cjni_callback_info_create: Unknown type: %#x",
type);
@@ -1941,7 +1975,7 @@ static int cjni_write (const data_set_t *ds, const value_list_t *vl, /* {{{ */
return (status);
} /* }}} int cjni_write */
-/* Call the CB_TYPE_WRITE callback pointed to by the `user_data_t' pointer. */
+/* Call the CB_TYPE_FLUSH callback pointed to by the `user_data_t' pointer. */
static int cjni_flush (int timeout, const char *identifier, /* {{{ */
user_data_t *ud)
{
return (status);
} /* }}} int cjni_flush */
+/* Call the CB_TYPE_LOG callback pointed to by the `user_data_t' pointer. */
+static void cjni_log (int severity, const char *message, /* {{{ */
+ user_data_t *ud)
+{
+ JNIEnv *jvm_env;
+ cjni_callback_info_t *cbi;
+ jobject o_message;
+
+ if (jvm == NULL)
+ return;
+
+ if ((ud == NULL) || (ud->data == NULL))
+ return;
+
+ jvm_env = cjni_thread_attach ();
+ if (jvm_env == NULL)
+ return;
+
+ cbi = (cjni_callback_info_t *) ud->data;
+
+ o_message = (*jvm_env)->NewStringUTF (jvm_env, message);
+ if (o_message == NULL)
+ return;
+
+ (*jvm_env)->CallVoidMethod (jvm_env,
+ cbi->object, cbi->method, (jint) severity, o_message);
+
+ (*jvm_env)->DeleteLocalRef (jvm_env, o_message);
+
+ cjni_thread_detach ();
+} /* }}} int cjni_log */
+
/* Iterate over `java_classes_list' and create one object of each class. This
* will trigger the object's constructors, to the objects can register callback
* methods. */