jmethodID m_long_constructor;
/* Look up the java.lang.Long class */
- c_long = (*jvm_env)->FindClass (jvm_env, "java.lang.Long");
+ c_long = (*jvm_env)->FindClass (jvm_env, "java/lang/Long");
if (c_long == NULL)
{
ERROR ("java plugin: ctoj_jlong_to_number: Looking up the "
jmethodID m_double_constructor;
/* Look up the java.lang.Long class */
- c_double = (*jvm_env)->FindClass (jvm_env, "java.lang.Double");
+ c_double = (*jvm_env)->FindClass (jvm_env, "java/lang/Double");
if (c_double == NULL)
{
ERROR ("java plugin: ctoj_jdouble_to_number: Looking up the "
return (NULL);
}
- (*jvm_env)->CallVoidMethod (jvm_env, o_ocitem, m_addvalue, o_child);
+ (*jvm_env)->CallVoidMethod (jvm_env, o_ocitem, m_addchild, o_child);
(*jvm_env)->DeleteLocalRef (jvm_env, o_child);
} /* }}} for (i = 0; i < ci->children_num; i++) */
/* Search for the `DataSet (String type)' constructor. */
m_constructor = (*jvm_env)->GetMethodID (jvm_env,
- c_dataset, "<init>", "(Ljava.lang.String;)V");
+ c_dataset, "<init>", "(Ljava/lang/String;)V");
if (m_constructor == NULL)
{
ERROR ("java plugin: ctoj_data_set: Looking up the "
(*jvm_env)->ReleaseStringUTFChars (jvm_env, o_name, c_name);
- cbi->class = (*jvm_env)->GetObjectClass (jvm_env, o_callback);
+ cbi->object = (*jvm_env)->NewGlobalRef (jvm_env, o_callback);
+ if (cbi->object == NULL)
+ {
+ ERROR ("java plugin: cjni_callback_info_create: NewGlobalRef failed.");
+ free (cbi);
+ return (NULL);
+ }
+
+ cbi->class = (*jvm_env)->GetObjectClass (jvm_env, cbi->object);
if (cbi->class == NULL)
{
ERROR ("java plugin: cjni_callback_info_create: GetObjectClass failed.");
return (NULL);
}
- cbi->object = o_callback;
-
cbi->method = (*jvm_env)->GetMethodID (jvm_env, cbi->class,
method_name, method_signature);
if (cbi->method == NULL)
return (NULL);
}
- (*jvm_env)->NewGlobalRef (jvm_env, o_callback);
-
return (cbi);
} /* }}} cjni_callback_info_t cjni_callback_info_create */
vm_args.options[i].optionString = jvm_argv[i];
}
- status = JNI_CreateJavaVM (&jvm, (void **) &jvm_env, (void **) &vm_args);
+ status = JNI_CreateJavaVM (&jvm, (void *) &jvm_env, (void *) &vm_args);
if (status != 0)
{
ERROR ("java plugin: cjni_create_jvm: "
JNIEnv *jvm_env;
java_plugin_class_t *class;
jmethodID constructor_id;
+ jobject tmp_object;
if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_STRING))
{
class->class = NULL;
class->object = NULL;
+ { /* Replace all dots ('.') with slashes ('/'). Dots are usually used
+ thorough the Java community, but (Sun's) `FindClass' and friends need
+ slashes. */
+ size_t i;
+ for (i = 0; class->name[i] != 0; i++)
+ if (class->name[i] == '.')
+ class->name[i] = '/';
+ }
+
DEBUG ("java plugin: Loading class %s", class->name);
class->class = (*jvm_env)->FindClass (jvm_env, class->name);
return (-1);
}
- class->object = (*jvm_env)->NewObject (jvm_env, class->class,
+ tmp_object = (*jvm_env)->NewObject (jvm_env, class->class,
constructor_id);
+ if (tmp_object != NULL)
+ class->object = (*jvm_env)->NewGlobalRef (jvm_env, tmp_object);
+ else
+ class->object = NULL;
if (class->object == NULL)
{
ERROR ("java plugin: cjni_config_load_plugin: "
return (-1);
}
- (*jvm_env)->NewGlobalRef (jvm_env, class->object);
cjni_thread_detach ();
java_classes_list_len++;
int status;
size_t i;
+ jclass class;
+ jmethodID method;
+
if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_STRING))
{
WARNING ("java plugin: `Plugin' blocks "
return (-1);
}
+ class = (*jvm_env)->GetObjectClass (jvm_env, cbi->object);
+ method = (*jvm_env)->GetMethodID (jvm_env, class,
+ "config", "(Lorg/collectd/api/OConfigItem;)I");
+
status = (*jvm_env)->CallIntMethod (jvm_env,
- cbi->object, cbi->method, o_ocitem);
+ cbi->object, method, o_ocitem);
(*jvm_env)->DeleteLocalRef (jvm_env, o_ocitem);
cjni_thread_detach ();
cjni_callback_info_t *cbi_factory;
const char *name;
jobject o_ci;
+ jobject o_tmp;
int type;
size_t i;
}
/* Then call the factory method so it creates a new object for us. */
- cbi_ret->object = (*jvm_env)->CallObjectMethod (jvm_env,
+ o_tmp = (*jvm_env)->CallObjectMethod (jvm_env,
cbi_factory->object, cbi_factory->method, o_ci);
- if (cbi_ret->object == NULL)
+ if (o_tmp == NULL)
{
ERROR ("java plugin: cjni_match_target_create: CallObjectMethod failed.");
BAIL_OUT (-1);
}
+ cbi_ret->object = (*jvm_env)->NewGlobalRef (jvm_env, o_tmp);
+ if (o_tmp == NULL)
+ {
+ ERROR ("java plugin: cjni_match_target_create: NewGlobalRef failed.");
+ BAIL_OUT (-1);
+ }
+
/* This is the class of the match. It is possibly different from the class of
* the match-factory! */
cbi_ret->class = (*jvm_env)->GetObjectClass (jvm_env, cbi_ret->object);
BAIL_OUT (-1);
}
- /* We have everything we hoped for. Now we add a new global reference so this
- * match isn't freed immediately after we return.. */
- (*jvm_env)->NewGlobalRef (jvm_env, cbi_ret->object);
-
/* Return the newly created match via the user_data pointer. */
*user_data = (void *) cbi_ret;
memset (&args, 0, sizeof (args));
args.version = JNI_VERSION_1_2;
- status = (*jvm)->AttachCurrentThread (jvm, (void **) &jvm_env, &args);
+ status = (*jvm)->AttachCurrentThread (jvm, (void *) &jvm_env, &args);
if (status != 0)
{
ERROR ("java plugin: cjni_shutdown: AttachCurrentThread failed with status %i.",