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/05/12 08:15:25 UTC

cvs commit: jakarta-tomcat/src/share/org/apache/tomcat/session StandardManager.java StandardSessionManager.java

costin      00/05/11 23:15:25

  Modified:    src/share/org/apache/tomcat/context DefaultCMSetter.java
               src/share/org/apache/tomcat/core RequestImpl.java
                        SessionManager.java
               src/share/org/apache/tomcat/request SessionInterceptor.java
               src/share/org/apache/tomcat/session StandardManager.java
  Removed:     src/share/org/apache/tomcat/session
                        StandardSessionManager.java
  Log:
  - Finally moved SessionManager to Context level, as requested (and agreed) long time ago.
  
  - Removed StandardSessionManager - now StandardManager can implement SessionManager, it
  no longer have the big impedance problem ( both are now at context level )
  
  - Made all the changes related with that.
  
  Note that Session management is more or less orthogonal to the main function of
  executing requests.  There is no reason to have too tight coupling between
  those components.
  
  It should be easy to plug in other module ( like the one from JServ or Catalina ),
  the interface SessionManager have _nothing_ specific to tomcat.
  
  We need some hooks for re-loading - whatever Jon adds is fine ( probably it will not
  be specific to tomcat ).
  
  Next: documentation, beautify the code, keep only the essential.
  
  Revision  Changes    Path
  1.32      +5 -2      jakarta-tomcat/src/share/org/apache/tomcat/context/DefaultCMSetter.java
  
  Index: DefaultCMSetter.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/context/DefaultCMSetter.java,v
  retrieving revision 1.31
  retrieving revision 1.32
  diff -u -r1.31 -r1.32
  --- DefaultCMSetter.java	2000/05/09 17:56:08	1.31
  +++ DefaultCMSetter.java	2000/05/12 06:15:22	1.32
  @@ -159,8 +159,11 @@
   	ctx.setAttribute(Constants.ATTRIB_WORKDIR , ctx.getWorkDir());
   
   	// Set default session manager if none set
  -	if( ctx.getSessionManager() == null )
  -	    ctx.setSessionManager(new org.apache.tomcat.session.StandardSessionManager());
  +	if( ctx.getSessionManager() == null ) {
  +	    SessionManager sm=new org.apache.tomcat.session.StandardManager();
  +	    sm.setContext(ctx);
  +	    ctx.setSessionManager(sm);
  +	}
   	//  Alternative: org.apache.tomcat.session.ServerSessionManager.getManager();
   
   	ServletWrapper authWrapper=new ServletWrapper();
  
  
  
  1.34      +5 -5      jakarta-tomcat/src/share/org/apache/tomcat/core/RequestImpl.java
  
  Index: RequestImpl.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/core/RequestImpl.java,v
  retrieving revision 1.33
  retrieving revision 1.34
  diff -u -r1.33 -r1.34
  --- RequestImpl.java	2000/05/12 02:19:59	1.33
  +++ RequestImpl.java	2000/05/12 06:15:23	1.34
  @@ -1,7 +1,7 @@
   /*
  - * $Header: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/core/RequestImpl.java,v 1.33 2000/05/12 02:19:59 costin Exp $
  - * $Revision: 1.33 $
  - * $Date: 2000/05/12 02:19:59 $
  + * $Header: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/core/RequestImpl.java,v 1.34 2000/05/12 06:15:23 costin Exp $
  + * $Revision: 1.34 $
  + * $Date: 2000/05/12 06:15:23 $
    *
    * ====================================================================
    *
  @@ -433,7 +433,7 @@
   	// if the interceptors found a request id, use it
   	if( reqSessionId != null ) {
   	    // we have a session !
  -	    serverSession=sM.findSession( context, reqSessionId );
  +	    serverSession=sM.findSession( reqSessionId );
   	    if( serverSession!=null) return serverSession;
   	}
   
  @@ -441,7 +441,7 @@
   	    return null;
   
   	// no session exists, create flag
  -	serverSession =sM.createSession( context );
  +	serverSession =sM.createSession( );
   	reqSessionId = serverSession.getId();
   
   	// XXX XXX will be changed - post-request Interceptors
  
  
  
  1.4       +6 -10     jakarta-tomcat/src/share/org/apache/tomcat/core/SessionManager.java
  
  Index: SessionManager.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/core/SessionManager.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- SessionManager.java	2000/03/01 07:51:41	1.3
  +++ SessionManager.java	2000/05/12 06:15:23	1.4
  @@ -74,6 +74,8 @@
    */
   public interface SessionManager {
   
  +    public void setContext( Context ctx );
  +    
       /**
        * Construct and return a new session object, based on the default
        * settings specified by this Manager's properties.  The session
  @@ -85,20 +87,14 @@
        * @exception IllegalStateException if a new session cannot be
        *  instantiated for any reason
        */
  -    public HttpSession createSession(Context ctx);
  +    public HttpSession createSession();
   
   
       /** Will mark the session lastAccess time.
        *  Will be called for each request that has a valid sessionId
        *
  -     *  A simple SessionManager will just use the id, a complex
  -     * manager may use the ctx and req to do additional work.
  -     *
  -     * @param ctx the context where the request belong
  -     * @param req the request having the id
  -     * @param id
        */
  -    public void accessed(Context ctx, Request req, String id);
  +    public void accessed(HttpSession s);
       //  we can pass only Request, as it contains both, but it's better to
       // show explicitely what this method uses.
   
  @@ -115,12 +111,12 @@
        * @exception IllegalStateException if a new session cannot be
        *  instantiated for any reason
        */
  -    public HttpSession findSession(Context ctx, String id);
  +    public HttpSession findSession(String id);
   
   
       /** Used by context when stoped, need to remove all sessions used by that context
        */
  -    public void removeSessions( Context ctx );
  +    public void removeSessions();
   
       /**
        * Used by context to configure the session manager's inactivity timeout.
  
  
  
  1.18      +5 -3      jakarta-tomcat/src/share/org/apache/tomcat/request/SessionInterceptor.java
  
  Index: SessionInterceptor.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/request/SessionInterceptor.java,v
  retrieving revision 1.17
  retrieving revision 1.18
  diff -u -r1.17 -r1.18
  --- SessionInterceptor.java	2000/05/02 22:39:58	1.17
  +++ SessionInterceptor.java	2000/05/12 06:15:23	1.18
  @@ -194,9 +194,11 @@
   	    // cookie. We must check for validity in the current context.
   	    Context ctx=request.getContext();
   	    SessionManager sM = ctx.getSessionManager();    
  -	    if(null != sM.findSession(ctx, sessionId)) {
  -		sM.accessed(ctx, request, sessionId );
  +	    HttpSession sess= sM.findSession( sessionId );
  +	    if(null != sess) {
  +		sM.accessed( sess );
   		request.setRequestedSessionId(sessionId);
  +		request.setSession( sess );
   		if( debug>0 ) cm.log(" Final session id " + sessionId );
   		return sessionId;
   	    }
  @@ -250,7 +252,7 @@
   	throws TomcatException
       {
   	if( ctx.getDebug() > 0 ) ctx.log("Removing sessions from " + ctx );
  -	ctx.getSessionManager().removeSessions(ctx);
  +	ctx.getSessionManager().removeSessions();
       }
   
   
  
  
  
  1.5       +65 -71    jakarta-tomcat/src/share/org/apache/tomcat/session/StandardManager.java
  
  Index: StandardManager.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/session/StandardManager.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- StandardManager.java	2000/05/12 02:31:58	1.4
  +++ StandardManager.java	2000/05/12 06:15:24	1.5
  @@ -1,7 +1,7 @@
   /*
  - * $Header: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/session/StandardManager.java,v 1.4 2000/05/12 02:31:58 costin Exp $
  - * $Revision: 1.4 $
  - * $Date: 2000/05/12 02:31:58 $
  + * $Header: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/session/StandardManager.java,v 1.5 2000/05/12 06:15:24 costin Exp $
  + * $Revision: 1.5 $
  + * $Date: 2000/05/12 06:15:24 $
    *
    * ====================================================================
    *
  @@ -103,12 +103,20 @@
    * </ul>
    *
    * @author Craig R. McClanahan
  - * @version $Revision: 1.4 $ $Date: 2000/05/12 02:31:58 $
  + * @version $Revision: 1.5 $ $Date: 2000/05/12 06:15:24 $
    */
   
  -public final class StandardManager implements Runnable {
  +public final class StandardManager implements Runnable, SessionManager {
  +    public StandardManager() {
  +	try {
  +	    start();
  +	} catch( Exception ex ) {
  +	}
  +    }
  +
       // ----------------------------------------------------- Instance Variables
   
  +    Context ctx;
   
       /**
        * The Container with which this Manager is associated.
  @@ -152,6 +160,9 @@
   
       // ------------------------------------------------------------- Properties
   
  +    public void setContext( Context ctx ) {
  +	this.ctx=ctx;
  +    }
   
       /**
        * Return the Container with which this Manager is associated.
  @@ -238,6 +249,18 @@
   
       // --------------------------------------------------------- Public Methods
   
  +    /**
  +     * Mark the specified session's last accessed time.  This should be
  +     * called for each request by a RequestInterceptor.
  +     *
  +     * @param session The session to be marked
  +     */
  +    public void accessed( HttpSession session ) {
  +	if( session == null) return;
  +	if (session instanceof StandardSession)
  +	    ((StandardSession) session).access();
  +    }
  +
   
       /**
        * Return the active Session, associated with this Manager, with the
  @@ -252,15 +275,50 @@
        * @exception IOException if an input/output error occurs while
        *  processing this request
        */
  -    public HttpSession findSession(String id) throws IOException {
  -
  +    public HttpSession findSession(String id) {
  +	
   	if (id == null)
   	    return (null);
   	return ((HttpSession) sessions.get(id));
  +    }
  +
  +    /**
  +     * Remove all sessions because our associated Context is being shut down.
  +     *
  +     * @param ctx The context that is being shut down
  +     */
  +    public void removeSessions() {
   
  +	// XXX XXX a manager may be shared by multiple
  +	// contexts, we just want to remove the sessions of ctx!
  +	// The manager will still run after that ( i.e. keep database
  +	// connection open
  +	try {
  +	    stop();
  +	} catch (TomcatException e) {
  +	    throw new IllegalStateException("" + e);
  +	}
  +
       }
   
  +    /**
  +     * Used by context to configure the session manager's inactivity timeout.
  +     *
  +     * The SessionManager may have some default session time out, the
  +     * Context on the other hand has it's timeout set by the deployment
  +     * descriptor (web.xml). This method lets the Context conforgure the
  +     * session manager according to this value.
  +     *
  +     * @param minutes The session inactivity timeout in minutes.
  +     */
  +    public void setSessionTimeOut(int minutes) {
  +        if(-1 != minutes) {
  +            // The manager works with seconds...
  +            setMaxInactiveInterval(minutes * 60);
  +        }
  +    }
   
  +    
       /**
        * Return the set of active Sessions associated with this Manager.
        * If this Manager has no active Sessions, a zero-length array is returned.
  @@ -468,70 +526,6 @@
   	session.setId(SessionUtil.generateSessionId());
   
   	return (session);
  -    }
  -
  -
  -    // ------------------------------------------------------ Lifecycle Methods
  -
  -
  -    /**
  -     * Configure this component, based on the specified configuration
  -     * parameters.  This method should be called immediately after the
  -     * component instance is created, and before <code>start()</code>
  -     * is called.
  -     *
  -     * @param parameters Configuration parameters for this component
  -     *  (<B>FIXME: What object type should this really be?)
  -     *
  -     * @exception IllegalStateException if this component has already been
  -     *  configured and/or started
  -     * @exception TomcatException if this component detects a fatal error
  -     *  in the configuration parameters it was given
  -     */
  -    public void configure(Node parameters)
  -	throws TomcatException {
  -
  -	// Validate and update our current component state
  -	if (configured)
  -	    throw new TomcatException
  -		(sm.getString("standardManager.alreadyConfigured"));
  -	configured = true;
  -	if (parameters == null)
  -	    return;
  -
  -	// Parse and process our configuration parameters
  -	if (!("Manager".equals(parameters.getNodeName())))
  -	    return;
  -	NamedNodeMap attributes = parameters.getAttributes();
  -	Node node = null;
  -
  -	node = attributes.getNamedItem("checkInterval");
  -	if (node != null) {
  -	    try {
  -		setCheckInterval(Integer.parseInt(node.getNodeValue()));
  -	    } catch (Throwable t) {
  -		;	// XXX - Throw exception?
  -	    }
  -	}
  -
  -	node = attributes.getNamedItem("maxActiveSessions");
  -	if (node != null) {
  -	    try {
  -		setMaxActiveSessions(Integer.parseInt(node.getNodeValue()));
  -	    } catch (Throwable t) {
  -		;	// XXX - Throw exception?
  -	    }
  -	}
  -
  -	node = attributes.getNamedItem("maxInactiveInterval");
  -	if (node != null) {
  -	    try {
  -		setMaxInactiveInterval(Integer.parseInt(node.getNodeValue()));
  -	    } catch (Throwable t) {
  -		;	// XXX - Throw exception?
  -	    }
  -	}
  -
       }