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

2005-05-15 Thread billbarker
billbarker2005/05/15 13:16:32

  Modified:jk/java/org/apache/jk/common Shm.java WorkerDummy.java
  Log:
  Oops missed a couple of files.
  
  Revision  ChangesPath
  1.16  +3 -3  
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.15
  retrieving revision 1.16
  diff -u -r1.15 -r1.16
  --- Shm.java  17 Sep 2004 18:34:18 -  1.15
  +++ Shm.java  15 May 2005 20:16:32 -  1.16
  @@ -160,7 +160,7 @@
   if( apr==null ) return;
   MsgContext mCtx=createMsgContext();
   Msg msg=(Msg)mCtx.getMsg(0);
  -C2BConverter c2b=(C2BConverter)mCtx.getNote(C2B_NOTE);
  +C2BConverter c2b=mCtx.getConverter();
   msg.reset();
   
   msg.appendByte( SHM_DUMP );
  @@ -182,7 +182,7 @@
   MsgContext mCtx=createMsgContext();
   Msg msg=(Msg)mCtx.getMsg(0);
   msg.reset();
  -C2BConverter c2b=(C2BConverter)mCtx.getNote(C2B_NOTE);
  +C2BConverter c2b=mCtx.getConverter();
   
   msg.appendByte( SHM_WRITE_SLOT );
   appendString( msg, slotName, c2b );
  @@ -225,7 +225,7 @@
   MsgContext mCtx=createMsgContext();
   Msg msg=(Msg)mCtx.getMsg(0);
   msg.reset();
  -C2BConverter c2b=(C2BConverter)mCtx.getNote(C2B_NOTE);
  +C2BConverter c2b=mCtx.getConverter();
   
   msg.appendByte( SHM_WRITE_SLOT );
   appendString( msg, slotName, c2b );
  
  
  
  1.11  +3 -3  
jakarta-tomcat-connectors/jk/java/org/apache/jk/common/WorkerDummy.java
  
  Index: WorkerDummy.java
  ===
  RCS file: 
/home/cvs/jakarta-tomcat-connectors/jk/java/org/apache/jk/common/WorkerDummy.java,v
  retrieving revision 1.10
  retrieving revision 1.11
  diff -u -r1.10 -r1.11
  --- WorkerDummy.java  11 Jan 2005 13:37:46 -  1.10
  +++ WorkerDummy.java  15 May 2005 20:16:32 -  1.11
  @@ -59,7 +59,7 @@
   }
   
   msg.reset();
  -msg.appendByte(HandlerRequest.JK_AJP13_SEND_HEADERS);
  +msg.appendByte(AjpConstants.JK_AJP13_SEND_HEADERS);
   msg.appendInt(200);
   msg.appendBytes(null);
   
  @@ -70,7 +70,7 @@
   // msg.dump(out: );
   
   msg.reset();
  -msg.appendByte( HandlerRequest.JK_AJP13_SEND_BODY_CHUNK);
  +msg.appendByte( AjpConstants.JK_AJP13_SEND_BODY_CHUNK);
   msg.appendInt( body.getLength() );
   msg.appendBytes( body );
   
  @@ -78,7 +78,7 @@
   ep.getSource().invoke(msg, ep);
   
   msg.reset();
  -msg.appendByte( HandlerRequest.JK_AJP13_END_RESPONSE );
  +msg.appendByte( AjpConstants.JK_AJP13_END_RESPONSE );
   msg.appendInt( 1 );
   
   ep.getSource().invoke(msg, ep );
  
  
  

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



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

2002-05-02 Thread Hans Schmid

