costin      02/04/15 17:01:33

  Modified:    jk/java/org/apache/jk/apr AprImpl.java
  Log:
  Added a more efficient interface to deal with callbacks from C to java
  ( code from channel_jni ).
  
  The idea is to avoid allocations and unneeded calls. I'll also try to
  add some experimental #ifdefed code to use pinning - that would eliminate
  the memcpy.
  
  Eventually this will be used for the unix channel and other callbacks from
  APR to java ( signals, etc ).
  
  Revision  Changes    Path
  1.6       +74 -0     jakarta-tomcat-connectors/jk/java/org/apache/jk/apr/AprImpl.java
  
  Index: AprImpl.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-tomcat-connectors/jk/java/org/apache/jk/apr/AprImpl.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- AprImpl.java      11 Apr 2002 05:46:51 -0000      1.5
  +++ AprImpl.java      16 Apr 2002 00:01:33 -0000      1.6
  @@ -1,6 +1,7 @@
   package org.apache.jk.apr;
   
   import java.io.*;
  +import java.util.*;
   
   /** Implements the interface with the APR library. This is for internal-use
    *  only. The goal is to use 'natural' mappings for user code - for example
  @@ -8,9 +9,15 @@
    * 
    */
   public class AprImpl {
  +    static AprImpl aprSingleton=new AprImpl();
  +
       String baseDir;
       String aprHome;
       String soExt="so";
  +
  +    public static AprImpl getAprImpl() {
  +        return aprSingleton;
  +    }
       
       /** Initialize APR
        */
  @@ -109,6 +116,73 @@
               ex.printStackTrace();
           }
       }
  +
  +    // Mostly experimental, the interfaces need to be cleaned up - after everything 
works
       
  +    Hashtable jniContextFactories=new Hashtable();
  +    
  +    public void addJniContextFactory(String type, JniContextFactory cb) {
  +        jniContextFactories.put( type, cb );
  +    }
  +
  +    public static interface JniContext {
  +
  +        /** Each context contains a number of byte[] buffers used for communication.
  +         *  The C side will contain a char * equivalent - both buffers are 
long-lived
  +         *  and recycled.
  +         *
  +         *  This will be called at init time. A long-lived global reference to the 
byte[]
  +         *  will be stored in the C context.
  +         */
  +        public byte[] getBuffer(  int id );
  +
  +
  +        /** Invoke a java hook. The xEnv is the representation of the current 
execution
  +         *  environment ( the jni_env_t * )
  +         */
  +        public int jniInvoke(  long xEnv );
  +    }
  +    
  +    public static interface JniContextFactory {
  +
  +        /** Create a Jni context - it is the corespondent of a C context, 
represented
  +         *    by a pointer
  +         *
  +         *  The 'context' is a long-lived object ( recycled ) that manages state for
  +         *  each jk operation.
  +         */
  +        public JniContext createJniContext( String type, long cContext );
  +    }
  +
       
  +    // -------------------- Called from C --------------------
  +
  +    public static Object createJavaContext(String type, long cContext) {
  +        JniContextFactory 
cb=(JniContextFactory)AprImpl.getAprImpl().jniContextFactories.get( type );
  +        if( cb==null ) return null;
  +
  +        return cb.createJniContext( type, cContext );
  +    }
  +
  +    /** Return a buffer associated with the ctx.
  +     */
  +    public static byte[] getBuffer( Object ctx, int id ) {
  +        return ((JniContext)ctx).getBuffer(  id );
  +    }
  +
  +    public static int jniInvoke( long jContext, Object ctx ) {
  +        return ((JniContext)ctx).jniInvoke(  jContext );
  +   }
  +
  +    // --------------------  java to C --------------------
  +
  +    // Temp - interface will evolve
  +    
  +    /** Send the packet to the C side. On return it contains the response
  +     *  or indication there is no response. Asymetrical because we can't
  +     *  do things like continuations.
  +     */
  +    public static native int sendPacket(long xEnv, long endpointP,
  +                                        byte data[], int len);
  +
   }
  
  
  

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

Reply via email to