billbarker 2004/01/26 22:43:18
Modified: jk/java/org/apache/jk/common ChannelSocket.java
JniHandler.java
jk/java/org/apache/jk/core JkHandler.java
jk/java/org/apache/jk/server JkCoyoteHandler.java
JkMain.java
Log:
Adding support for the new pause/resume protocol.
Revision Changes Path
1.39 +55 -15
jakarta-tomcat-connectors/jk/java/org/apache/jk/common/ChannelSocket.java
Index: ChannelSocket.java
===================================================================
RCS file:
/home/cvs/jakarta-tomcat-connectors/jk/java/org/apache/jk/common/ChannelSocket.java,v
retrieving revision 1.38
retrieving revision 1.39
diff -u -r1.38 -r1.39
--- ChannelSocket.java 16 Jan 2004 06:48:20 -0000 1.38
+++ ChannelSocket.java 27 Jan 2004 06:43:18 -0000 1.39
@@ -277,13 +277,38 @@
/* ==================== ==================== */
ServerSocket sSocket;
- int socketNote=1;
- int isNote=2;
- int osNote=3;
- int notifNote=4;
+ final int socketNote=1;
+ final int isNote=2;
+ final int osNote=3;
+ final int notifNote=4;
+ boolean paused = false;
+
+ public void pause() throws Exception {
+ synchronized(this) {
+ paused = true;
+ unLockSocket();
+ }
+ }
+
+ public void resume() throws Exception {
+ synchronized(this) {
+ paused = false;
+ notify();
+ }
+ }
+
public void accept( MsgContext ep ) throws IOException {
if( sSocket==null ) return;
+ synchronized(this) {
+ while(paused) {
+ try{
+ wait();
+ } catch(InterruptedException ie) {
+ //Ignore, since can't happen
+ }
+ }
+ }
Socket s=sSocket.accept();
ep.setNote( socketNote, s );
if(log.isDebugEnabled() )
@@ -412,6 +437,20 @@
s.close();
}
+ private void unLockSocket() throws IOException {
+ // Need to create a connection to unlock the accept();
+ Socket s;
+ if (inet == null) {
+ s=new Socket("127.0.0.1", port );
+ }else{
+ s=new Socket(inet, port );
+ // setting soLinger to a small value will help shutdown the
+ // connection quicker
+ s.setSoLinger(true, 0);
+ }
+ s.close();
+ }
+
public void destroy() throws IOException {
running = false;
try {
@@ -420,17 +459,10 @@
return;
tp.shutdown();
- // Need to create a connection to unlock the accept();
- Socket s;
- if (inet == null) {
- s=new Socket("127.0.0.1", port );
- }else{
- s=new Socket(inet, port );
- // setting soLinger to a small value will help shutdown the
- // connection quicker
- s.setSoLinger(true, 0);
- }
- s.close();
+ if(!paused) {
+ unLockSocket();
+ }
+
sSocket.close(); // XXX?
if( tpOName != null ) {
@@ -575,6 +607,11 @@
log.debug("Accepting ajp connections on " + port);
while( running ) {
try {
+ synchronized(this) {
+ while(paused) {
+ wait();
+ }
+ }
MsgContext ep=new MsgContext();
ep.setSource(this);
ep.setWorkerEnv( wEnv );
@@ -600,6 +637,9 @@
try {
MsgAjp recv=new MsgAjp();
while( running ) {
+ if(paused) { // Drop the connection on pause
+ break;
+ }
int status= this.receive( recv, ep );
if( status <= 0 ) {
if( status==-3)
1.14 +25 -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.13
retrieving revision 1.14
diff -u -r1.13 -r1.14
--- JniHandler.java 18 Sep 2003 16:21:00 -0000 1.13
+++ JniHandler.java 27 Jan 2004 06:43:18 -0000 1.14
@@ -103,6 +103,7 @@
public static final int MSG_NOTE=0;
public static final int C2B_NOTE=1;
public static final int MB_NOTE=2;
+ private boolean paused = false;
public JniHandler() {
@@ -177,11 +178,35 @@
msg.appendByteChunk( bc );
}
+ public void pause() throws Exception {
+ synchronized(this) {
+ paused = true;
+ }
+ }
+
+ public void resume() throws Exception {
+ synchronized(this) {
+ paused = false;
+ notifyAll();
+ }
+ }
+
+
/** Create a msg context to be used with the shm channel
*/
public MsgContext createMsgContext() {
if( nativeJkHandlerP==0 || apr==null )
return null;
+
+ synchronized(this) {
+ try{
+ while(paused) {
+ wait();
+ }
+ }catch(InterruptedException ie) {
+ // Ignore, since it can't happen
+ }
+ }
try {
MsgContext msgCtx=new MsgContext();
1.15 +6 -0
jakarta-tomcat-connectors/jk/java/org/apache/jk/core/JkHandler.java
Index: JkHandler.java
===================================================================
RCS file:
/home/cvs/jakarta-tomcat-connectors/jk/java/org/apache/jk/core/JkHandler.java,v
retrieving revision 1.14
retrieving revision 1.15
diff -u -r1.14 -r1.15
--- JkHandler.java 16 Jan 2004 06:48:20 -0000 1.14
+++ JkHandler.java 27 Jan 2004 06:43:18 -0000 1.15
@@ -229,4 +229,10 @@
public void postDeregister() {
}
+ public void pause() throws Exception {
+ }
+
+ public void resume() throws Exception {
+ }
+
}
1.50 +2 -2
jakarta-tomcat-connectors/jk/java/org/apache/jk/server/JkCoyoteHandler.java
Index: JkCoyoteHandler.java
===================================================================
RCS file:
/home/cvs/jakarta-tomcat-connectors/jk/java/org/apache/jk/server/JkCoyoteHandler.java,v
retrieving revision 1.49
retrieving revision 1.50
diff -u -r1.49 -r1.50
--- JkCoyoteHandler.java 26 Jan 2004 18:16:44 -0000 1.49
+++ JkCoyoteHandler.java 27 Jan 2004 06:43:18 -0000 1.50
@@ -236,11 +236,11 @@
}
public void pause() throws Exception {
- // FIXME
+ getJkMain().pause();
}
public void resume() throws Exception {
- // FIXME
+ getJkMain().resume();
}
public void destroy() {
1.43 +17 -0
jakarta-tomcat-connectors/jk/java/org/apache/jk/server/JkMain.java
Index: JkMain.java
===================================================================
RCS file:
/home/cvs/jakarta-tomcat-connectors/jk/java/org/apache/jk/server/JkMain.java,v
retrieving revision 1.42
retrieving revision 1.43
diff -u -r1.42 -r1.43
--- JkMain.java 18 Sep 2003 16:21:02 -0000 1.42
+++ JkMain.java 27 Jan 2004 06:43:18 -0000 1.43
@@ -692,4 +692,21 @@
public void postDeregister() {
}
+ public void pause() throws Exception {
+ for( int i=0; i<wEnv.getHandlerCount(); i++ ) {
+ if( wEnv.getHandler(i) != null ) {
+ wEnv.getHandler(i).pause();
+ }
+ }
+ }
+
+ public void resume() throws Exception {
+ for( int i=0; i<wEnv.getHandlerCount(); i++ ) {
+ if( wEnv.getHandler(i) != null ) {
+ wEnv.getHandler(i).resume();
+ }
+ }
+ }
+
+
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]