summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: d89088e)
raw | patch | inline | side by side (parent: d89088e)
author | Pierre-Yves Ritschard <pyr@spootnik.org> | |
Tue, 29 Jul 2014 12:37:05 +0000 (14:37 +0200) | ||
committer | Pierre-Yves Ritschard <pyr@spootnik.org> | |
Tue, 29 Jul 2014 12:37:05 +0000 (14:37 +0200) |
supersedes collectd/collectd#530
bindings/java/org/collectd/api/Collectd.java | patch | blob | history | |
bindings/java/org/collectd/java/GenericJMXConfConnection.java | 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 84e659265850dceafd0650c4a9bb7297e728b11f..e962f6e001a529b8c16988ec7807db2a40398a32 100644 (file)
*/
native private static void log (int severity, String message);
+ /**
+ * Yield contents of collectd/src/collectd.h:hostname_g
+ *
+ * @return The hostname as set in the collectd configuration.
+ */
+ native public static java.lang.String getHostname ();
+
/**
* Prints an error message.
*/
diff --git a/bindings/java/org/collectd/java/GenericJMXConfConnection.java b/bindings/java/org/collectd/java/GenericJMXConfConnection.java
index 99b140a210cbb74acba7862e115ddbb485207a66..186d14468bc9c04ef098db414e9663842fe1e38a 100644 (file)
return (this._host);
}
- try
- {
- InetAddress localHost = InetAddress.getLocalHost();
- return (localHost.getHostName ());
- }
- catch (UnknownHostException e)
- {
- return ("localhost");
- }
+ return Collectd.getHostname();
} /* }}} String getHost */
private void connect () /* {{{ */
diff --git a/src/java.c b/src/java.c
index e4b10bebb4f543bb74d3772f0894247c96c38f30..2b6a54271ce74221edcd533eb8a832efe30ad904 100644 (file)
--- a/src/java.c
+++ b/src/java.c
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]);