tomcat-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From billbar...@apache.org
Subject cvs commit: jakarta-tomcat/src/facade22/org/apache/tomcat/facade Servlet22Interceptor.java ServletHandler.java
Date Sat, 27 Oct 2001 02:55:20 GMT
billbarker    01/10/26 19:55:20

  Modified:    src/facade22/org/apache/tomcat/facade
                        Servlet22Interceptor.java ServletHandler.java
  Log:
  Add pooling support for STM servlets.
  
  At long last, Tomcat catches up with JServe ;). This is slightly modified from the original
patch to make configuration simplier.  Servlet22Interceptor now has two new options:
  useSTMPool: use Pool if true, old behavior else. Default: true.
  STMPoolSize: size of Pool (has no effect if previous is false).
  
  I'm defaulting to using STM pooling since most of the STM users seem to be coming off of
JServe, which did pooling.
  Submitted by:	David Schreibman DSchrebman@eTranslate.com
  
  Revision  Changes    Path
  1.19      +17 -2     jakarta-tomcat/src/facade22/org/apache/tomcat/facade/Servlet22Interceptor.java
  
  Index: Servlet22Interceptor.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat/src/facade22/org/apache/tomcat/facade/Servlet22Interceptor.java,v
  retrieving revision 1.18
  retrieving revision 1.19
  diff -u -r1.18 -r1.19
  --- Servlet22Interceptor.java	2001/09/23 00:21:40	1.18
  +++ Servlet22Interceptor.java	2001/10/27 02:55:20	1.19
  @@ -61,6 +61,7 @@
   package org.apache.tomcat.facade;
   
   import org.apache.tomcat.util.*;
  +import org.apache.tomcat.util.collections.SimplePool;
   import org.apache.tomcat.core.*;
   import java.io.*;
   import java.net.*;
  @@ -82,6 +83,8 @@
       extends BaseInterceptor
   {
       public static final String SERVLET_STAMP = " ( JSP 1.1; Servlet 2.2 )";
  +    private int stmPoolSize = SimplePool.DEFAULT_SIZE;
  +    private boolean useStmPool = true;
   	
       public Servlet22Interceptor() {
       }
  @@ -89,6 +92,13 @@
       public Servlet22Interceptor(Context ctx) {
       }
   
  +    public void setSTMPoolSize(int size) {
  +	stmPoolSize = size;
  +    }
  +    public void setUseSTMPool(boolean use) {
  +	useStmPool = use;
  +    }
  +
       // -------------------- implementation
       private void setEngineHeader(Context ctx) {
           String engineHeader=ctx.getEngineHeader();
  @@ -145,7 +155,8 @@
       {
   	String hN=ct.getHandlerName();
   	if( hN == null ) return;
  -			     
  +	
  +
   	if( ct.getHandler() == null ) {
   	    // we have a container with a valid handler name but without
   	    // a Handler. Create a ServletWrapper
  @@ -160,8 +171,12 @@
   	    handler.setModule( this );
   	    ct.setHandler(handler);
   	    ct.getContext().addServlet( handler );
  +	} 
  +	if(ct.getHandler() instanceof ServletHandler) {
  +	    ServletHandler handler = (ServletHandler)ct.getHandler();
  +	    handler.setSTMPoolSize(stmPoolSize);
  +	    handler.setUseSTMPool(useStmPool);
   	}
  -	    
       }
   
   
  
  
  
  1.18      +72 -6     jakarta-tomcat/src/facade22/org/apache/tomcat/facade/ServletHandler.java
  
  Index: ServletHandler.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat/src/facade22/org/apache/tomcat/facade/ServletHandler.java,v
  retrieving revision 1.17
  retrieving revision 1.18
  diff -u -r1.17 -r1.18
  --- ServletHandler.java	2001/09/18 02:37:40	1.17
  +++ ServletHandler.java	2001/10/27 02:55:20	1.18
  @@ -59,7 +59,8 @@
   package org.apache.tomcat.facade;
   
   import org.apache.tomcat.core.*;
  -import org.apache.tomcat.util.*;
  +import org.apache.tomcat.util.collections.*;
  +
   import java.io.*;
   import java.net.*;
   import java.util.*;
  @@ -111,6 +112,12 @@
       private ServletInfo sw;
   
       private String servletClassName;
  +
  +    private SimplePool stmPool=null;
  +    private int stmPoolSize=SimplePool.DEFAULT_SIZE;
  +    private int stmInstances=0;
  +    private boolean useStmPool=true;
  +
       protected Class servletClass;
       protected Servlet servlet;
       protected Context context;
  @@ -131,7 +138,14 @@
       public void setServletInfo( ServletInfo sw ) {
   	this.sw=sw;
       }
  -    
  +
  +    public void setUseSTMPool(boolean useP){
  +	useStmPool = useP;
  +    }
  +    public void setSTMPoolSize(int size) {
  +	stmPoolSize = size;
  +    }
  +
       public ServletInfo getServletInfo() {
   	if( sw==null ) {
   	    // it is possible to create a handler without ServletInfo
  @@ -330,6 +344,13 @@
   	}
   	
   	servlet = (Servlet)servletClass.newInstance();
  +	if (useStmPool && ( servlet instanceof SingleThreadModel )) {
  +	    if(stmPool == null){
  +		stmPool = new SimplePool(stmPoolSize);
  +	    }
  +	    stmPool.put(servlet);
  +	    stmInstances++;
  +	}
   	return servlet;
       }
   
  @@ -347,8 +368,16 @@
   			} catch( TomcatException ex) {
   			    log(context, "preServletDestroy", ex);
   			}
  +		    }
  +		    if(useStmPool && (servlet instanceof SingleThreadModel)){
  +			Servlet sl=null;
  +			while((sl = (Servlet)stmPool.get()) != null){
  +			    sl.destroy();
  +			}
  +			stmInstances=0;
  +		    } else {
  +			servlet.destroy();
   		    }
  -		    servlet.destroy();
   
   		    for( int i=0; i< cI.length; i++ ) {
   			try {
  @@ -432,7 +461,40 @@
   	super.service( req, res );
       }
   
  -    
  +    protected void doSTMService(HttpServletRequest reqF, HttpServletResponse resF) 
  +	throws Exception {
  +	Servlet sl = null;
  +	try {
  +	    boolean newInstance = false;
  +	    if ((sl = (Servlet)stmPool.get()) == null) {
  +		synchronized (this) {
  +		    if (stmInstances < stmPoolSize) {
  +			stmInstances++;
  +			newInstance = true;
  +		    }
  +		}
  +		if (newInstance) {
  +		    sl = (Servlet)servletClass.newInstance();
  +		    sl.init(getServletInfo().getServletConfig());
  +		} else {
  +		 /* The pool is full, just synchronize on the initial instance.
  +		    Ideally, we would the pain across all pooled instances
  +		    to avoid a bottleneck on a single instance. */
  +		    sl = servlet;
  +		}
  +	    }
  +	    /* Since this may be the initial instance, we still need to
  +	       synchronize here */
  +	    synchronized(sl) {
  +		sl.service(reqF, resF);
  +	    }
  +	} finally {
  +	    if (sl != null) {
  +		stmPool.put(sl);
  +	    }
  +	}
  +    }
  +         
       protected void doService(Request req, Response res)
   	throws Exception
       {
  @@ -477,8 +539,12 @@
   	try {
   	    // We are initialized and fine
   	    if (servlet instanceof SingleThreadModel) {
  -		synchronized(servlet) {
  -		    servlet.service(reqF, resF);
  +		if(useStmPool) {
  +		    doSTMService(reqF,resF);
  +		} else {
  +		    synchronized(servlet) {
  +			servlet.service(reqF, resF);
  +		    }
   		}
   	    } else {
   		servlet.service(reqF, resF);
  
  
  

Mime
View raw message