You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@turbine.apache.org by Daniel Rall <dl...@collab.net> on 2003/02/04 21:52:51 UTC

TurbineSessionService

Quinton, I'm curious about your thoughts on how the Servlet API's
HttpSessionActivationListener [1] ties in with TurbineSessionService.  
SessionListener implements only HttpSessionListener, the callback for
session creation and deletion events.  When active sessions which have been
serialized to disk during servlet container shutdown are loaded during a
server restart, it seems unlikely that they will again show up in Turbine's
list of active sessions.  I'm currently working with a version of
TurbineSessionService in SourceCast (I dumped our custom code which did the
same thing so that we could share the maintainence costs).  Any ideas in
regard to the HttpSessionActivationListener issue?

- Dan


[1] http://java.sun.com/products/servlet/2.3/javadoc/javax/servlet/http/HttpSessionActivationListener.html


---------------------------------------------------------------------
To unsubscribe, e-mail: turbine-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: turbine-dev-help@jakarta.apache.org


Re: TurbineSessionService

Posted by Daniel Rall <dl...@collab.net>.
On Tue, 4 Feb 2003, Daniel Rall wrote:

> Quinton, I'm curious about your thoughts on how the Servlet API's
> HttpSessionActivationListener [1] ties in with TurbineSessionService.  
> SessionListener implements only HttpSessionListener, the callback for
> session creation and deletion events.  When active sessions which have been
> serialized to disk during servlet container shutdown are loaded during a
> server restart, it seems unlikely that they will again show up in Turbine's
> list of active sessions.  I'm currently working with a version of
> TurbineSessionService in SourceCast (I dumped our custom code which did the
> same thing so that we could share the maintainence costs).  Any ideas in
> regard to the HttpSessionActivationListener issue?
> 
> - Dan
> 
> 
> [1] http://java.sun.com/products/servlet/2.3/javadoc/javax/servlet/http/HttpSessionActivationListener.html

Quinton, what do you think about SessionListener auto-adding itself as a 
HttpSessionActivationListener to each newly created session?


Index: SessionListener.java
===================================================================
RCS file: /home/cvs/jakarta-turbine-2/src/java/org/apache/turbine/services/session/SessionListener.java,v
retrieving revision 1.3
diff -u -r1.3 SessionListener.java
--- SessionListener.java	4 Feb 2003 17:01:45 -0000	1.3
+++ SessionListener.java	4 Feb 2003 21:42:17 -0000
@@ -58,9 +58,10 @@
 import javax.servlet.http.HttpSessionListener;
 
 /**
- * This class is a listener for Session creation and destruction.  It
- * must be configured via your web application's <code>web.xml</code>
- * deployment descriptor as follows for the container to call it:
+ * This class is a listener for both session creation and destruction,
+ * and for session activation and passivation.  It must be configured
+ * via your web application's <code>web.xml</code> deployment
+ * descriptor as follows for the container to call it:
  *
  * <blockquote><code><pre>
  * <listener>
@@ -74,31 +75,64 @@
  * <code>&lt;context-param&gt;</code> and <code>&lt;servlet&gt;</code>
  * elements in your deployment descriptor.
  *
+ * The {@link #sessionCreated(HttpSessionEvent)} callback will
+ * automatically add an instance of this listener to any newly created
+ * <code>HttpSession</code> for detection of session passivation and
+ * re-activation.
+ *
  * @since 2.3
  * @version $Id: SessionListener.java,v 1.3 2003/02/04 17:01:45 quintonm Exp $
  * @author <a href="mailto:quintonm@bellsouth.net">Quinton McCombs</a>
+ * @author <a href="mailto:dlr@apache.org">Daniel Rall</a>
  * @see javax.servlet.http.HttpSessionListener
  */
 public class SessionListener
-        implements HttpSessionListener
+        implements HttpSessionListener, HttpSessionActivationListener
 {
+    // ---- HttpSessionListener implementation -----------------------------
+
     /**
      * Called by the servlet container when a new session is created
      *
-     * @param event
+     * @param event Session creation event.
      */
     public void sessionCreated(HttpSessionEvent event)
     {
-        TurbineSession.addSession(event.getSession());
+        TurbineSessionService.getInstance().addSession(event.getSession());
+        event.getSession().setAttribute(getClass().getName(), this);
     }
 
     /**
      * Called by the servlet container when a session is destroyed
      *
-     * @param event
+     * @param event Session destruction event.
      */
     public void sessionDestroyed(HttpSessionEvent event)
     {
-        TurbineSession.removeSession(event.getSession());
+        event.getSession().removeAttribute(getClass().getName());
+        TurbineSessionService.getInstance().removeSession(event.getSession());
+    }
+
+
+    // ---- HttpSessionActivationListener implementation -------------------
+
+    /**
+     * Called by the servlet container when a new session is created
+     *
+     * @param event Session activation event.
+     */
+    public void sessionDidActivate(HttpSessionEvent event)
+    {
+        TurbineSessionService.getInstance().addSession(event.getSession());
+    }
+
+    /**
+     * Called by the servlet container when a session is destroyed
+     *
+     * @param event Session passivation event.
+     */
+    public void sessionWillPassivate(HttpSessionEvent event)
+    {
+        TurbineSessionService.getInstance().removeSession(event.getSession());
     }
 }



---------------------------------------------------------------------
To unsubscribe, e-mail: turbine-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: turbine-dev-help@jakarta.apache.org