提交 efcd5656 authored 作者: Brian West's avatar Brian West

FS-4743 --resolve

上级 b4502078
......@@ -38,7 +38,7 @@ static switch_memory_pool_t *memoryPool = NULL;
static switch_dso_handle_t *javaVMHandle = NULL;
JavaVM *javaVM = NULL;
jclass launcherClass = NULL;
SWITCH_MODULE_LOAD_FUNCTION(mod_java_load);
SWITCH_MODULE_SHUTDOWN_FUNCTION(mod_java_shutdown);
......@@ -62,19 +62,16 @@ static vm_control_t vmControl;
static void launch_java(switch_core_session_t *session, const char *data, JNIEnv *env)
{
jclass Launcher = NULL;
jmethodID launch = NULL;
jstring uuid = NULL;
jstring args = NULL;
Launcher = (*env)->FindClass(env, "org/freeswitch/Launcher");
if (Launcher == NULL)
if (launcherClass == NULL)
{
(*env)->ExceptionDescribe(env);
goto done;
}
launch = (*env)->GetStaticMethodID(env, Launcher, "launch", "(Ljava/lang/String;Ljava/lang/String;)V");
launch = (*env)->GetStaticMethodID(env, launcherClass, "launch", "(Ljava/lang/String;Ljava/lang/String;)V");
if (launch == NULL)
{
(*env)->ExceptionDescribe(env);
......@@ -95,7 +92,7 @@ static void launch_java(switch_core_session_t *session, const char *data, JNIEnv
goto done;
}
(*env)->CallStaticVoidMethod(env, Launcher, launch, uuid, args);
(*env)->CallStaticVoidMethod(env, launcherClass, launch, uuid, args);
if ((*env)->ExceptionOccurred(env))
(*env)->ExceptionDescribe(env);
......@@ -104,8 +101,6 @@ done:
(*env)->DeleteLocalRef(env, args);
if (uuid != NULL)
(*env)->DeleteLocalRef(env, uuid);
if (Launcher != NULL)
(*env)->DeleteLocalRef(env, Launcher);
}
static switch_status_t exec_user_method(user_method_t * userMethod) {
......@@ -145,6 +140,7 @@ static switch_status_t exec_user_method(user_method_t * userMethod) {
goto done;
}
if (userMethod->arg != NULL) {
arg = (*env)->NewStringUTF(env, userMethod->arg);
if (arg == NULL) {
......@@ -152,6 +148,7 @@ static switch_status_t exec_user_method(user_method_t * userMethod) {
status = SWITCH_STATUS_FALSE;
goto done;
}
}
(*env)->CallStaticVoidMethod(env, class, method, arg);
......@@ -311,9 +308,32 @@ static switch_status_t create_java_vm(JavaVMOption *options, int optionCount, vm
res = pJNI_CreateJavaVM(&javaVM, (void*) &env, &initArgs);
if (res == JNI_OK)
{
(*javaVM)->DetachCurrentThread(javaVM);
// call FindClass here already so that the Java VM executes the static
// initializer (@see org.freeswitch.Launcher) which loads the jni library
// so we can use jni functions right away (for example in the startup method)
launcherClass = (*env)->FindClass(env, "org/freeswitch/Launcher");
if ( launcherClass == NULL )
{
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Unable to find 'org.freeswitch.Launcher' class!\n");
(*env)->ExceptionDescribe(env);
status = SWITCH_STATUS_FALSE;
}
// store a global reference for use in the launch_java() function
launcherClass = (*env)->NewGlobalRef(env, launcherClass);
if ( launcherClass == NULL )
{
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Out of memory!\n");
(*env)->ExceptionDescribe(env);
status = SWITCH_STATUS_FALSE;
}
else
{
status = SWITCH_STATUS_SUCCESS;
}
(*javaVM)->DetachCurrentThread(javaVM);
}
else
{
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error creating Java VM!\n");
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论