You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by co...@locus.apache.org on 2000/09/25 01:03:14 UTC
cvs commit: jakarta-tomcat/src/share/org/apache/tomcat/util/threads Reaper.java
costin 00/09/24 16:03:14
Modified: src/facade22/org/apache/tomcat/facade
HttpServletRequestFacade.java
src/share/org/apache/tomcat/core Request.java
src/share/org/apache/tomcat/session ServerSession.java
StandardSessionInterceptor.java
src/share/org/apache/tomcat/util SimplePool.java
src/share/org/apache/tomcat/util/threads Reaper.java
Added: src/share/org/apache/tomcat/session
ServerSessionManager.java
Removed: src/share/org/apache/tomcat/session StandardManager.java
StandardSession.java
Log:
Session management refactoring - re-use existing code ( Reaper, etc),
simplify the internal objects, better reuse. Less redundant comments, but
a bit more documentation on special cases.
This is based on the original tomcat design, plus session reloading code
from StandardManager.
Revision Changes Path
1.4 +3 -3 jakarta-tomcat/src/facade22/org/apache/tomcat/facade/HttpServletRequestFacade.java
Index: HttpServletRequestFacade.java
===================================================================
RCS file: /home/cvs/jakarta-tomcat/src/facade22/org/apache/tomcat/facade/HttpServletRequestFacade.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- HttpServletRequestFacade.java 2000/09/24 20:01:43 1.3
+++ HttpServletRequestFacade.java 2000/09/24 23:03:12 1.4
@@ -385,13 +385,14 @@
// -------------------- Session --------------------
public HttpSession getSession() {
- return (HttpSession)request.getSession(true);
+ return getSession(true);
}
/** Create the Facade for session.
*/
public HttpSession getSession(boolean create) {
ServerSession realSession = (ServerSession)request.getSession(create);
+
// No real session, return null
if( realSession == null ) {
if( sessionFacade!= null) sessionFacade.recycle();
@@ -410,8 +411,7 @@
public boolean isRequestedSessionIdValid() {
// so here we just assume that if we have a session it's,
// all good, else not.
- HttpSession session = (HttpSession)request.getSession(false);
- return (session != null);
+ return null != request.getSession(false);
}
/** Adapter - Request uses getSessionIdSource
1.61 +7 -0 jakarta-tomcat/src/share/org/apache/tomcat/core/Request.java
Index: Request.java
===================================================================
RCS file: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/core/Request.java,v
retrieving revision 1.60
retrieving revision 1.61
diff -u -r1.60 -r1.61
--- Request.java 2000/09/24 20:01:44 1.60
+++ Request.java 2000/09/24 23:03:12 1.61
@@ -449,6 +449,9 @@
this.jvmRoute=jvmRoute;
}
+ /** Session ID requested by client as a cookie or any other
+ * method. It may be a valid ( and existing ) session or not.
+ */
public String getRequestedSessionId() {
return reqSessionId;
}
@@ -457,6 +460,8 @@
this.reqSessionId = reqSessionId;
}
+ /** Method used to determine requestedSessionId
+ */
public String getSessionIdSource() {
return sessionIdSource;
}
@@ -465,6 +470,8 @@
sessionIdSource=s;
}
+ /** "Real" session Id, coresponding to an existing ServerSession
+ */
public void setSessionId( String id ) {
if( ! response.isIncluded() ) sessionId=id;
}
1.5 +0 -14 jakarta-tomcat/src/share/org/apache/tomcat/session/ServerSession.java
Index: ServerSession.java
===================================================================
RCS file: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/session/ServerSession.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- ServerSession.java 2000/09/24 20:01:46 1.4
+++ ServerSession.java 2000/09/24 23:03:13 1.5
@@ -114,20 +114,6 @@
distributable=b;
}
-
-// // XXX XXX XXX
-// public void setId(String id) {
-
-// if ((this.id != null) && (manager != null))
-// manager.remove(this);
-
-// this.id = id;
-
-// if ((manager != null) )
-// manager.add(this);
-
-// }
-
// --------------------
/**
1.10 +41 -31 jakarta-tomcat/src/share/org/apache/tomcat/session/StandardSessionInterceptor.java
Index: StandardSessionInterceptor.java
===================================================================
RCS file: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/session/StandardSessionInterceptor.java,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -r1.9 -r1.10
--- StandardSessionInterceptor.java 2000/09/24 20:01:47 1.9
+++ StandardSessionInterceptor.java 2000/09/24 23:03:13 1.10
@@ -56,8 +56,6 @@
* [Additional notices, if required by prior licensing conditions]
*
*/
-
-
package org.apache.tomcat.session;
import java.io.IOException;
@@ -69,6 +67,7 @@
import org.apache.tomcat.util.*;
import org.apache.tomcat.core.*;
+
/**
* This is the adapter between tomcat and a StandardManager.
* A session manager should not depend on tomcat internals - so you can
@@ -92,15 +91,11 @@
public StandardSessionInterceptor() {
}
- // -------------------- Internal methods --------------------
- private StandardManager getManager( Context ctx ) {
- return (StandardManager)ctx.getContainer().getNote(manager_note);
- }
+ // -------------------- Configuration properties --------------------
- private void setManager( Context ctx, StandardManager sm ) {
- ctx.getContainer().setNote( manager_note, sm );
- }
-
+
+
+
// -------------------- Tomcat request events --------------------
public void engineInit( ContextManager cm ) throws TomcatException {
// set-up a per/container note for StandardManager
@@ -110,13 +105,13 @@
/**
* StandardManager will set the HttpSession if one is found.
- *
*/
public int requestMap(Request request ) {
String sessionId = null;
Context ctx=request.getContext();
if( ctx==null ) {
- log( "Configuration error in StandardSessionInterceptor - no context " + request );
+ log( "Configuration error in StandardSessionInterceptor " +
+ " - no context " + request );
return 0;
}
@@ -128,26 +123,28 @@
// multiple Session cookies (one for the root
// context and one for the real context... or old session
// cookie. We must check for validity in the current context.
- StandardManager sM = getManager( ctx );
- HttpSession sess= sM.findSession( sessionId );
+ ServerSessionManager sM = getManager( ctx );
+ ServerSession sess= sM.findSession( sessionId );
+ // log("Try to find: " + sessionId );
if(null != sess) {
- // log( "Found session");
+ sess.getTimeStamp().touch( System.currentTimeMillis() );
+ //log("Session found " + sessionId );
// set it only if nobody else did !
if( null == request.getSession( false ) ) {
request.setSession( sess );
- request.setSessionId( sess.getId());
- // log("Session set ");
+ // XXX use MessageBytes!
+ request.setSessionId( sessionId );
+ //log("Session set " + sessionId );
}
}
return 0;
}
- // log( "No session ");
return 0;
}
public void reload( Request req, Context ctx ) {
ClassLoader newLoader = ctx.getClassLoader();
- StandardManager sM = getManager( ctx );
+ ServerSessionManager sM = getManager( ctx );
sM.handleReload(req, newLoader);
if (req.getSession(false) != null) {
// replace the current session in the current request
@@ -163,12 +160,13 @@
Context ctx=request.getContext();
if( ctx==null ) return 0;
- StandardManager sM = getManager( ctx );
+ ServerSessionManager sM = getManager( ctx );
if( request.getSession( false ) != null )
return 0; // somebody already set the session
- HttpSession newS=sM.getNewSession();
+ ServerSession newS=sM.getNewSession();
request.setSession( newS );
+ request.setSessionId( newS.getId().toString());
return 0;
}
@@ -178,14 +176,15 @@
* sessions.
*/
public int postService( Request rrequest, Response response ) {
- Context ctx=rrequest.getContext();
- if( ctx==null ) return 0;
+ // Not used, maybe add it back later if we need to
- StandardManager sm= getManager( ctx );
- HttpSession sess=(HttpSession)rrequest.getSession(false);
- if( sess == null ) return 0;
-
- sm.release( sess );
+ // Context ctx=rrequest.getContext();
+ // if( ctx==null ) return 0;
+
+ // ServerSessionManager sm= getManager( ctx );
+ // HttpSession sess=(HttpSession)rrequest.getSession(false);
+ // if( sess == null ) return 0;
+ // sm.release( sess );
return 0;
}
@@ -197,10 +196,10 @@
*/
public void contextInit(Context ctx) throws TomcatException {
// Defaults !!
- StandardManager sm= getManager( ctx );
+ ServerSessionManager sm= getManager( ctx );
if( sm == null ) {
- sm=new StandardManager();
+ sm=new ServerSessionManager();
setManager(ctx, sm);
}
@@ -223,7 +222,7 @@
throws TomcatException
{
if( ctx.getDebug() > 0 ) ctx.log("Removing sessions from " + ctx );
- StandardManager sm=getManager(ctx);
+ ServerSessionManager sm=getManager(ctx);
try {
if( sm != null )
sm.stop();
@@ -231,4 +230,15 @@
throw new TomcatException( ex );
}
}
+
+ // -------------------- Internal methods --------------------
+ private ServerSessionManager getManager( Context ctx ) {
+ return (ServerSessionManager)ctx.getContainer().getNote(manager_note);
+ }
+
+ private void setManager( Context ctx, Object sm ) {
+ ctx.getContainer().setNote( manager_note, sm );
+ }
+
+
}
1.6 +222 -89 jakarta-tomcat/src/share/org/apache/tomcat/session/ServerSessionManager.java
1.4 +7 -4 jakarta-tomcat/src/share/org/apache/tomcat/util/SimplePool.java
Index: SimplePool.java
===================================================================
RCS file: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/util/SimplePool.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- SimplePool.java 2000/05/26 17:32:17 1.3
+++ SimplePool.java 2000/09/24 23:03:13 1.4
@@ -1,8 +1,4 @@
/*
- * $Header: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/util/SimplePool.java,v 1.3 2000/05/26 17:32:17 costin Exp $
- * $Revision: 1.3 $
- * $Date: 2000/05/26 17:32:17 $
- *
* ====================================================================
*
* The Apache Software License, Version 1.1
@@ -89,7 +85,14 @@
private int current=-1;
Object lock;
+ public static final int DEFAULT_SIZE=16;
+ public SimplePool() {
+ this.max=DEFAULT_SIZE;
+ pool=new Object[max];
+ lock=new Object();
+ }
+
public SimplePool(int max) {
this.max=max;
pool=new Object[max];
1.2 +17 -2 jakarta-tomcat/src/share/org/apache/tomcat/util/threads/Reaper.java
Index: Reaper.java
===================================================================
RCS file: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/util/threads/Reaper.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- Reaper.java 2000/08/28 03:14:09 1.1
+++ Reaper.java 2000/09/24 23:03:14 1.2
@@ -75,7 +75,12 @@
this.setName("TomcatReaper");
}
- private int interval = 1000 * 60; //ms
+ public Reaper(String name) {
+ this.setDaemon(true);
+ this.setName(name);
+ }
+
+ private long interval = 1000 * 60; //ms
// XXX TODO Allow per/callback interval, find next, etc
// Right now the "interval" is used for all callbacks
@@ -89,6 +94,10 @@
*/
Object lock=new Object();
static boolean running=true;
+
+ public void setDefaultInterval( long t ) {
+ interval=t;
+ }
public int addCallback( ThreadPoolRunnable c, int interval ) {
synchronized( lock ) {
@@ -106,6 +115,11 @@
}
}
+ public void startReaper() {
+ running=true;
+ this.start();
+ }
+
public void stopReaper() {
running=false;
this.notify();
@@ -118,7 +132,8 @@
} catch (InterruptedException ie) {
// sometimes will happen
}
-
+
+ if( !running) return;
for( int i=0; i< count; i++ ) {
ThreadPoolRunnable callB=cbacks[i];
// it may be null if a callback is removed.