1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.jetspeed.container.session;
18
19 import javax.servlet.http.HttpSession;
20 import javax.servlet.http.HttpSessionBindingEvent;
21 import javax.servlet.http.HttpSessionEvent;
22
23 import org.apache.jetspeed.services.JetspeedPortletServices;
24 import org.apache.jetspeed.services.PortletServices;
25
26 /***
27 * PortalSessionMonitorImpl
28 *
29 * @author <a href="mailto:ate@douma.nu">Ate Douma</a>
30 * @version $Id: $
31 */
32 public class PortalSessionMonitorImpl implements PortalSessionMonitor
33 {
34 private static final long serialVersionUID = 1239564779524373742L;
35
36 private long sessionKey;
37 private transient String sessionId;
38 private transient HttpSession session;
39 private boolean forceInvalidate;
40
41 public PortalSessionMonitorImpl(long sessionKey)
42 {
43 this(sessionKey,true);
44 }
45
46 public PortalSessionMonitorImpl(long sessionKey, boolean forceInvalidate)
47 {
48 this.sessionKey = sessionKey;
49 this.forceInvalidate = forceInvalidate;
50 }
51
52
53
54
55 public String getSessionId()
56 {
57 return sessionId;
58 }
59
60
61
62
63 public long getSessionKey()
64 {
65 return sessionKey;
66 }
67
68 public HttpSession getSession()
69 {
70 return session;
71 }
72
73
74
75
76
77 public void invalidateSession()
78 {
79 HttpSession thisSession = session;
80 if ( thisSession != null )
81 {
82 session = null;
83 if (forceInvalidate)
84 {
85 try
86 {
87 thisSession.invalidate();
88 }
89 catch (Exception ise)
90 {
91
92 }
93 }
94 }
95 }
96
97
98
99
100 public void valueBound(HttpSessionBindingEvent event)
101 {
102 this.session = event.getSession();
103 this.sessionId = session.getId();
104 }
105
106
107
108
109 public void valueUnbound(HttpSessionBindingEvent event)
110 {
111 if ( session != null )
112 {
113 PortalSessionsManager manager = getManager();
114 if (manager != null)
115 {
116 manager.portalSessionDestroyed(this);
117 }
118 session = null;
119 }
120 }
121
122
123
124
125 public void sessionDidActivate(HttpSessionEvent event)
126 {
127 session = event.getSession();
128 sessionId = session.getId();
129 PortalSessionsManager manager = getManager();
130 if (manager != null)
131 {
132 manager.portalSessionDidActivate(this);
133 }
134 }
135
136
137
138
139 public void sessionWillPassivate(HttpSessionEvent event)
140 {
141 PortalSessionsManager manager = getManager();
142 if (manager != null)
143 {
144 manager.portalSessionWillPassivate(this);
145 }
146 session = null;
147 }
148
149 private PortalSessionsManager getManager()
150 {
151 PortletServices services = JetspeedPortletServices.getSingleton();
152 if (services != null)
153 {
154 return (PortalSessionsManager)services.getService(PortalSessionsManager.SERVICE_NAME);
155 }
156 return null;
157 }
158 }