From f8212f9e4bcacd586c98bfac843be6dcdaf6e11b Mon Sep 17 00:00:00 2001 From: Unbit Date: Fri, 8 Mar 2013 09:18:20 +0100 Subject: [PATCH] fixed alarm subsystem and added uwsgi.alarm to the JVM --- core/alarm.c | 2 +- core/master.c | 3 --- core/uwsgi.c | 3 +++ plugins/jvm/jvm_plugin.c | 12 ++++++++++++ plugins/jvm/uwsgi.java | 9 +++++++++ 5 files changed, 25 insertions(+), 4 deletions(-) diff --git a/core/alarm.c b/core/alarm.c index 2a60423a..949cf97d 100644 --- a/core/alarm.c +++ b/core/alarm.c @@ -267,7 +267,7 @@ void uwsgi_alarms_init() { } void uwsgi_alarm_thread_start() { - // start the alarm_threa + // start the alarm_thread uwsgi.alarm_thread = uwsgi_thread_new(uwsgi_alarm_thread_loop); if (!uwsgi.alarm_thread) { uwsgi_log("unable to spawn alarm thread\n"); diff --git a/core/master.c b/core/master.c index 95bebcc2..beff3015 100644 --- a/core/master.c +++ b/core/master.c @@ -371,9 +371,6 @@ int master_loop(char **argv, char **environ) { } - uwsgi_alarm_thread_start(); - uwsgi_exceptions_handler_thread_start(); - #ifdef UWSGI_SSL uwsgi_start_legions(); #endif diff --git a/core/uwsgi.c b/core/uwsgi.c index 8a3ffa7e..63b40315 100644 --- a/core/uwsgi.c +++ b/core/uwsgi.c @@ -2541,6 +2541,9 @@ next: #endif if (uwsgi.master_process) { + // initialize threads with shared state + uwsgi_alarm_thread_start(); + uwsgi_exceptions_handler_thread_start(); // initialize a mutex to avoid glibc problem with pthread+fork() if (uwsgi.threaded_logger) { pthread_mutex_init(&uwsgi.threaded_logger_lock, NULL); diff --git a/plugins/jvm/jvm_plugin.c b/plugins/jvm/jvm_plugin.c index a1e2daf6..c1afd1e8 100644 --- a/plugins/jvm/jvm_plugin.c +++ b/plugins/jvm/jvm_plugin.c @@ -93,6 +93,17 @@ JNIEXPORT jobject JNICALL uwsgi_jvm_api_cache_get(JNIEnv *env, jclass c, jstring return NULL; } +JNIEXPORT void JNICALL uwsgi_jvm_api_alarm(JNIEnv *env, jclass c, jstring alarm, jstring msg) { + + char *c_alarm = uwsgi_jvm_str2c(alarm); + size_t c_msg_len = uwsgi_jvm_strlen(msg); + char *c_msg = uwsgi_jvm_str2c(msg); + uwsgi_alarm_trigger(c_alarm, c_msg, c_msg_len); + uwsgi_jvm_release_chars(msg, c_msg); + uwsgi_jvm_release_chars(alarm, c_alarm); + +} + static JNINativeMethod uwsgi_jvm_api_methods[] = { {"register_signal", "(ILjava/lang/String;Luwsgi$SignalHandler;)V", (void *) &uwsgi_jvm_api_register_signal}, {"register_rpc", "(Ljava/lang/String;Luwsgi$RpcFunction;)V", (void *) &uwsgi_jvm_api_register_rpc}, @@ -102,6 +113,7 @@ static JNINativeMethod uwsgi_jvm_api_methods[] = { {"lock", "(I)V", (void *) &uwsgi_jvm_api_lock}, {"unlock", "(I)V", (void *) &uwsgi_jvm_api_unlock}, {"cache_get", "(Ljava/lang/String;)[B", (void *) &uwsgi_jvm_api_cache_get}, + {"alarm", "(Ljava/lang/String;Ljava/lang/String;)V", (void *) &uwsgi_jvm_api_alarm}, }; JNIEXPORT jint JNICALL uwsgi_jvm_request_body_read(JNIEnv *env, jobject o) { diff --git a/plugins/jvm/uwsgi.java b/plugins/jvm/uwsgi.java index 6dcc9a8c..db9b7516 100644 --- a/plugins/jvm/uwsgi.java +++ b/plugins/jvm/uwsgi.java @@ -28,5 +28,14 @@ public class uwsgi { public static native void unlock(int locknum); public static native byte[] cache_get(String key); + public static native byte[] cache_get(String key, String cache); + public static native void cache_set(String key, byte[] value); + public static native void cache_update(String key, byte[] value); + public static native void cache_set(String key, byte[] value, int expires); + public static native void cache_update(String key, byte[] value, int expires); + public static native void cache_set(String key, byte[] value, int expires, String cache); + public static native void cache_update(String key, byte[] value, int expires, String cache); + + public static native void alarm(String alarm, String msg); }