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