> -----Original Message-----
> From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]] 
> Sent: 8. lipanj 2002 22:38
> To: Tomcat Developers List
> Subject: Re: [PROPOSAL] RegisterNatives
> 
> 
> On Sat, 8 Jun 2002, Mladen Turk wrote:
> 
> > Are there any reason why are we loading jkjni, or mod_jk2 for 
> 
> +1 !

Ok, here is the patch.

RegisterNatives are called inside jk_worker_jni.c for AprImpl class.
There is a small change in AprImpl.java that checks the name of
jniModeSo and if
the name equals "inprocess" (didn't think of anything smarter) the
native lib loading
is simply skipped. We trust that the native functions are inserted in
the JVM from the caller.

There is one potential problem about portability (apr_initialize call in
native initialize),
cause there is no need to call that from apache so I ifdef that out. The
apr_initialize for IIS should be called
IMO from DllMain  in jk_isapi_plugin, but I'm not familiar with that.

Nevertheless I've tested it with TC 4.1.3 and Apache-2.0.37-dev on
WINXP, build with VS7,
and it works as good as the 'standard' version :-).

Simply put the apr.jniModeSo=inprocess in jk2.properties, and that's it.


MT.
Index: AprImpl.java
===================================================================
RCS file: 
/home/cvspublic/jakarta-tomcat-connectors/jk/java/org/apache/jk/apr/AprImpl.java,v
retrieving revision 1.19
diff -u -r1.19 AprImpl.java
--- AprImpl.java        1 Jun 2002 08:29:34 -0000       1.19
+++ AprImpl.java        9 Jun 2002 08:12:31 -0000
@@ -204,6 +204,10 @@
                This seems the cleanest solution that works with multiple
                VMs.
             */
