costin      01/08/23 18:15:18

  Modified:    src/share/org/apache/tomcat/modules/server
                        JNIConnectionHandler.java JNIEndpoint.java
  Log:
  - remove the dependency between JNIEndpoint and JNIConnectionHandler.
  The reverse is ok ( JNIConnection handler depends on JNIEndpoint ), since
  JNIEndpoint is in the main classloader.
  
  - added an option to exit if the library can't be loaded. This is a serious
  configuration problem, similar with apache not beeing able to find a module, the
  behavior should be the same.
  
  - fix the name of the .so/.dll/.nlm file ( had an extra s ). Fix File.separator,
  use the constructed path.
  
  - fix the 'multiple start' problem.
  
  Revision  Changes    Path
  1.12      +19 -23    
jakarta-tomcat/src/share/org/apache/tomcat/modules/server/JNIConnectionHandler.java
  
  Index: JNIConnectionHandler.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/modules/server/JNIConnectionHandler.java,v
  retrieving revision 1.11
  retrieving revision 1.12
  diff -u -r1.11 -r1.12
  --- JNIConnectionHandler.java 2001/08/16 00:26:14     1.11
  +++ JNIConnectionHandler.java 2001/08/24 01:15:18     1.12
  @@ -1,8 +1,4 @@
   /*
  - * $Header: 
/home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/modules/server/JNIConnectionHandler.java,v
 1.11 2001/08/16 00:26:14 costin Exp $
  - * $Revision: 1.11 $
  - * $Date: 2001/08/16 00:26:14 $
  - *
    * ====================================================================
    *
    * The Apache Software License, Version 1.1
  @@ -83,25 +79,15 @@
    *
    * @author Gal Shachor <[EMAIL PROTECTED]>
    */
  -public class JNIConnectionHandler extends BaseInterceptor {
  +public class JNIConnectionHandler extends BaseInterceptor implements 
JNIEndpoint.JniHandler {
   
       public JNIConnectionHandler() {
       }
   
  -    // JNIEndpoint was called to start tomcat
  -    // Hack used to set the handler in JNIEndpoint.
  -    // This works - if we have problems we may take the time
  -    // and implement a better mechanism
  -    static JNIEndpoint ep;
  -
  -    public static void setEndpoint(JNIEndpoint jniep)
  -    {
  -        ep = jniep;
  -    }
  -
       // -------------------- Config -------------------- 
       boolean nativeLibLoaded=false;
       String lib;
  +    boolean exitOnError=true;
       
       /** Location of the jni library
        */
  @@ -109,14 +95,24 @@
        this.lib=lib;
       }
   
  +    public void setExitIfNoLib(boolean b) {
  +     exitOnError=b;
  +    }
  +
  +    JNIEndpoint ep=null;
  +    
       /** Called when the ContextManger is started
        */
       public void engineInit(ContextManager cm) throws TomcatException {
  -     if( ep==null ) return;
  +     ep= JNIEndpoint.getEndpoint();
  +     if(ep==null ) return;
        super.engineInit( cm );
   
        if(! nativeLibLoaded ) {
            initLibrary();
  +         if( ! nativeLibLoaded && exitOnError) {
  +             System.exit(2);
  +         }
        }
        try {
            // notify the jni side that jni is set up corectly
  @@ -201,7 +197,7 @@
        }
   
        if( lib==null ) {
  -         lib="jni_connector.";
  +         lib="jni_connect.";
            String os = System.getProperty("os.name").toLowerCase();
            if(os.indexOf("windows")>=0){
                lib+="dll";
  @@ -232,23 +228,23 @@
        if( ! libF.isAbsolute() ) {
            File f1=new File(cm.getInstallDir());
            // XXX should it be "libexec" ???
  -         File f2=new File( f1, "bin" + File.pathSeparator + "native" );
  +         File f2=new File( f1, "bin" + File.separator + "native" );
            libF=new File( f2, lib );
        }
   
        if( ! libF.exists() ) {
            throw new TomcatException( "Native library doesn't exist " + libF );
        }
  -     
  +
           // Loading from the library path failed
           // Try to load assuming lib is a complete pathname.
           try {
  -         System.load(lib);
  +         System.load(libF.getAbsolutePath());
            nativeLibLoaded=true;
  -         System.out.println("Library " + lib + " loaded");
  +         System.out.println("Library " + libF.getAbsolutePath() + " loaded");
               return;
           } catch(UnsatisfiedLinkError usl) {
  -            System.err.println("Failed to load() " + lib);
  +            System.err.println("Failed to load() " + libF.getAbsolutePath());
               if( debug > 0 )
                usl.printStackTrace();
           }        
  
  
  
  1.4       +38 -21    
jakarta-tomcat/src/share/org/apache/tomcat/modules/server/JNIEndpoint.java
  
  Index: JNIEndpoint.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/modules/server/JNIEndpoint.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- JNIEndpoint.java  2001/08/23 15:02:42     1.3
  +++ JNIEndpoint.java  2001/08/24 01:15:18     1.4
  @@ -1,7 +1,7 @@
   /*
  - * $Header: 
/home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/modules/server/JNIEndpoint.java,v 
1.3 2001/08/23 15:02:42 costin Exp $
  - * $Revision: 1.3 $
  - * $Date: 2001/08/23 15:02:42 $
  + * $Header: 
/home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/modules/server/JNIEndpoint.java,v 
1.4 2001/08/24 01:15:18 costin Exp $
  + * $Revision: 1.4 $
  + * $Date: 2001/08/24 01:15:18 $
    *
    * ====================================================================
    *
  @@ -76,7 +76,7 @@
    */
   public class JNIEndpoint {
   
  -    JNIConnectionHandler handler;
  +    JniHandler handler;
   
       boolean running = false;
   
  @@ -90,10 +90,11 @@
       // -------------------- Configuration --------------------
   
       // Called back when the server is initializing the handler
  -    public void setConnectionHandler(JNIConnectionHandler handler ) {
  +    public void setConnectionHandler(JniHandler handler ) {
        this.handler=handler;
        // the handler is no longer useable
        if( handler==null ) {
  +         System.out.println("Shutting down, handler==null ...");
            running=false;
               synchronized(this) {
                   notify();
  @@ -107,7 +108,20 @@
               notify();
           }
       }
  +    
  +    // We can have a single active JNIEndpoint.
  +    static JNIEndpoint ep;
  +
  +    public static void setEndpoint(JNIEndpoint jniep)
  +    {
  +        ep = jniep;
  +    }
  +
  +    public static JNIEndpoint getEndpoint() {
  +     return ep;
  +    }
   
  +
       // -------------------- JNI Entry points
   
       /** Called by JNI to start up tomcat.
  @@ -116,6 +130,11 @@
                          String stdout,
                          String stderr)
       {
  +     if( ep != null ) {
  +         System.err.println("ALREADY STARTED, this is the second call to STARTUP ");
  +         return 1;
  +     }
  +     System.err.println("Mod_jk calling startup() ");
           try {
               if(null != stdout) {
                   System.setOut(new PrintStream(new FileOutputStream(stdout)));
  @@ -129,24 +148,23 @@
        // We need to make sure tomcat did start successfully and
        // report this back.
           try {
  -            JNIConnectionHandler.setEndpoint(this);
  +            JNIEndpoint.setEndpoint(this);
            // it will call back setHandler !!
  -            StartupThread startup = new StartupThread(cmdLine,
  -                                                      this);
  +            StartupThread startup = new StartupThread(cmdLine);
  +         System.err.println("Starting up StartupThread");
               startup.start();
  -         System.out.println("Starting up StartupThread");
               synchronized (this) {
                   wait(60*1000);
               }
  -         System.out.println("End waiting");
  +         System.err.println("End waiting");
           } catch(Throwable t) {
           }
   
           if(running) {
  -         System.out.println("Running fine ");
  +         System.err.println("Running fine ");
               return 1;
           }
  -     System.out.println("Error - why doesn't run ??");
  +     System.err.println("Error - why doesn't run ??");
           return 0;
       }
   
  @@ -172,6 +190,10 @@
       {
           System.out.println("JNI In shutdown");
       }
  +
  +    public static interface JniHandler {
  +     public void processConnection( long s, long l );
  +    }
   }
   
   /** Tomcat is started in a separate thread. It may be loaded on demand,
  @@ -182,12 +204,8 @@
    */
   class StartupThread extends Thread {
       String []cmdLine = null;
  -    JNIEndpoint jniEp = null;
  -
  -    public StartupThread(String cmdLine,
  -                         JNIEndpoint jniEp) {
  -        this.jniEp = jniEp;
   
  +    public StartupThread(String cmdLine) {
           if(null == cmdLine) {
                this.cmdLine = new String[0];
           } else {
  @@ -204,16 +222,15 @@
       public void run() {
           boolean failed = true;
           try {
  -         System.out.println("Calling main" );
  +         System.err.println("Calling main" );
               org.apache.tomcat.startup.Main.main(cmdLine);
  -         System.out.println("Main returned" );
  +         System.err.println("Main returned" );
               failed = false;
           } catch(Throwable t) {
               t.printStackTrace(); // OK
           } finally {
               if(failed) {
  -             System.out.println("Failed ??");
  -             // stopEndpoint();
  +             System.err.println("Failed ??");
               }
           }
       }
  
  
  

Reply via email to