summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 6e50de5)
raw | patch | inline | side by side (parent: 6e50de5)
author | Florian Forster <octo@leeloo.lan.home.verplant.org> | |
Sun, 22 Feb 2009 21:15:47 +0000 (22:15 +0100) | ||
committer | Florian Forster <octo@leeloo.lan.home.verplant.org> | |
Sun, 22 Feb 2009 21:15:47 +0000 (22:15 +0100) |
bindings/java/org/collectd/api/Collectd.java | patch | blob | history | |
bindings/java/org/collectd/api/CollectdFlushInterface.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 70629595c4c89014ce66d6bfb21c27621b3dd3eb..3950b220642b27972139b015f8fd5d01a2231f21 100644 (file)
native public static int registerWrite (String name,
CollectdWriteInterface object);
+ /**
+ * Java representation of collectd/src/plugin.h:plugin_register_flush
+ */
+ native public static int registerFlush (String name,
+ CollectdFlushInterface object);
+
/**
* Java representation of collectd/src/plugin.h:plugin_register_shutdown
*/
diff --git a/bindings/java/org/collectd/api/CollectdFlushInterface.java b/bindings/java/org/collectd/api/CollectdFlushInterface.java
--- /dev/null
@@ -0,0 +1,27 @@
+/*
+ * collectd/java - org/collectd/api/CollectdFlushInterface.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 CollectdFlushInterface
+{
+ public int flush (int timeout, String identifier);
+}
diff --git a/src/collectd-java.pod b/src/collectd-java.pod
index 9326cb00c83acc02e5a3eba45b76c644f86db17a..c4f4ef7f2a4ca1c7f3146d2d5334589f82c85ca6 100644 (file)
--- a/src/collectd-java.pod
+++ b/src/collectd-java.pod
Interface: B<org.collectd.api.CollectdConfigInterface>
-Signature: I<int> B<config> (I<OConfigItem>)
+Signature: I<int> B<config> (I<OConfigItem> ci)
This method is passed a B<OConfigItem> object, if both, method and
configuration, are available. B<OConfigItem> is the root of a tree representing
Interface: B<org.collectd.api.CollectdWriteInterface>
-Signature: I<int> B<write> (I<ValueList>)
+Signature: I<int> B<write> (I<ValueList> vl)
This method is called whenever a value is dispatched to the daemon. The
corresponding C "write"-functions are passed a C<data_set_t>, so they can
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 flush callback
+
+Interface: B<org.collectd.api.CollectdFlushInterface>
+
+Signature: I<int> B<flush> (I<int> timeout, I<String> identifier)
+
+This method is called when the daemon received a flush command. This can either
+be done using the C<USR1> signal (see L<collectd(1)>) or using the I<unixsock>
+plugin (see L<collectd-unixsock(1)>).
+
+If I<timeout> is greater than zero, only values older than this number of
+seconds should be flushed. To signal that all values should be flushed
+regardless of age, this argument is set to a negative number.
+
+The I<identifier> specifies which value should be flushed. If it is not
+possible to flush one specific value, flush all values. To signal that all
+values should be flushed, this argument is set to I<null>.
+
+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 shutdown callback
Interface: B<org.collectd.api.CollectdShutdownInterface>
Returns zero upon success and non-zero when an error occurred.
+=head2 registerFlush
+
+Signature: I<int> B<registerFlush> (I<String> name,
+I<CollectdFlushInterface> object)
+
+Registers the B<flush> function of I<object> with the daemon.
+
+Returns zero upon success and non-zero when an error occurred.
+
=head2 registerShutdown
Signature: I<int> B<registerShutdown> (I<String> name,
diff --git a/src/java.c b/src/java.c
index 984d29a4c20d6da55315bf6bcf7bd28bef413d51..39311c8b7f1365733c21bf042ad23ebb4298483a 100644 (file)
--- a/src/java.c
+++ b/src/java.c
#define CB_TYPE_INIT 2
#define CB_TYPE_READ 3
#define CB_TYPE_WRITE 4
-#define CB_TYPE_SHUTDOWN 5
+#define CB_TYPE_FLUSH 5
+#define CB_TYPE_SHUTDOWN 6
struct cjni_callback_info_s /* {{{ */
{
char *name;
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);
+static int cjni_flush (int timeout, const char *identifier, user_data_t *ud);
/*
* C to Java conversion functions
return (0);
} /* }}} jint cjni_api_register_write */
+static jint JNICALL cjni_api_register_flush (JNIEnv *jvm_env, /* {{{ */
+ jobject this, jobject o_name, jobject o_flush)
+{
+ user_data_t ud;
+ cjni_callback_info_t *cbi;
+
+ cbi = cjni_callback_info_create (jvm_env, o_name, o_flush, CB_TYPE_FLUSH);
+ if (cbi == NULL)
+ return (-1);
+
+ DEBUG ("java plugin: Registering new flush callback: %s", cbi->name);
+
+ memset (&ud, 0, sizeof (ud));
+ ud.data = (void *) cbi;
+ ud.free_func = cjni_callback_info_destroy;
+
+ plugin_register_flush (cbi->name, cjni_flush, &ud);
+
+ (*jvm_env)->DeleteLocalRef (jvm_env, o_flush);
+
+ return (0);
+} /* }}} jint cjni_api_register_flush */
+
static jint JNICALL cjni_api_register_shutdown (JNIEnv *jvm_env, /* {{{ */
jobject this, jobject o_name, jobject o_shutdown)
{
"(Ljava/lang/String;Lorg/collectd/api/CollectdWriteInterface;)I",
cjni_api_register_write },
+ { "registerFlush",
+ "(Ljava/lang/String;Lorg/collectd/api/CollectdFlushInterface;)I",
+ cjni_api_register_flush },
+
{ "registerShutdown",
"(Ljava/lang/String;Lorg/collectd/api/CollectdShutdownInterface;)I",
cjni_api_register_shutdown },
@@ -1351,6 +1380,11 @@ static cjni_callback_info_t *cjni_callback_info_create (JNIEnv *jvm_env, /* {{{
method_signature = "(Lorg/collectd/api/ValueList;)I";
break;
+ case CB_TYPE_FLUSH:
+ method_name = "flush";
+ method_signature = "(ILjava/lang/String;)I";
+ break;
+
case CB_TYPE_SHUTDOWN:
method_name = "shutdown";
method_signature = "()I";
@@ -1907,6 +1941,59 @@ 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. */
+static int cjni_flush (int timeout, const char *identifier, /* {{{ */
+ user_data_t *ud)
+{
+ JNIEnv *jvm_env;
+ cjni_callback_info_t *cbi;
+ jobject o_identifier;
+ int status;
+
+ if (jvm == NULL)
+ {
+ ERROR ("java plugin: cjni_flush: jvm == NULL");
+ return (-1);
+ }
+
+ if ((ud == NULL) || (ud->data == NULL))
+ {
+ ERROR ("java plugin: cjni_flush: Invalid user data.");
+ return (-1);
+ }
+
+ jvm_env = cjni_thread_attach ();
+ if (jvm_env == NULL)
+ return (-1);
+
+ cbi = (cjni_callback_info_t *) ud->data;
+
+ o_identifier = NULL;
+ if (identifier != NULL)
+ {
+ o_identifier = (*jvm_env)->NewStringUTF (jvm_env, identifier);
+ if (o_identifier == NULL)
+ {
+ ERROR ("java plugin: cjni_flush: NewStringUTF failed.");
+ return (-1);
+ }
+ }
+
+ status = (*jvm_env)->CallIntMethod (jvm_env,
+ cbi->object, cbi->method, (jint) timeout, o_identifier);
+
+ (*jvm_env)->DeleteLocalRef (jvm_env, o_identifier);
+
+ status = cjni_thread_detach ();
+ if (status != 0)
+ {
+ ERROR ("java plugin: cjni_flush: cjni_thread_detach failed.");
+ return (-1);
+ }
+
+ return (status);
+} /* }}} int cjni_flush */
+
/* 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. */