+            if (jniModeSo.equals("inprocess")) {
+                ok=true;
+                return;                                
+            }
             try {



Index: jk_worker_jni.c
===================================================================
RCS file: /home/cvspublic/jakarta-tomcat-connectors/jk/native2/common/jk_worker_jni.c,v
retrieving revision 1.15
diff -u -r1.15 jk_worker_jni.c
--- jk_worker_jni.c     16 May 2002 23:48:27 -0000      1.15
+++ jk_worker_jni.c     9 Jun 2002 08:13:35 -0000
@@ -71,10 +71,13 @@
 
 #include "jk_vm.h"
 #include "jk_registry.h"
-#include "jni.h"
+#include <jni.h>
+
+extern jint jk_jni_aprImpl_registerNatives(JNIEnv *, jclass);
 
 /* default only, will be  configurable  */
 #define JAVA_BRIDGE_CLASS_NAME ("org/apache/jk/apr/TomcatStarter")
+#define JAVA_BRIDGE_CLASS_APRI ("org/apache/jk/apr/AprImpl")
 
 struct jni_worker_data {
     jclass      jk_java_bridge_class;
@@ -102,8 +105,8 @@
 
     
     if(!p->jk_main_method) {
-       env->l->jkLog(env, env->l, JK_LOG_EMERG, "Can't find main()\n"); 
-       return JK_ERR;
+    env->l->jkLog(env, env->l, JK_LOG_EMERG, "Can't find main()\n"); 
+    return JK_ERR;
     }
 
     return JK_OK;
@@ -167,6 +170,7 @@
     jk_map_t *props=_this->workerEnv->initData;
     jk_vm_t *vm=_this->workerEnv->vm;
     jclass jstringClass;
+    jclass aprImplClass;
     jarray jargs;
     int i=0;
     
@@ -227,6 +231,29 @@
     
     env->l->jkLog(env, env->l, JK_LOG_INFO,
                   "Loaded %s\n", jniWorker->className);
+
+/* Instead of loading mod_jk2.so from java, use the JNI RegisterGlobals.
+   XXX Need the way to customize JAVA_BRIDGE_CLASS_APRI, but since
+   it's hardcoded in JniHandler.java doesn't matter for now.
+*/
+    aprImplClass =
+        (*jniEnv)->FindClass(jniEnv, JAVA_BRIDGE_CLASS_APRI );
+
+    if( aprImplClass == NULL ) {
+        env->l->jkLog(env, env->l, JK_LOG_ERROR,
+                      "Can't find class %s\n", JAVA_BRIDGE_CLASS_APRI );
+        /* [V] the detach here may segfault on 1.1 JVM... */
+        vm->detach(env, vm);
+        return JK_ERR;
+    }
+    rc = jk_jni_aprImpl_registerNatives( jniEnv, aprImplClass);
+
+   if( rc != 0) {
+     env->l->jkLog(env, env->l, JK_LOG_ERROR,
+                      "Can't register native functions for %s \n", 
+JAVA_BRIDGE_CLASS_APRI ); 
+        vm->detach(env, vm);
+        return JK_ERR;
+    }
 
     rc=jk2_get_method_ids(env, jniWorker, jniEnv);
     if( rc!=JK_OK ) {



cvs server: Diffing .
Index: jk_jni_aprImpl.c
===================================================================
RCS file: /home/cvspublic/jakarta-tomcat-connectors/jk/native2/jni/jk_jni_aprImpl.c,v
retrieving revision 1.31
diff -u -r1.31 jk_jni_aprImpl.c
--- jk_jni_aprImpl.c    7 Jun 2002 23:42:19 -0000       1.31
+++ jk_jni_aprImpl.c    9 Jun 2002 08:14:15 -0000
@@ -96,7 +96,7 @@
 #include "signal.h"
 #endif
 
-static apr_pool_t *jniAprPool;
+static apr_pool_t *jniAprPool = NULL;
 static jk_workerEnv_t *workerEnv;
 static int jniDebug=0;
 
@@ -118,8 +118,10 @@
 Java_org_apache_jk_apr_AprImpl_initialize(JNIEnv *jniEnv, jobject _jthis)
 {
     jk_env_t *env;
-    
+
+#if 0
     apr_initialize(); 
+#endif
     apr_pool_create( &jniAprPool, NULL );
 
     if( jk_env_globalEnv == NULL ) {
@@ -168,6 +170,11 @@
 Java_org_apache_jk_apr_AprImpl_terminate(JNIEnv *jniEnv, jobject _jthis)
 {
 /*     apr_terminate(); */
+    /* XXX Do we need that */
+    if (jniAprPool) {
+        apr_pool_destroy(jniAprPool);
+        jniAprPool = NULL;
+    }
     return 0;
 }
 
@@ -624,3 +631,78 @@
 }
 
 
+static JNINativeMethod org_apache_jk_apr_AprImpl_native_methods[] = {
+    { 
+        "initialize", "()I", 
+        Java_org_apache_jk_apr_AprImpl_initialize 
+    },
+    { 
+        "terminate", "()I",
+        Java_org_apache_jk_apr_AprImpl_terminate
+    },
+    { 
+        "getJkEnv", "()J",
+        Java_org_apache_jk_apr_AprImpl_getJkEnv
+    },
+    {
+        "releaseJkEnv", "(J)V",
+        Java_org_apache_jk_apr_AprImpl_releaseJkEnv
+    },
+    { 
+        "getJkHandler", "(JLjava/lang/String;)J",
+        Java_org_apache_jk_apr_AprImpl_getJkHandler
+    },
+    {
+        "createJkHandler", "(JLjava/lang/String;)J",
+        Java_org_apache_jk_apr_AprImpl_createJkHandler
+    },
+    {
+        "jkSetAttribute", "(JJLjava/lang/String;Ljava/lang/String;)I",
+        Java_org_apache_jk_apr_AprImpl_jkSetAttribute
+    },
+    {
+        "jkGetAttribute", "(JJLjava/lang/String;)Ljava/lang/String;",
+        Java_org_apache_jk_apr_AprImpl_jkGetAttribute
+    },
+    {
+        "jkInit", "(JJ)I",
+        Java_org_apache_jk_apr_AprImpl_jkInit
+    },
+    {
+        "jkDestroy", "(JJ)I",
+        Java_org_apache_jk_apr_AprImpl_jkDestroy
+    },
+    {
+        "jkInvoke", "(JJJI[BIII)I",
+        Java_org_apache_jk_apr_AprImpl_jkInvoke
+    },
+    {
+        "jkRecycle", "(JJ)V",
+        Java_org_apache_jk_apr_AprImpl_jkRecycle
+    },
+    {
+        "setUser", "(Ljava/lang/String;Ljava/lang/String;)I",
+        Java_org_apache_jk_apr_AprImpl_setUser
+    },
+    {
+        "signal", "(I)I",
+        Java_org_apache_jk_apr_AprImpl_signal
+    },
+    {
+        "sendSignal", "(II)V",
+        Java_org_apache_jk_apr_AprImpl_sendSignal
+    }
+};
+
+/*
+  Register Native methods returning the total number of
+  native functions
+*/
+jint jk_jni_aprImpl_registerNatives(JNIEnv *jniEnv, jclass bridgeClass)
+{
+  
+   return (*jniEnv)->RegisterNatives(jniEnv, bridgeClass,
+                        org_apache_jk_apr_AprImpl_native_methods,
+                        sizeof(org_apache_jk_apr_AprImpl_native_methods) / 
+                        sizeof(JNINativeMethod));
+}

--
To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>

Reply via email to