Please see questions on shm and lb worker intermixed,

 -Ursprüngliche Nachricht-
 Von: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]]
 Gesendet: Donnerstag, 2. Mai 2002 05:18
 An: [EMAIL PROTECTED]
 Betreff: cvs commit:
 jakarta-tomcat-connectors/jk/java/org/apache/jk/common Shm.java


 costin  02/05/01 20:18:01

   Modified:jk/java/org/apache/jk/common Shm.java
   Log:
   Few more features. I think the sending part works fine now (
 but we should
   still do more tunning ).

   For each tomcat instance we create a shm slot in the scoreboard. The
   slot is named TOMCAT:host:port ( host:port is used as instance ID ), and
   contains a ( ajp13-encoded ) structure with informations about
 the channels
   ( currently the socket and unix channel - jni is special ). It'll also
   include the groups where the instance belongs, and possibly other
   informations.

   If the number of channels is 0, the lb worker is supposed to stop
   sending new requests to the instance ( but keep forwarding the
   existing sessions ). That'll implement 'gracefull shutdown'.


I hope the current 'lbfactor' functionality mod_jk from TC3.3.1 will still
be working
(or an equivilent strategy):

Scenario:
We have two Tomcats in a lb group. Only one is running at a time with
lbfactor=1,
the other has lbfactor=0 assinged but is not running - all requests go to
TC1

When we upgrade our system we update the classes/jars and start the second
Tomcat TC2 in the group,
switch the lbfactor of TC1 to 0 and the lbfactor fo TC2 to 1 and do a
graceful
restart of apache. This way old sessions still go to TC1 whereas new
sessions go to TC2.

After all sessions on TC1 have ended, we shutdown TC1 and TC2 serves
everything.

Next update goes in the oposit direction (start TC1, switch lbfactors, wait
for the end of all
sessions on TC2 and finally shutdown TC2.


Thanks,
Hans



   Still to add:
   - display ( nicely ) the information in the shm
   - read info from shm ( like slots owned by apache processes with
   statistics - in a future release )

   Revision  ChangesPath
   1.9   +27 -0
 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/S
 hm.java,v
   retrieving revision 1.8
   retrieving revision 1.9
   diff -u -r1.8 -r1.9
   --- Shm.java1 May 2002 22:40:17 -   1.8
   +++ Shm.java2 May 2002 03:18:01 -   1.9
   @@ -95,6 +95,7 @@

boolean unregister=false;
boolean reset=false;
   +String dumpFile=null;

// Will be dynamic ( getMethodId() ) after things are stable
static final int SHM_SET_ATTRIBUTE=0;
   @@ -102,6 +103,8 @@
static final int SHM_ATTACH=3;
static final int SHM_DETACH=4;
static final int SHM_RESET=5;
   +static final int SHM_DUMP=6;
   +static final int SHM_DESTROY=7;

public Shm() {
}
   @@ -112,6 +115,13 @@
file=f;
}

   +/** Copy the scoreboard in a file for debugging
   + *  Will also log a lot of information about what's in the
 scoreboard.
   + */
   +public void setDump( String dumpFile ) {
   +this.dumpFile=dumpFile;
   +}
   +
/** Size. Used only if the scoreboard is to be created.
 */
public void setSize( int size ) {
   @@ -199,6 +209,20 @@
this.invoke( msg, mCtx );
}

   +public void dumpScoreboard(String fname) throws IOException {
   +if( apr==null ) return;
   +MsgContext mCtx=createMsgContext();
   +Msg msg=(Msg)mCtx.getMsg(0);
   +C2BConverter c2b=(C2BConverter)mCtx.getNote(C2B_NOTE);
   +msg.reset();
   +
   +msg.appendByte( SHM_DUMP );
   +
   +appendString( msg, fname, c2b);
   +
   +this.invoke( msg, mCtx );
   +}
   +
public void setNativeAttribute(String name, String val)
 throws IOException {
if( apr==null ) return;
MsgContext mCtx=createMsgContext();
   @@ -315,8 +339,11 @@
return;
}
init();
   +
