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
69
70
71
72 public void invalidateSession()
73 {
74 HttpSession thisSession = session;
75 if ( thisSession != null )
76 {
77 session = null;
78 if (forceInvalidate)
79 {
80 try
81 {
82 thisSession.invalidate();
83 }
84 catch (Exception ise)
85 {
86
87 }
88 }
89 }
90 }
91
92
93
94
95 public void valueBound(HttpSessionBindingEvent event)
96 {
97 this.session = event.getSession();
98 this.sessionId = session.getId();
99 }
100
101
102
103
104 public void valueUnbound(HttpSessionBindingEvent event)
105 {
106 if ( session != null )
107 {
108 PortalSessionsManager manager = getManager();
109 if (manager != null)
110 {
111 manager.portalSessionDestroyed(this);
112 }
113 session = null;
114 }
115 }
116
117
118
119
120 public void sessionDidActivate(HttpSessionEvent event)
121 {
122 session = event.getSession();
123 sessionId = session.getId();
124 PortalSessionsManager manager = getManager();
125 if (manager != null)
126 {
127 manager.portalSessionDidActivate(this);
128 }
129 }
130
131
132
133
134 public void sessionWillPassivate(HttpSessionEvent event)
135 {
136 PortalSessionsManager manager = getManager();
137 if (manager != null)
138 {
139 manager.portalSessionWillPassivate(this);
140 }
141 session = null;
142 }
143
144 private PortalSessionsManager getManager()
145 {
146 PortletServices services = JetspeedPortletServices.getSingleton();
147 if (services != null)
148 {
149 return (PortalSessionsManager)services.getService(PortalSessionsManager.SERVICE_NAME);
150 }
151 return null;
152 }
153 }