1 package org.apache.turbine.services.session;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 import java.io.Serializable;
20 import javax.servlet.http.HttpSessionActivationListener;
21 import javax.servlet.http.HttpSessionEvent;
22 import javax.servlet.http.HttpSessionListener;
23
24 /***
25 * This class is a listener for both session creation and destruction,
26 * and for session activation and passivation. It must be configured
27 * via your web application's <code>web.xml</code> deployment
28 * descriptor as follows for the container to call it:
29 *
30 * <blockquote><code><pre>
31 * <listener>
32 * <listener-class>
33 * org.apache.turbine.session.SessionListener
34 * </listener-class>
35 * </listener>
36 * </pre></code></blockquote>
37 *
38 * <code><listener></code> elemements can occur between
39 * <code><context-param></code> and <code><servlet></code>
40 * elements in your deployment descriptor.
41 *
42 * The {@link #sessionCreated(HttpSessionEvent)} callback will
43 * automatically add an instance of this listener to any newly created
44 * <code>HttpSession</code> for detection of session passivation and
45 * re-activation.
46 *
47 * @since 2.3
48 * @author <a href="mailto:quintonm@bellsouth.net">Quinton McCombs</a>
49 * @author <a href="mailto:dlr@apache.org">Daniel Rall</a>
50 * @version $Id: SessionListener.java 278822 2005-09-05 19:53:05Z henning $
51 * @see javax.servlet.http.HttpSessionListener
52 */
53 public class SessionListener
54 implements HttpSessionListener, HttpSessionActivationListener, Serializable
55 {
56 /*** Serial Version UID */
57 private static final long serialVersionUID = -8083730704842809870L;
58
59
60
61 /***
62 * Called by the servlet container when a new session is created
63 *
64 * @param event Session creation event.
65 */
66 public void sessionCreated(HttpSessionEvent event)
67 {
68 TurbineSession.addSession(event.getSession());
69 event.getSession().setAttribute(getClass().getName(), this);
70 }
71
72 /***
73 * Called by the servlet container when a session is destroyed
74 *
75 * @param event Session destruction event.
76 */
77 public void sessionDestroyed(HttpSessionEvent event)
78 {
79 TurbineSession.removeSession(event.getSession());
80 }
81
82
83
84
85 /***
86 * Called by the servlet container when an existing session is
87 * (re-)activated.
88 *
89 * @param event Session activation event.
90 */
91 public void sessionDidActivate(HttpSessionEvent event)
92 {
93 TurbineSession.addSession(event.getSession());
94 }
95
96 /***
97 * Called by the servlet container when a an existing session is
98 * passivated.
99 *
100 * @param event Session passivation event.
101 */
102 public void sessionWillPassivate(HttpSessionEvent event)
103 {
104 TurbineSession.removeSession(event.getSession());
105 }
106 }