cvs commit: jakarta-tomcat-connectors/jk/java/org/apache/jk/common JniHandler.java MsgAjp.java
costin 2002/06/11 15:48:46 Modified:jk/java/org/apache/jk/apr AprImpl.java jk/java/org/apache/jk/common JniHandler.java MsgAjp.java Log: Few fixes, moved the signal and user out of AprImpl ( will use the same mechanism as all other components ) Revision ChangesPath 1.21 +0 -17 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.20 retrieving revision 1.21 diff -u -r1.20 -r1.21 --- AprImpl.java 10 Jun 2002 21:26:25 - 1.20 +++ AprImpl.java 11 Jun 2002 22:48:46 - 1.21 @@ -249,23 +249,6 @@ } } -/** Set the user id, to avoid running as root. Should be called after we - * aquire all resources ( i.e. open files and sockets ). - */ -public native int setUser( String user, String group ); - -/** Return the process id of the java process - */ -public native int setPid(); - -/** Intercept the given signal. ( whenever this is possible ) - */ -public native int signal(int sig); - -/** Send the given singal to a process - */ -public native void sendSignal( int pid, int sig ); - public void loadNative(String libPath) { try { System.load( libPath ); 1.10 +10 -1 jakarta-tomcat-connectors/jk/java/org/apache/jk/common/JniHandler.java Index: JniHandler.java === RCS file: /home/cvs/jakarta-tomcat-connectors/jk/java/org/apache/jk/common/JniHandler.java,v retrieving revision 1.9 retrieving revision 1.10 diff -u -r1.9 -r1.10 --- JniHandler.java 6 Jun 2002 00:59:10 - 1.9 +++ JniHandler.java 11 Jun 2002 22:48:46 - 1.10 @@ -74,7 +74,16 @@ /** - * Proxy for the Jk native component. + * Base class for components using native code ( libjkjni.so ). + * It allows to access the jk_env and wrap ( 'box' ? ) a native + * jk component, and call it's methods. + * + * Note that get/setAttribute are expensive ( Strings, etc ), + * invoke() is were all optimizations are done. We do recycle + * all memory on both C and java sides ( the only exception is + * when we attempt pinning but the VM doesn't support it ). The + * low level optimizations from ByteBuffer, etc are used to + * reduce the overhead of passing strings. * * @author Costin Manolache */ 1.9 +1 -1 jakarta-tomcat-connectors/jk/java/org/apache/jk/common/MsgAjp.java Index: MsgAjp.java === RCS file: /home/cvs/jakarta-tomcat-connectors/jk/java/org/apache/jk/common/MsgAjp.java,v retrieving revision 1.8 retrieving revision 1.9 diff -u -r1.8 -r1.9 --- MsgAjp.java 1 Jun 2002 02:55:55 - 1.8 +++ MsgAjp.java 11 Jun 2002 22:48:46 - 1.9 @@ -286,7 +286,7 @@ int length = getInt(); if( length buf.length ) { // XXX Should be if(pos + length buff.legth)? -log.error(Try to get data after the end of the buffer); +log.error(getBytes() buffer overflow + length + + buf.length ); } if( (length == 0x) || (length == -1) ) { -- To unsubscribe, e-mail: mailto:[EMAIL PROTECTED] For additional commands, e-mail: mailto:[EMAIL PROTECTED]
cvs commit: jakarta-tomcat-connectors/jk/java/org/apache/jk/common JniHandler.java
costin 2002/06/05 17:59:10 Modified:jk/java/org/apache/jk/common JniHandler.java Log: Just a bit of cleanup, remove dead code. Revision ChangesPath 1.9 +10 -15 jakarta-tomcat-connectors/jk/java/org/apache/jk/common/JniHandler.java Index: JniHandler.java === RCS file: /home/cvs/jakarta-tomcat-connectors/jk/java/org/apache/jk/common/JniHandler.java,v retrieving revision 1.8 retrieving revision 1.9 diff -u -r1.8 -r1.9 --- JniHandler.java 1 Jun 2002 08:29:34 - 1.8 +++ JniHandler.java 6 Jun 2002 00:59:10 - 1.9 @@ -234,12 +234,14 @@ apr.jkRecycle(ep.getJniEnv(), ep.getJniContext()); } -/** send and get the response in the same buffer. +/** send and get the response in the same buffer. This calls the +* method on the wrapped jk_bean object. */ protected int nativeDispatch( Msg msg, MsgContext ep, int code, int raw ) throws IOException { -if( log.isDebugEnabled() ) log.debug( Sending packet + code + + raw); +if( log.isDebugEnabled() ) +log.debug( Sending packet + code + + raw); if( raw == 0 ) { msg.end(); @@ -267,7 +269,8 @@ int status=apr.jkInvoke( xEnv, nativeJkHandlerP, nativeContext, - code, msg.getBuffer(), 0, msg.getLen(), raw ); + code, msg.getBuffer(), 0, msg.getLen(), raw ); + if( status != 0 status != 2 ) { log.error( nativeDispatch: error + status ); } @@ -276,30 +279,22 @@ return status; } +/** Base implementation for invoke. Dispatch the action to the native +* code, where invoke() is called on the wrapped jk_bean. +*/ public int invoke(Msg msg, MsgContext ep ) throws IOException { long xEnv=ep.getJniEnv(); int type=ep.getType(); -switch( type ) { -case JkHandler.HANDLE_RECEIVE_PACKET: -//return receive( msg, ep ); -case JkHandler.HANDLE_SEND_PACKET: -//return send( msg, ep ); -} - int status=nativeDispatch(msg, ep, type, 0 ); apr.jkRecycle(xEnv, ep.getJniContext()); - -if(log.isInfoEnabled() ) log.info(Jni invoke status + status); - apr.releaseJkEnv( xEnv ); -return 0; +return status; } private static org.apache.commons.logging.Log log= org.apache.commons.logging.LogFactory.getLog( JniHandler.class ); - } -- To unsubscribe, e-mail: mailto:[EMAIL PROTECTED] For additional commands, e-mail: mailto:[EMAIL PROTECTED]
cvs commit: jakarta-tomcat-connectors/jk/java/org/apache/jk/common JniHandler.java
costin 02/05/28 15:50:37 Modified:jk/java/org/apache/jk/common JniHandler.java Log: Few fixes and enhancements, making sure everything works. Revision ChangesPath 1.6 +71 -9 jakarta-tomcat-connectors/jk/java/org/apache/jk/common/JniHandler.java Index: JniHandler.java === RCS file: /home/cvs/jakarta-tomcat-connectors/jk/java/org/apache/jk/common/JniHandler.java,v retrieving revision 1.5 retrieving revision 1.6 diff -u -r1.5 -r1.6 --- JniHandler.java 26 May 2002 07:13:59 - 1.5 +++ JniHandler.java 28 May 2002 22:50:37 - 1.6 @@ -151,6 +151,9 @@ try { MsgContext msgCtx=new MsgContext(); MsgAjp msg=new MsgAjp(); + +msgCtx.setSource( this ); +msgCtx.setWorkerEnv( wEnv ); msgCtx.setNext( this ); @@ -168,11 +171,60 @@ } } +public void setNativeAttribute(String name, String val) throws IOException { +if( apr==null ) return; + +if( nativeJkHandlerP == 0 ) { +log.error( Unitialized component + name+ + val ); +return; +} + +long xEnv=apr.getJkEnv(); + +apr.jkSetAttribute( xEnv, nativeJkHandlerP, name, val ); + +apr.releaseJkEnv( xEnv ); +} + +public void initJkComponent() throws IOException { +if( apr==null ) return; + +if( nativeJkHandlerP == 0 ) { +log.error( Unitialized component ); +return; +} + +long xEnv=apr.getJkEnv(); + +apr.jkInit( xEnv, nativeJkHandlerP ); + +apr.releaseJkEnv( xEnv ); +} + +public void destroyJkComponent() throws IOException { +if( apr==null ) return; + +if( nativeJkHandlerP == 0 ) { +log.error( Unitialized component ); +return; +} + +long xEnv=apr.getJkEnv(); + +apr.jkDestroy( xEnv, nativeJkHandlerP ); + +apr.releaseJkEnv( xEnv ); +} + + + protected void setNativeEndpoint(MsgContext msgCtx) { long xEnv=apr.getJkEnv(); msgCtx.setJniEnv( xEnv ); long epP=apr.createJkHandler(xEnv, endpoint); +log.debug(create ep + epP ); +if( epP == 0 ) return; apr.jkInit( xEnv, epP ); msgCtx.setJniContext( epP ); @@ -184,12 +236,19 @@ /** send and get the response in the same buffer. */ -protected int nativeDispatch( Msg msg, MsgContext ep, int code ) +protected int nativeDispatch( Msg msg, MsgContext ep, int code, int raw ) throws IOException { -if( log.isDebugEnabled() ) log.debug( Sending packet ); -msg.end(); -if( log.isTraceEnabled() ) msg.dump(OUT: ); +if( log.isDebugEnabled() ) log.debug( Sending packet + code + + raw); + +if( raw == 0 ) { +msg.end(); + +if( log.isTraceEnabled() ) msg.dump(OUT: ); +} + +// Create ( or reuse ) the jk_endpoint ( the native pair of +// MsgContext ) long xEnv=ep.getJniEnv(); long nativeContext=ep.getJniContext(); if( nativeContext==0 || xEnv==0 ) { @@ -204,11 +263,13 @@ } // Will process the message in the current thread. -// No wait needed to receive the response +// No wait needed to receive the response, if any int status=apr.jkInvoke( xEnv, nativeJkHandlerP, nativeContext, - code, msg.getBuffer(), msg.getLen()); + code, msg.getBuffer(), 0, msg.getLen(), raw ); +if( status != 0 ) +log.error( nativeDispatch: error + status ); if( log.isDebugEnabled() ) log.debug( Sending packet - done + status); return status; @@ -227,13 +288,14 @@ //return send( msg, ep ); } -int status=nativeDispatch(msg, ep, type ); +int status=nativeDispatch(msg, ep, type, 0 ); apr.jkRecycle(xEnv, ep.getJniContext()); if(log.isInfoEnabled() ) log.info(Shm invoke status + status); - -return 0; + +apr.releaseJkEnv( xEnv ); + return 0; } private static org.apache.commons.logging.Log log= -- To unsubscribe, e-mail: mailto:[EMAIL PROTECTED] For additional commands, e-mail: mailto:[EMAIL PROTECTED]
cvs commit: jakarta-tomcat-connectors/jk/java/org/apache/jk/common JniHandler.java
costin 02/04/25 11:20:33 Added: jk/java/org/apache/jk/common JniHandler.java Log: Add the code that is common the Shm and ChannelJni ( and soon ChannleUn ). ( I won't touch the stable code for socket and ajp13: Remy, relax :-) Revision ChangesPath 1.1 jakarta-tomcat-connectors/jk/java/org/apache/jk/common/JniHandler.java Index: JniHandler.java === /* * * * The Apache Software License, Version 1.1 * * Copyright (c) 1999 The Apache Software Foundation. All rights * reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright *notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above copyright *notice, this list of conditions and the following disclaimer in *the documentation and/or other materials provided with the *distribution. * * 3. The end-user documentation included with the redistribution, if *any, must include the following acknowlegement: * This product includes software developed by the *Apache Software Foundation (http://www.apache.org/). *Alternately, this acknowlegement may appear in the software itself, *if and wherever such third-party acknowlegements normally appear. * * 4. The names The Jakarta Project, Tomcat, and Apache Software *Foundation must not be used to endorse or promote products derived *from this software without prior written permission. For written *permission, please contact [EMAIL PROTECTED] * * 5. Products derived from this software may not be called Apache *nor may Apache appear in their names without prior written *permission of the Apache Group. * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * * * This software consists of voluntary contributions made by many * individuals on behalf of the Apache Software Foundation. For more * information on the Apache Software Foundation, please see * http://www.apache.org/. * * [Additional notices, if required by prior licensing conditions] * */ package org.apache.jk.common; import java.io.*; import java.net.*; import java.util.*; import org.apache.tomcat.util.buf.*; import org.apache.tomcat.util.http.*; import org.apache.tomcat.util.threads.*; import org.apache.jk.core.*; import org.apache.jk.apr.*; /** * Proxy for the Jk native component. * * @author Costin Manolache */ public class JniHandler extends JkHandler { protected AprImpl apr; // The native side handler protected long nativeJkHandlerP; protected String jkHome; // Dispatch table codes. Hardcoded for now, will change when we have more handlers. public static final int JK_HANDLE_JNI_DISPATCH=0x15; public static final int JK_HANDLE_SHM_DISPATCH=0x16; public static final int MSG_NOTE=0; public static final int C2B_NOTE=1; public static final int MB_NOTE=2; public JniHandler() { } /** */ public void setJkHome( String s ) { jkHome=s; } /** You must call initNative() inside the component init() */ public void init() throws IOException { // static field init, temp } protected void initNative(String nativeComponentName) { apr=(AprImpl)wEnv.getHandler(apr); if( apr==null || ! apr.isLoaded() ) { log.error(No apr, disabling jni proxy ); return; } long xEnv=apr.getJkEnv(); nativeJkHandlerP=apr.getJkHandler(xEnv, nativeComponentName ); if( nativeJkHandlerP==0 ) { log.info(Component not found,
cvs commit: jakarta-tomcat-connectors/jk/java/org/apache/jk/common JniHandler.java Shm.java
costin 02/04/25 15:44:24 Modified:jk/java/org/apache/jk/common JniHandler.java Shm.java Log: Few more fixes, checking if jni is initialized corectly and enabling the components that depend on that. Revision ChangesPath 1.2 +1 -0 jakarta-tomcat-connectors/jk/java/org/apache/jk/common/JniHandler.java Index: JniHandler.java === RCS file: /home/cvs/jakarta-tomcat-connectors/jk/java/org/apache/jk/common/JniHandler.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- JniHandler.java 25 Apr 2002 18:20:32 - 1.1 +++ JniHandler.java 25 Apr 2002 22:44:23 - 1.2 @@ -115,6 +115,7 @@ apr=(AprImpl)wEnv.getHandler(apr); if( apr==null || ! apr.isLoaded() ) { log.error(No apr, disabling jni proxy ); +apr=null; return; } 1.6 +1 -1 jakarta-tomcat-connectors/jk/java/org/apache/jk/common/Shm.java Index: Shm.java === RCS file: /home/cvs/jakarta-tomcat-connectors/jk/java/org/apache/jk/common/Shm.java,v retrieving revision 1.5 retrieving revision 1.6 diff -u -r1.5 -r1.6 --- Shm.java 25 Apr 2002 22:04:00 - 1.5 +++ Shm.java 25 Apr 2002 22:44:23 - 1.6 @@ -176,7 +176,7 @@ public int invoke(Msg msg, MsgContext ep ) throws IOException { -if( apr==null ) return; +if( apr==null ) return 0; System.err.println(ChannelShm.invoke: + ep ); super.nativeDispatch( msg, ep, JK_HANDLE_SHM_DISPATCH ); return 0; -- To unsubscribe, e-mail: mailto:[EMAIL PROTECTED] For additional commands, e-mail: mailto:[EMAIL PROTECTED]