Return-Path: Delivered-To: apmail-jakarta-tomcat-dev-archive@apache.org Received: (qmail 39242 invoked from network); 1 May 2002 22:40:31 -0000 Received: from unknown (HELO nagoya.betaversion.org) (192.18.49.131) by daedalus.apache.org with SMTP; 1 May 2002 22:40:31 -0000 Received: (qmail 7782 invoked by uid 97); 1 May 2002 22:40:28 -0000 Delivered-To: qmlist-jakarta-archive-tomcat-dev@nagoya.betaversion.org Received: (qmail 7687 invoked by alias); 1 May 2002 22:40:28 -0000 Delivered-To: jakarta-archive-tomcat-dev@jakarta.apache.org Received: (qmail 7659 invoked by uid 97); 1 May 2002 22:40:27 -0000 Mailing-List: contact tomcat-dev-help@jakarta.apache.org; run by ezmlm Precedence: bulk List-Unsubscribe: List-Subscribe: List-Help: List-Post: List-Id: "Tomcat Developers List" Reply-To: "Tomcat Developers List" Delivered-To: mailing list tomcat-dev@jakarta.apache.org Received: (qmail 7631 invoked by alias); 1 May 2002 22:40:27 -0000 X-Antivirus: nagoya (v4198 created Apr 24 2002) Date: 1 May 2002 22:40:17 -0000 Message-ID: <20020501224017.74162.qmail@icarus.apache.org> From: costin@apache.org To: jakarta-tomcat-connectors-cvs@apache.org Subject: cvs commit: jakarta-tomcat-connectors/jk/java/org/apache/jk/common Shm.java X-Spam-Rating: daedalus.apache.org 1.6.2 0/1000/N X-Spam-Rating: daedalus.apache.org 1.6.2 0/1000/N costin 02/05/01 15:40:17 Modified: jk/java/org/apache/jk/common Shm.java Log: More code, start adding command line options. ( each bean setter is mapped to a command line option by IntrospectionUtil, in case you're not familiar with the code ) Revision Changes Path 1.8 +134 -6 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.7 retrieving revision 1.8 diff -u -r1.7 -r1.8 --- Shm.java 30 Apr 2002 17:44:50 -0000 1.7 +++ Shm.java 1 May 2002 22:40:17 -0000 1.8 @@ -74,6 +74,13 @@ import org.apache.tomcat.util.IntrospectionUtils; +/* The code is a bit confusing at this moment - the class is used as + a Bean, or ant Task, or CLI - i.e. you set properties and call execute. + + That's different from the rest of jk handlers wich are stateless ( but + similar with Coyote-http ). +*/ + /** Handle the shared memory objects. * @@ -82,24 +89,78 @@ public class Shm extends JniHandler { String file="/tmp/shm.file"; int size; + String host="localhost"; + int port=8009; + String unixSocket; + boolean unregister=false; + boolean reset=false; + // Will be dynamic ( getMethodId() ) after things are stable static final int SHM_SET_ATTRIBUTE=0; static final int SHM_WRITE_SLOT=2; static final int SHM_ATTACH=3; static final int SHM_DETACH=4; + static final int SHM_RESET=5; public Shm() { } - + + /** Scoreboard location + */ public void setFile( String f ) { file=f; } + /** Size. Used only if the scoreboard is to be created. + */ public void setSize( int size ) { this.size=size; } + /** Set this to get the scoreboard reset. + * The shm segment will be destroyed and a new one created, + * with the provided size. + * + * Requires "file" and "size". + */ + public void setReset(boolean b) { + reset=true; + } + + /** Ajp13 host + */ + public void setHost( String host ) { + this.host=host; + } + + /** Ajp13 port + */ + public void setPort( int port ) { + this.port=port; + } + + /** Unix socket where tomcat is listening. + * Use it only if tomcat is on the same host, of course + */ + public void setUnixSocket( String unixSocket ) { + this.unixSocket=unixSocket; + } + + /** Set this option to mark the tomcat instance as + 'down', so apache will no longer forward messages to it. + Note that requests with a session will still try this + host first. + + This can be used to implement gracefull shutdown. + + Host and port are still required, since they are used + to identify tomcat. + */ + public void setUnregister( boolean unregister ) { + this.unregister=unregister; + } + public void init() throws IOException { super.initNative( "shm" ); if( apr==null ) return; @@ -127,6 +188,17 @@ this.invoke( msg, mCtx ); } + public void resetScoreboard() throws IOException { + if( apr==null ) return; + MsgContext mCtx=createMsgContext(); + Msg msg=(Msg)mCtx.getMsg(0); + msg.reset(); + + msg.appendByte( SHM_RESET ); + + this.invoke( msg, mCtx ); + } + public void setNativeAttribute(String name, String val) throws IOException { if( apr==null ) return; MsgContext mCtx=createMsgContext(); @@ -143,15 +215,51 @@ this.invoke( msg, mCtx ); } - public void registerTomcat(String host, int port) throws IOException { + /** Register a tomcat instance + * XXX make it more flexible + */ + public void registerTomcat(String host, int port, String unixDomain) + throws IOException + { + if( apr==null ) return; + String slotName="TOMCAT:" + host + ":" + port; - writeSlot( slotName ); + MsgContext mCtx=createMsgContext(); + Msg msg=(Msg)mCtx.getMsg(0); + msg.reset(); + C2BConverter c2b=(C2BConverter)mCtx.getNote(C2B_NOTE); + + msg.appendByte( SHM_WRITE_SLOT ); + appendString( msg, slotName, c2b ); + + int channelCnt=1; + if( unixDomain != null ) channelCnt++; + + // number of channels for this instance + msg.appendInt( channelCnt ); + + // The body: + appendString(msg, "channel.socket:" + host + ":" + port, c2b ); + msg.appendInt( 1 ); + appendString(msg, "instance", c2b); + appendString(msg, host+":" + port, c2b); + + if( unixDomain != null ) { + appendString(msg, "channel.apr:" + unixDomain, c2b ); + msg.appendInt(1); + appendString(msg, "instance", c2b); + appendString(msg, host+":" + port, c2b); + } + + this.invoke( msg, mCtx ); } - - public void writeSlot(String slotName) + + public void unRegisterTomcat(String host, int port) throws IOException { if( apr==null ) return; + + String slotName="TOMCAT:" + host + ":" + port; MsgContext mCtx=createMsgContext(); Msg msg=(Msg)mCtx.getMsg(0); msg.reset(); @@ -160,6 +268,9 @@ msg.appendByte( SHM_WRITE_SLOT ); appendString( msg, slotName, c2b ); + // number of channels for this instance + msg.appendInt( 0 ); + this.invoke( msg, mCtx ); } @@ -193,9 +304,26 @@ public void execute() { try { + WorkerEnv wEnv=new WorkerEnv(); + AprImpl apr=new AprImpl(); + wEnv.addHandler( "apr", apr ); + wEnv.addHandler( "shm", this ); + apr.init(); + if( ! apr.isLoaded() ) { + log.error( "No native support. " + + "Make sure libapr.so and libjkjni.so are available in LD_LIBRARY_PATH"); + return; + } init(); + if( reset ) { + resetScoreboard(); + } else if( unregister ) { + unRegisterTomcat( host, port ); + } else { + registerTomcat( host, port, unixSocket ); + } } catch (Exception ex ) { - ex.printStackTrace(); + log.error( "Error executing Shm", ex); } } -- To unsubscribe, e-mail: For additional commands, e-mail: