You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by co...@apache.org on 2002/01/26 08:24:37 UTC

cvs commit: jakarta-tomcat-connectors/jk/java/org/apache/jk/common ChannelJni.java

costin      02/01/25 23:24:37

  Modified:    jk/java/org/apache/jk/common ChannelJni.java
  Log:
  Yes, it's working ( at least at hello world level ). And I bet it's going to be
  much better now ( I only tested with the dummy container, 3.3/4.0 should be
  easy to add but need some more work )
  
  See the commits on the c side for details.
  
  Revision  Changes    Path
  1.3       +129 -40   jakarta-tomcat-connectors/jk/java/org/apache/jk/common/ChannelJni.java
  
  Index: ChannelJni.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat-connectors/jk/java/org/apache/jk/common/ChannelJni.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- ChannelJni.java	16 Jan 2002 15:38:29 -0000	1.2
  +++ ChannelJni.java	26 Jan 2002 07:24:37 -0000	1.3
  @@ -77,60 +77,149 @@
    *
    * @author Costin Manolache
    */
  -public class ChannelJni extends JkChannel implements Channel {
  +public class ChannelJni extends Channel {
   
  +    int receivedNote=1;
  +    public ChannelJni() {
  +        // we use static for now, it's easier on the C side.
  +        // Easy to change after we get everything working
  +        chJni=this;
  +    }
   
  -    /* ==================== ==================== */
  -    
  -    static WorkerEnv wenv=null;
  +    public void init() throws IOException {
  +        // static field init, temp
  +        wEnv=we;
  +    }
       
  -    public static int startup(String cmdLine,
  -                              String stdout,
  -                              String stderr)
  +    public int receive( Msg msg, Endpoint ep )
  +        throws IOException
       {
  -        System.out.println("In startup");
  -        System.err.println("In startup err");
  -        if( wenv!=null ) {
  -            d("Second call, ignored ");
  -            return 1;
  -        }
  -
  -        try {
  -            if(null != stdout) {
  -                PrintStream out=new PrintStream(new FileOutputStream(stdout));
  -                System.setOut(out);
  -                if( stderr==null ) 
  -                    System.setErr(out);
  -            }
  -            if(null != stderr) {
  -                PrintStream err=new PrintStream(new FileOutputStream(stderr));
  -                System.setErr(err);
  -                if( stdout==null )
  -                    System.setOut(err);
  -            }
  -            if( stdout==null && stderr==null ) {
  -                // no problem, use stderr - it'll go to error.log of the server.
  -                System.setOut( System.err );
  -            }
  -        } catch(Throwable t) {
  +        Msg sentResponse=(Msg)ep.getNote( receivedNote );
  +        // same buffer is used, no need to copy
  +        if( msg==sentResponse ) {
  +            d("Returned previously received message ");
  +            return 0;
           }
  -        System.out.println("New stream");
  -        System.err.println("New err stream");
   
  -        return 1;
  +        d("XXX Copy previously received message ");
  +        // send will alter the msg and insert the response.
  +        // copy...
  +        // XXX TODO
  +        
  +        return 0;
       }
   
  -    public static int service(long s, long l)
  +    /** Send the packet. XXX This will modify msg !!!
  +     *  We could use 2 packets, or sendAndReceive().
  +     *    
  +     */
  +    public int send( Msg msg, Endpoint ep )
  +        throws IOException
       {
  -        System.out.println("In service");
  +        byte buf[]=msg.getBuffer();
  +        EpData epData=(EpData)ep.getNote( epDataNote );
  +
  +        // send and get the response
  +        d( "Sending packet ");
  +        msg.end();
  +        //         msg.dump("Outgoing: ");
  +        
  +        int status=sendPacket( epData.jkEnvP, epData.jkEndpointP,
  +                               epData.jkServiceP, buf, msg.getLen() );
  +        ep.setNote( receivedNote, msg );
  +        
  +        d( "Sending packet - done ");
           return 0;
       }
   
  -    public static void shutdown() {
  -        System.out.println("In shutdown");
  +    /* ==================== ==================== */
  +    
  +    static WorkerEnv wEnv=null;
  +    static int epDataNote=-1;
  +    static ChannelJni chJni=new ChannelJni();
  +
  +    static class EpData {
  +        public long jkEnvP;
  +        public long jkEndpointP;
  +        public long jkServiceP;
  +    }
  +    
  +    public static Endpoint createEndpointStatic(long env, long epP) {
  +        Endpoint ep=new Endpoint();
  +        if( epDataNote==-1) 
  +            epDataNote=wEnv.getNoteId(WorkerEnv.ENDPOINT_NOTE, "epData");
  +
  +        d("createEndpointStatic() " + env + " " + epP);
  +        EpData epData=new EpData();
  +        epData.jkEnvP=env;
  +        epData.jkEndpointP=epP;
  +        ep.setNote( epDataNote, epData );
  +        return ep;
       }
   
  -    private static final int dL=0;
  +    public static MsgAjp createMessage() {
  +        System.out.println("XXX CreateMessage");
  +        return new MsgAjp();
  +    }
  +
  +    public static byte[] getBuffer(MsgAjp msg) {
  +        System.out.println("XXX getBuffer " + msg.getBuffer() + " "
  +                           + msg.getBuffer().length);
  +        return msg.getBuffer();
  +    }
  +    
  +    /** Receive a packet from the C side. This is called from the C
  +     *  code using invocation, but only for the first packet - to avoid
  +     *  recursivity and thread problems.
  +     *
  +     *  This may look strange, but seems the best solution for the
  +     *  problem ( the problem is that we don't have 'continuation' ).
  +     *
  +     *  sendPacket will move the thread execution on the C side, and
  +     *  return when another packet is available. For packets that
  +     *  are one way it'll return after it is processed too ( having
  +     *  2 threads is far more expensive ).
  +     *
  +     *  Again, the goal is to be efficient and behave like all other
  +     *  Channels ( so the rest of the code can be shared ). Playing with
  +     *  java objects on C is extremely difficult to optimize and do
  +     *  right ( IMHO ), so we'll try to keep it simple - byte[] passing,
  +     *  the conversion done in java ( after we know the encoding and
  +     *  if anyone asks for it - same lazy behavior as in 3.3 ).
  +     */
  +    public static int receiveRequest( long env, long rP, Endpoint ep,
  +                                      MsgAjp msg)
  +    {
  +        try {
  +            // first, we need to get an endpoint. It should be
  +            // per/thread - and probably stored by the C side.
  +            d("Received request " + rP);
  +            // The endpoint will store the message pt.
  +            msg.processHeader();
  +            // msg.dump("Incoming msg ");
  +
  +            EpData epData=(EpData)ep.getNote( epDataNote );
  +
  +            epData.jkServiceP=rP;
  +            
  +            int status=wEnv.processCallbacks( chJni, ep, msg );
  +            
  +            d("after processCallbacks ");
  +
  +        } catch( Exception ex ) {
  +            ex.printStackTrace();
  +        }
  +        return 0;
  +    }
  +
  +    /** 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 env, long e, long s,
  +                                        byte data[], int len);
  +    
  +    private static final int dL=10;
       private static void d(String s ) {
           System.err.println( "ChannelJni: " + s );
       }
  
  
  

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>