portals-jetspeed-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ggol...@apache.org
Subject cvs commit: jakarta-jetspeed/src/java/org/apache/jetspeed/services/statemanager BaseStateManagerService.java JetspeedHttpStateManagerService.java StateManagerService.java
Date Thu, 08 Aug 2002 00:05:18 GMT
ggolden     2002/08/07 17:05:18

  Modified:    src/java/org/apache/jetspeed/services/statemanager
                        BaseStateManagerService.java
                        JetspeedHttpStateManagerService.java
                        StateManagerService.java
  Log:
  The StateManagerService now has the getCurrentSessionState() methods:
  one to get the state keyed by the current thread / http request / http session id,
  and one to get the state keyed by the current session id plus additional text.
  
  These are useful for getting session state where the rundata or http session
  is not handy.
  
  Note: they must be called in the context of a http request; if a service is running
  a background thread, this thread will not have a current session associated with it.
  
  Also Note: to have these work, each http request must install it's http session
  with this service at the start, and remove it at the end.
  
  The BaseStateManagerService has been updated to provide for these
  getCurrentSessionState and set/clearSessionContext methods.  Note that
  it now has available the http session for the current request / thread.
  
  JetspeedHttpStateManagerService no longer asks for the current Jetspeed
  Rundata to get the http session; it relies upon the current session kept by
  the base class BseStateManagerService.
  
  Revision  Changes    Path
  1.2       +67 -5     jakarta-jetspeed/src/java/org/apache/jetspeed/services/statemanager/BaseStateManagerService.java
  
  Index: BaseStateManagerService.java
  ===================================================================
  RCS file: /home/cvs/jakarta-jetspeed/src/java/org/apache/jetspeed/services/statemanager/BaseStateManagerService.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- BaseStateManagerService.java	10 Jun 2002 19:57:18 -0000	1.1
  +++ BaseStateManagerService.java	8 Aug 2002 00:05:18 -0000	1.2
  @@ -67,14 +67,16 @@
   import java.util.Collections;
   import java.util.Vector;
   import javax.servlet.ServletConfig;
  +import javax.servlet.http.HttpSession;
   
  -import org.apache.jetspeed.services.statemanager.StateManagerService;
  -import org.apache.jetspeed.services.statemanager.SessionStateBindingListener;
   import org.apache.turbine.services.TurbineBaseService;
   import org.apache.turbine.services.InitializationException;
   import org.apache.turbine.util.RunData;
   import org.apache.turbine.util.Log;
   
  +import org.apache.jetspeed.services.statemanager.StateManagerService;
  +import org.apache.jetspeed.services.statemanager.SessionStateBindingListener;
  +
   /**
   * <p>BaseStateManagerService is a Turbine Service implementation of the
   * StateManagerService.</p>
  @@ -91,6 +93,9 @@
       extends TurbineBaseService
       implements StateManagerService
   {
  +    /** map of thread to http session for that thread. */
  +    protected Map m_httpSessions = null;
  +
       /*******************************************************************************
       * Abstract methods
       *******************************************************************************/
  @@ -247,6 +252,9 @@
       {
           super.init();
   
  +        // allocate a thread-safe map to store the "current" http session for each thread
  +        m_httpSessions = Collections.synchronizedMap(new HashMap());
  +
           // create our states storage
           initStates();
   
  @@ -260,6 +268,8 @@
       */
       public void shutdown()
       {
  +        m_httpSessions.clear();
  +        m_httpSessions = null;
           shutdownStates();
           super.shutdown();
   
  @@ -391,6 +401,34 @@
       }   // getSessionState
   
       /**
  +    * Access the SessionState object associated with the current request's http session.
  +	* The session id is used as the key.
  +    * @return an SessionState object associated with the current request's http session.
  +    */
  +    public SessionState getCurrentSessionState()
  +    {
  +        HttpSession session = (HttpSession) m_httpSessions.get(Thread.currentThread());
  +        if (session == null) return null;
  +
  +        return getSessionState(session.getId());
  +
  +    }   // getCurrentSessionState
  +
  +    /**
  +    * Access the SessionState object associated with the current request's http session
with the given key.
  +	* @param key The string to add to the session id to form the SessionState key.
  +    * @return an SessionState object associated with the current request's http session
with the given key.
  +    */
  +    public SessionState getCurrentSessionState( String key )
  +    {
  +        HttpSession session = (HttpSession) m_httpSessions.get(Thread.currentThread());
  +        if (session == null) return null;
  +
  +        return getSessionState(session.getId() + key);
  +
  +    }   // getCurrentSessionState
  +
  +    /**
       * Retire, forget about and clean up all states that start with the given key.
       * @param keyStart The beginning of the key of the states to clean up.
       */
  @@ -407,6 +445,30 @@
           }
   
       }   // retireState
  +
  +    /**
  +    * Set the "current" context for this thread -
  +    * Call this at the start of each request, and call %%% at the end.
  +    * getCurrentSession() uses this for the session state key.
  +    * @param session the HttpSession of the current request.
  +    */
  +    public void setCurrentContext( HttpSession session )
  +    {
  +        // store the session associated with this thread
  +        m_httpSessions.put(Thread.currentThread(), session);
  +
  +    }   // setCurrentContext
  +
  +    /**
  +    * Clear the "current context for this thread -
  +    * Call at the end of each request, balanced with calls to setCurrentContext()
  +    */
  +    public void clearCurrentContext()
  +    {
  +        // clear the session associated with this thread
  +        m_httpSessions.remove(Thread.currentThread());
  +
  +    }    // clearCurrentContext
   
       /*******************************************************************************
       * SessionState implementation
  
  
  
  1.2       +8 -30     jakarta-jetspeed/src/java/org/apache/jetspeed/services/statemanager/JetspeedHttpStateManagerService.java
  
  Index: JetspeedHttpStateManagerService.java
  ===================================================================
  RCS file: /home/cvs/jakarta-jetspeed/src/java/org/apache/jetspeed/services/statemanager/JetspeedHttpStateManagerService.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- JetspeedHttpStateManagerService.java	10 Jun 2002 19:57:18 -0000	1.1
  +++ JetspeedHttpStateManagerService.java	8 Aug 2002 00:05:18 -0000	1.2
  @@ -70,18 +70,13 @@
   import javax.servlet.http.HttpSessionBindingListener;
   import javax.servlet.http.HttpSessionBindingEvent;
   
  -import org.apache.turbine.services.rundata.RunDataService;
  -import org.apache.turbine.services.TurbineServices;
  -
   import org.apache.jetspeed.services.statemanager.BaseStateManagerService;
  -import org.apache.jetspeed.services.rundata.JetspeedRunDataService;
  -import org.apache.jetspeed.services.rundata.JetspeedRunData;
   
   /**
   * <p>JetspeedHttpStateManagerService is an implementation of the BaseStateManagerService
   * which manages the states stored in the "current" HttpSession.</p>
  -* <p>Note: This implementation of the StateManagerService is dependent on the JetspeedRunDataService,
  -* but it takes advantage of the Servlet container's management of the HttpSession.
  +* <p>Note: This implementation of the StateManagerService takes advantage of the
  +* Servlet container's management of the HttpSession.
   * When the session is invalidated, the states we manage will be automatically cleaned up.
   * When this happens, the objects placed into our states will have their
   * SessionStateBindingListener mechanism invoked.</p>
  @@ -96,19 +91,11 @@
   public class JetspeedHttpStateManagerService
       extends BaseStateManagerService
   {
  -    /** The JetspeedRunData Service. */
  -    private JetspeedRunDataService runDataService = null;
  -
       /**
       * Initialize the states storage.
       */
       protected void initStates()
       {
  -        // get the runData service
  -        this.runDataService =
  -            (JetspeedRunDataService)TurbineServices.getInstance()
  -                .getService(RunDataService.SERVICE_NAME);
  -
       }   // initStates
   
       /**
  @@ -116,11 +103,6 @@
       */
       protected void shutdownStates()
       {
  -        // Note: this is called out of any specific request thread, so we
  -        //      do not have any access to sessions... let the Servlet Container
  -        //      clean up the stuff in the sessions.
  -        this.runDataService = null;
  -
       }   // shutdownStates
   
       /**
  @@ -128,14 +110,10 @@
       */
       private HttpSession getSession()
       {
  -        if (runDataService == null) return null;
  -
  -        JetspeedRunData rundata = runDataService.getCurrentRunData();
  -        if (rundata == null) return null;
  -        
  -        HttpSession session = rundata.getSession();
  +        // get the current session that was installed for this thread
  +        HttpSession session = (HttpSession) m_httpSessions.get(Thread.currentThread());
           if (session == null) return null;
  -        
  +
           // call isNew just to see if the session has been invalidated already
           try
           {
  
  
  
  1.4       +41 -3     jakarta-jetspeed/src/java/org/apache/jetspeed/services/statemanager/StateManagerService.java
  
  Index: StateManagerService.java
  ===================================================================
  RCS file: /home/cvs/jakarta-jetspeed/src/java/org/apache/jetspeed/services/statemanager/StateManagerService.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- StateManagerService.java	17 May 2002 18:37:46 -0000	1.3
  +++ StateManagerService.java	8 Aug 2002 00:05:18 -0000	1.4
  @@ -59,6 +59,9 @@
   // package
   package org.apache.jetspeed.services.statemanager;
   
  +// imports
  +import javax.servlet.http.HttpSession;
  +
   /**
   * <p>The StateManagerService is a service that manages SessionState information.
   * Each SessionState is identified by a unique key in this service.  The SessionState
  @@ -69,6 +72,13 @@
   * objects can be notified of their placement into and out of the SessionState.  Objects
that wish
   * to receive this notification implement the SessionStateBindingListener interface.  This
is based
   * on and similar to the HttpSessionBindingListener mechanism.</p>
  +* <p>To support the "current" routines; the ability to get a session state based
  +* on the current http session, this service must be installed properly into the
  +* procssing of each http request.  At the start of the request, the HttpSession
  +* of the request must be passed into the setCurrentContext() method.  At the end
  +* of the request, clearCurrentContext() is called.  For Jetspeed, this is done in
  +* the JetspeedRunDataService, which is always going to be called by Turbine in this
  +* way.</p>
   * @version $Revision$
   * @see org.apache.jetspeed.services.statemanager.SessionState
   * @see org.apache.jetspeed.services.statemanager.SessionStateBindingListener
  @@ -123,10 +133,38 @@
       public SessionState getSessionState( String key );
   
       /**
  +    * Access the SessionState object associated with the current request's http session.
  +	* The session id is used as the key.
  +    * @return an SessionState object associated with the current request's http session.
  +    */
  +    public SessionState getCurrentSessionState();
  +
  +    /**
  +    * Access the SessionState object associated with the current request's http session
with the given key.
  +	* @param key The string to add to the session id to form the SessionState key.
  +    * @return an SessionState object associated with the current request's http session
with the given key.
  +    */
  +    public SessionState getCurrentSessionState( String key );
  +
  +    /**
       * Retire, forget about and clean up all states that start with the given key.
       * @param keyStart The beginning of the key of the states to clean up.
       */
       public void retireState( String keyStart );
  +
  +    /**
  +    * Set the "current" context for this thread -
  +    * Call this at the start of each request, and call %%% at the end.
  +    * getCurrentSession() uses this for the session state key.
  +    * @param session the HttpSession of the current request.
  +    */
  +    public void setCurrentContext( HttpSession session );
  +
  +    /**
  +    * Clear the "current context for this thread -
  +    * Call at the end of each request, balanced with calls to setCurrentContext()
  +    */
  +    public void clearCurrentContext();
   
   }   // interface StateManagerService
   
  
  
  

--
To unsubscribe, e-mail:   <mailto:jetspeed-dev-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:jetspeed-dev-help@jakarta.apache.org>


Mime
View raw message