* 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
* Authors:
- * Florian octo Forster <octo at verplant.org>
+ * Florian octo Forster <octo at collectd.org>
* Justo Alonso Achaques <justo.alonso at gmail.com>
**/
static int cjni_match_target_invoke (const data_set_t *ds, value_list_t *vl,
notification_meta_t **meta, void **user_data);
-/*
+/*
* C to Java conversion functions
*/
static int ctoj_string (JNIEnv *jvm_env, /* {{{ */
return (0);
} /* }}} int ctoj_string */
+static jstring ctoj_output_string (JNIEnv *jvm_env, /* {{{ */
+ const char *string)
+{
+ jstring o_string;
+
+ /* Create a java.lang.String */
+ o_string = (*jvm_env)->NewStringUTF (jvm_env,
+ (string != NULL) ? string : "");
+ if (o_string == NULL)
+ {
+ ERROR ("java plugin: ctoj_output_string: NewStringUTF failed.");
+ return NULL;
+ }
+
+ return (o_string);
+} /* }}} int ctoj_output_string */
+
static int ctoj_int (JNIEnv *jvm_env, /* {{{ */
jint value,
jclass class_ptr, jobject object_ptr, const char *method_name)
return (0);
} /* }}} int jtoc_notification */
-/*
+/*
* Functions accessible from Java
*/
static jint JNICALL cjni_api_dispatch_values (JNIEnv *jvm_env, /* {{{ */
(*jvm_env)->ReleaseStringUTFChars (jvm_env, o_message, c_str);
} /* }}} void cjni_api_log */
+static jstring JNICALL cjni_api_get_hostname (JNIEnv *jvm_env, jobject this)
+{
+ return ctoj_output_string(jvm_env, hostname_g);
+}
+
/* List of ``native'' functions, i. e. C-functions that can be called from
* Java. */
static JNINativeMethod jni_api_functions[] = /* {{{ */
{ "log",
"(ILjava/lang/String;)V",
cjni_api_log },
+
+ { "getHostname",
+ "()Ljava/lang/String;",
+ cjni_api_get_hostname },
+
};
static size_t jni_api_functions_num = sizeof (jni_api_functions)
/ sizeof (jni_api_functions[0]);
pthread_mutex_unlock (&java_callbacks_lock);
ERROR ("java plugin: cjni_callback_info_create: strdup failed.");
(*jvm_env)->ReleaseStringUTFChars (jvm_env, o_name, c_name);
+ sfree (cbi);
return (NULL);
}
if (cbi->object == NULL)
{
ERROR ("java plugin: cjni_callback_info_create: NewGlobalRef failed.");
- free (cbi);
+ sfree (cbi->name);
+ sfree (cbi);
return (NULL);
}
if (cbi->class == NULL)
{
ERROR ("java plugin: cjni_callback_info_create: GetObjectClass failed.");
- free (cbi);
+ (*jvm_env)->DeleteGlobalRef (jvm_env, cbi->object);
+ sfree (cbi->name);
+ sfree (cbi);
return (NULL);
}
ERROR ("java plugin: cjni_callback_info_create: "
"Cannot find the `%s' method with signature `%s'.",
method_name, method_signature);
- free (cbi);
+ (*jvm_env)->DeleteGlobalRef (jvm_env, cbi->object);
+ sfree (cbi->name);
+ sfree (cbi);
return (NULL);
}
cjni_env->jvm_env = NULL;
return (0);
-} /* }}} JNIEnv *cjni_thread_attach */
+} /* }}} int cjni_thread_detach */
static int cjni_config_add_jvm_arg (oconfig_item_t *ci) /* {{{ */
{
{
JNIEnv *jvm_env;
cjni_callback_info_t *cbi;
- int status;
int ret_status;
if (jvm == NULL)
ret_status = (*jvm_env)->CallIntMethod (jvm_env, cbi->object,
cbi->method);
- status = cjni_thread_detach ();
- if (status != 0)
- {
- ERROR ("java plugin: cjni_read: cjni_thread_detach failed.");
- return (-1);
- }
-
+ cjni_thread_detach ();
return (ret_status);
} /* }}} int cjni_read */
JNIEnv *jvm_env;
cjni_callback_info_t *cbi;
jobject vl_java;
- int status;
int ret_status;
if (jvm == NULL)
if (vl_java == NULL)
{
ERROR ("java plugin: cjni_write: ctoj_value_list failed.");
+ cjni_thread_detach ();
return (-1);
}
(*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);
- }
-
+ cjni_thread_detach ();
return (ret_status);
} /* }}} int cjni_write */
cjni_callback_info_t *cbi;
jobject o_timeout;
jobject o_identifier;
- int status;
int ret_status;
if (jvm == NULL)
{
ERROR ("java plugin: cjni_flush: Converting double "
"to Number object failed.");
+ cjni_thread_detach ();
return (-1);
}
{
(*jvm_env)->DeleteLocalRef (jvm_env, o_timeout);
ERROR ("java plugin: cjni_flush: NewStringUTF failed.");
+ cjni_thread_detach ();
return (-1);
}
}
(*jvm_env)->DeleteLocalRef (jvm_env, o_identifier);
(*jvm_env)->DeleteLocalRef (jvm_env, o_timeout);
- status = cjni_thread_detach ();
- if (status != 0)
- {
- ERROR ("java plugin: cjni_flush: cjni_thread_detach failed.");
- return (-1);
- }
-
+ cjni_thread_detach ();
return (ret_status);
} /* }}} int cjni_flush */
o_message = (*jvm_env)->NewStringUTF (jvm_env, message);
if (o_message == NULL)
+ {
+ cjni_thread_detach ();
return;
+ }
(*jvm_env)->CallVoidMethod (jvm_env,
cbi->object, cbi->method, (jint) severity, o_message);
JNIEnv *jvm_env;
cjni_callback_info_t *cbi;
jobject o_notification;
- int status;
int ret_status;
if (jvm == NULL)
if (o_notification == NULL)
{
ERROR ("java plugin: cjni_notification: ctoj_notification failed.");
+ cjni_thread_detach ();
return (-1);
}
(*jvm_env)->DeleteLocalRef (jvm_env, o_notification);
- status = cjni_thread_detach ();
- if (status != 0)
- {
- ERROR ("java plugin: cjni_read: cjni_thread_detach failed.");
- return (-1);
- }
-
+ cjni_thread_detach ();
return (ret_status);
} /* }}} int cjni_notification */
(*jvm_env)->DeleteLocalRef (jvm_env, cbi_ret->object); \
} \
free (cbi_ret); \
- if (jvm_env != NULL) { \
- if (o_ci != NULL) \
- (*jvm_env)->DeleteLocalRef (jvm_env, o_ci); \
- cjni_thread_detach (); \
- } \
+ if (o_ci != NULL) \
+ (*jvm_env)->DeleteLocalRef (jvm_env, o_ci); \
+ cjni_thread_detach (); \
return (status)
if (jvm == NULL)
{
ERROR ("java plugin: cjni_read: jvm == NULL");
- BAIL_OUT (-1);
+ return (-1);
}
jvm_env = cjni_thread_attach ();
if (jvm_env == NULL)
- {
- BAIL_OUT (-1);
- }
+ return (-1);
/* Find out whether to create a match or a target. */
if (strcasecmp ("Match", ci->key) == 0)
}
} /* if (cbi->type == CB_TYPE_TARGET) */
- status = cjni_thread_detach ();
- if (status != 0)
- ERROR ("java plugin: cjni_read: cjni_thread_detach failed.");
-
+ cjni_thread_detach ();
return (ret_status);
} /* }}} int cjni_match_target_invoke */
if (config_block != NULL)
{
-
cjni_config_perform (config_block);
oconfig_free (config_block);
- config_block = NULL;
}
if (jvm == NULL)