if( reset ) {
resetScoreboard();
   +} else if( dumpFile!=null ) {
   +dumpScoreboard(dumpFile);
} else if( unregister ) {
unRegisterTomcat( host, port );
} else {




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




--
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 Shm.java

2002-05-01 Thread costin

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  ChangesPath
  1.8   +134 -6jakarta-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 -  1.7
  +++ Shm.java  1 May 2002 22:40:17 -   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 

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

2002-05-01 Thread costin

costin  02/05/01 20:18:01

  Modified:jk/java/org/apache/jk/common Shm.java
  Log:
  Few more features. I think the sending part works fine now ( but we should
  still do more tunning ).
  
  For each tomcat instance we create a shm slot in the scoreboard. The
  slot is named TOMCAT:host:port ( host:port is used as instance ID ), and
  contains a ( ajp13-encoded ) structure with informations about the channels
  ( currently the socket and unix channel - jni is special ). It'll also
  include the groups where the instance belongs, and possibly other
  informations.
  
  If the number of channels is 0, the lb worker is supposed to stop
  sending new requests to the instance ( but keep forwarding the
  existing sessions ). That'll implement 'gracefull shutdown'.
  
  Still to add:
  - display ( nicely ) the information in the shm
  - read info from shm ( like slots owned by apache processes with
  statistics - in a future release )
  
  Revision  ChangesPath
  1.9   +27 -0 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.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- Shm.java  1 May 2002 22:40:17 -   1.8
  +++ Shm.java  2 May 2002 03:18:01 -   1.9
  @@ -95,6 +95,7 @@
   
   boolean unregister=false;
   boolean reset=false;
  +String dumpFile=null;
   
   // Will be dynamic ( getMethodId() ) after things are stable 
   static final int SHM_SET_ATTRIBUTE=0;
  @@ -102,6 +103,8 @@
   static final int SHM_ATTACH=3;
   static final int SHM_DETACH=4;
   static final int SHM_RESET=5;
  +static final int SHM_DUMP=6;
  +static final int SHM_DESTROY=7;
   
   public Shm() {
   }
  @@ -112,6 +115,13 @@
   file=f;
   }
   
  +/** Copy the scoreboard in a file for debugging
  + *  Will also log a lot of information about what's in the scoreboard.
  + */
  +public void setDump( String dumpFile ) {
  +this.dumpFile=dumpFile;
  +}
  +
   /** Size. Used only if the scoreboard is to be created.
*/
   public void setSize( int size ) {
  @@ -199,6 +209,20 @@
   this.invoke( msg, mCtx );
   }
   
  +public void dumpScoreboard(String fname) throws IOException {
  +if( apr==null ) return;
  +MsgContext mCtx=createMsgContext();
  +Msg msg=(Msg)mCtx.getMsg(0);
  +C2BConverter c2b=(C2BConverter)mCtx.getNote(C2B_NOTE);
  +msg.reset();
  +
  +msg.appendByte( SHM_DUMP );
  +
  +appendString( msg, fname, c2b);
  +
  +this.invoke( msg, mCtx );
  +}
  +
   public void setNativeAttribute(String name, String val) throws IOException {
   if( apr==null ) return;
   MsgContext mCtx=createMsgContext();
  @@ -315,8 +339,11 @@
   return;
   }
   init();
  +
   if( reset ) {
   resetScoreboard();
  +} else if( dumpFile!=null ) {
  +dumpScoreboard(dumpFile);
   } else if( unregister ) {
   unRegisterTomcat( host, port );
   } else {
  
  
  

--
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 Shm.java

2002-04-30 Thread costin

costin  02/04/30 10:44:50

  Modified:jk/java/org/apache/jk/common Shm.java
  Log:
  Use the WRITE_SLOT command.
  
  Again, the idea is that the scoreboard is divided in 'slots', each slot
  has a name ( identifying the 'owner' ).
  
  We'll use the scoreboard for configuration ( at first ), with a
  java bean ( used either individually or at tomcat startup ) writing
  information in the scoreboard about a tomcat instance.
  
  The lb worker will read the 'serial' number in the scoreboard header
  and update it's instance table based on the content.
  
  The synchronization is not implemented yet - if 2 tomcats
  are registered at the exact same time we may get unexpected results
  ( a bit unlikely, will be fixed after we 'bridge' the APR locks ).
  
  Revision  ChangesPath
  1.7   +8 -5  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.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- Shm.java  25 Apr 2002 22:44:23 -  1.6
  +++ Shm.java  30 Apr 2002 17:44:50 -  1.7
  @@ -85,7 +85,7 @@
   
   // Will be dynamic ( getMethodId() ) after things are stable 
   static final int SHM_SET_ATTRIBUTE=0;
  -static final int SHM_REGISTER_TOMCAT=2;
  +static final int SHM_WRITE_SLOT=2;
   static final int SHM_ATTACH=3;
   static final int SHM_DETACH=4;
   
  @@ -142,8 +142,13 @@
   
   this.invoke( msg, mCtx );
   }
  +
  +public void registerTomcat(String host, int port) throws IOException {
  +String slotName=TOMCAT: + host + : + port;
  +writeSlot( slotName );
  +}
   
  -public void registerTomcat(String host, int port)
  +public void writeSlot(String slotName)
   throws IOException
   {
   if( apr==null ) return;
  @@ -151,10 +156,8 @@
   Msg msg=(Msg)mCtx.getMsg(0);
   msg.reset();
   C2BConverter c2b=(C2BConverter)mCtx.getNote(C2B_NOTE);
  -
  -String slotName=TOMCAT: + host + : + port;
   
  -msg.appendByte( SHM_REGISTER_TOMCAT );
  +msg.appendByte( SHM_WRITE_SLOT );
   appendString( msg, slotName, c2b );
   
   this.invoke( msg, mCtx );
  
  
  

--
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 Shm.java

2002-04-25 Thread costin

costin  02/04/25 11:25:49

  Modified:jk/java/org/apache/jk/common Shm.java
  Log:
  Update to use the new jni communication.
  
  Started to add the main() and execute() to allow Shm to be called from
  CLI and ant - to register remote tomcats.
  
  Revision  ChangesPath
  1.4   +102 -55   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.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- Shm.java  18 Apr 2002 22:59:20 -  1.3
  +++ Shm.java  25 Apr 2002 18:25:49 -  1.4
  @@ -72,21 +72,22 @@
   import org.apache.jk.core.*;
   import org.apache.jk.apr.*;
   
  +import org.apache.tomcat.util.IntrospectionUtils;
  +
   
   /** Handle the shared memory objects.
*
* @author Costin Manolache
*/
  -public class Shm extends JkHandler {
  -
  -String jkHome;
  -String file;
  -
  -// Apr data. 
  -private long memP;
  -private long aprShmPoolP;
  -private long aprShmP;
  -private AprImpl apr;
  +public class Shm extends JniHandler {
  +String file=/tmp/shm.file;
  +int size;
  +
  +// Will be dynamic ( getMethodId() ) after things are stable 
  +static final int SHM_SET_ATTRIBUTE=0;
  +static final int SHM_REGISTER_TOMCAT=2;
  +static final int SHM_ATTACH=3;
  +static final int SHM_DETACH=4;
   
   public Shm() {
   }
  @@ -95,73 +96,119 @@
   file=f;
   }
   
  -/** 
  - */
  -public void setJkHome( String s ) {
  -jkHome=s;
  +public void setSize( int size ) {
  +this.size=size;
   }
   
   public void init() throws IOException {
  +super.initNative( shm );
   if( file==null ) {
   log.error(No shm file, disabling shared memory);
  +apr=null;
   return;
   }
  -try {
  -apr=(AprImpl)wEnv.getHandler(apr);
  -if( apr==null || ! apr.isLoaded() ) {
  -log.error( Apr unavailable, disabling shared memory  );
  -apr=null;
  -return;
  -}
   
  -aprShmPoolP=apr.poolCreate( 0 );
  +// Set properties and call init.
  +setNativeAttribute( file, file );
  +if( size  0 )
  +setNativeAttribute( size, Integer.toString( size ) );
  +attach();
  +}
   
  -aprShmP= apr.shmAttach( aprShmPoolP, file );
  +public void attach() throws IOException {
  +MsgContext mCtx=createMsgContext();
  +Msg msg=(Msg)mCtx.getMsg(0);
  +msg.reset();
   
  -if( aprShmP== 0 ) {
  -// no shared mem. This is normal result, but create should throw
  -log.info(Can't attach, try to create  + file );
  -aprShmP= apr.shmCreate( aprShmPoolP, 8196, file );
  -
  -}
  -if( aprShmP== 0 ) {
  -// no shared mem. This is normal result, but create should throw
  -log.info(Can't create  + file );
  -return;
  -}
  +msg.appendByte( SHM_ATTACH );
  +
  +this.invoke( msg, mCtx );
  +}
   
  -long base=apr.shmBaseaddrGet( aprShmPoolP, aprShmP );
  -long size=apr.shmSizeGet( aprShmPoolP, aprShmP );
  +public void setNativeAttribute(String name, String val) throws IOException {
  +MsgContext mCtx=createMsgContext();
  +Msg msg=(Msg)mCtx.getMsg(0);
  +C2BConverter c2b=(C2BConverter)mCtx.getNote(C2B_NOTE);
  +msg.reset();
   
  -log.info(Got shared memory at  + base +   + size );
  +msg.appendByte( SHM_SET_ATTRIBUTE );
   
  -byte b1[]=new byte[16];
  -
  -apr.shmRead( aprShmPoolP, base, b1, 0, b1.length );
  -
  -System.out.println(Read:  + new String( b1 ));
  -
  -byte helloW[]=hello World.getBytes();
  -
  -apr.shmWrite( aprShmPoolP, base, helloW, 0, helloW.length );
  -
  -} catch( Throwable ex ) {
  -log.error( Can't initialize shared memory  + ex.toString() );
  -apr=null;
  -}
  +appendString( msg, name, c2b);
  +
  +appendString(msg, val, c2b );
  +
  +this.invoke( msg, mCtx );
  +}
  +
  +public void registerTomcat(String host, int port)
  +throws IOException
  +{
  +MsgContext mCtx=createMsgContext();
  +Msg msg=(Msg)mCtx.getMsg(0);
  +msg.reset();
  +C2BConverter c2b=(C2BConverter)mCtx.getNote(C2B_NOTE);
  +
  +String slotName=TOMCAT: + host + : + port;
  +
  +msg.appendByte( SHM_REGISTER_TOMCAT );
  +appendString( 

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

2002-04-18 Thread costin

costin  02/04/18 15:59:20

  Modified:jk/java/org/apache/jk/apr AprImpl.java
   jk/java/org/apache/jk/common Shm.java
  Log:
  The java side of the changes.
  
  For now it's just a Hello World sent between Apache and tomcat,
  but it works fine - and that was the hard part.
  
  Now follows the hard part, implementing a protocol that is flexible enough
  to support both worker status but also config updates and other status
  and config info.
  
  Luckily there is a backup plan - to use the exact same format as in jserv
  ( at least to get things started )
  
  Revision  ChangesPath
  1.11  +25 -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.10
  retrieving revision 1.11
  diff -u -r1.10 -r1.11
  --- AprImpl.java  18 Apr 2002 17:42:26 -  1.10
  +++ AprImpl.java  18 Apr 2002 22:59:20 -  1.11
  @@ -94,10 +94,35 @@
   
   public native long shmAttach( long pool, String file );
   
  +public native long shmCreate( long pool, long size, String file );
  +
  +public native long shmBaseaddrGet( long pool, long shmP );
  +
  +public native long shmSizeGet( long pool, long shmP );
  +
   public native long shmDetach( long pool, long shmP );
   
   public native long shmDestroy( long pool, long shmP );
   
  +public native int shmRead( long pool, long mP, 
  +   byte buf[], int off, int len );
  +
  +public native int shmWrite( long pool, long mP, 
  +byte buf[], int off, int len );
  +
  +
  +//  Mutexes 
  +
  +public native long mutexCreate( long pool, String file, int type );
  +
  +public native long mutexLock( long pool, long mutexP );
  +
  +public native long mutexUnLock( long pool, long mutexP );
  +
  +public native long mutexTryLock( long pool, long mutexP );
  +
  +public native long mutexDestroy( long pool, long mutexP );
  +
   //   java to C 
   
   // Temp - interface will evolve
  
  
  
  1.3   +22 -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.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- Shm.java  18 Apr 2002 17:44:49 -  1.2
  +++ Shm.java  18 Apr 2002 22:59:20 -  1.3
  @@ -121,9 +121,30 @@
   if( aprShmP== 0 ) {
   // no shared mem. This is normal result, but create should throw
   log.info(Can't attach, try to create  + file );
  +aprShmP= apr.shmCreate( aprShmPoolP, 8196, file );
  +
   }
  +if( aprShmP== 0 ) {
  +// no shared mem. This is normal result, but create should throw
  +log.info(Can't create  + file );
  +return;
  +}
  +
  +long base=apr.shmBaseaddrGet( aprShmPoolP, aprShmP );
  +long size=apr.shmSizeGet( aprShmPoolP, aprShmP );
  +
  +log.info(Got shared memory at  + base +   + size );
  +
  +byte b1[]=new byte[16];
  +
  +apr.shmRead( aprShmPoolP, base, b1, 0, b1.length );
  +
  +System.out.println(Read:  + new String( b1 ));
  +
  +byte helloW[]=hello World.getBytes();
  +
  +apr.shmWrite( aprShmPoolP, base, helloW, 0, helloW.length );
   
  -//XXX not implemented.
   } catch( Throwable ex ) {
   log.error( Can't initialize shared memory  + ex.toString() );
   apr=null;
  
  
  

--
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 Shm.java

2002-04-17 Thread costin

costin  02/04/17 15:36:04

  Added:   jk/java/org/apache/jk/common Shm.java
  Log:
  A simple component that will automatically register the tomcat workers in
  the jk 'scoreboard'.
  
  Getting this to work is the last step in supporting multi-process JNI and
  dynamic addition/removal/status of workers for jk.
  
  So far attach() seems to work ( and I'm not sure if tomcat should create the
  shmem ).
  
  The data structures in the shm will be very similar with what jserv used to have,
  but more flexible.
  
  We may also need to add some mutexes - or at least atomic operations from
  APR.
  
  Revision  ChangesPath
  1.1  jakarta-tomcat-connectors/jk/java/org/apache/jk/common/Shm.java
  
  Index: Shm.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.*;
  
  
  /** Handle the shared memory objects.
   *
   * @author Costin Manolache
   */
  public class Shm extends JkHandler {
  
  String jkHome;
  String file;
  
  // Apr data. 
  private long memP;
  private long aprShmPoolP;
  private long aprShmP;
  private AprImpl apr;
  
  public Shm() {
  }
  
  public void setFile( String f ) {
  file=f;
  }
  
  /** 
   */
  public void setJkHome( String s ) {
  jkHome=s;
  }
  
  public void init() throws IOException {
  if( file==null ) {
  log.error(No shm file, disabling shared memory);
  return;
  }
  try {
  apr=(AprImpl)wEnv.getHandler(apr);
  if( apr==null ) {
  log.error( Apr unavailable, disabling shared memory  );
  return;
  }
  
  aprShmPoolP=apr.poolCreate( 0 );
  
  aprShmP= apr.shmAttach( aprShmPoolP, file );
  
  if( aprShmP== 0 ) {