*/
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
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
*/
native public static int dispatchValues (ValueList vl);
--- /dev/null
+/*
+ * 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);
+}
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>)
#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 },
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);
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. */