1/*2 * Copyright 2000-2004 The Apache Software Foundation.3 * 4 * Licensed under the Apache License, Version 2.0 (the "License");5 * you may not use this file except in compliance with the License.6 * You may obtain a copy of the License at7 * 8 * http://www.apache.org/licenses/LICENSE-2.09 * 10 * Unless required by applicable law or agreed to in writing, software11 * distributed under the License is distributed on an "AS IS" BASIS,12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.13 * See the License for the specific language governing permissions and14 * limitations under the License.15 */1617packageorg.apache.jetspeed.services.webpage;
1819// java.util20import java.util.HashMap;
21import java.util.Iterator;
2223// javax.servlet24import javax.servlet.http.*;
2526import org.apache.log4j.Logger;
2728/***29 * Stores a map of sessions with other sites for the current portal session.30 * The map is keyed by the portal session's SessionID (from the servlet api). 31 * Binds to the servlet's session so that it can be cleaned up on session end.32 * This session keeps a map of all live sessions per site local session.33 *34 * @author <a href="mailto:taylor@apache.org">David Sean Taylor</a>35 * @version $Id: SessionMap.java,v 1.3 2004/02/23 03:46:26 jford Exp $ 36 */3738publicclassSessionMapextends HashMap implements HttpSessionBindingListener
39 {
4041// the name of the user for this session42private String sessionUser;
4344// the servlet session id on this server45private String sessionID;
4647// the active status of this session48privateboolean active = true;
4950// hit count51privateint hitCount = 0;
5253// cache hit count 54privateint cacheCount = 0;
5556static Logger log = Logger.getLogger(SessionMap.class);
5758/***59 * construct a Session Map60 *61 * @param sessionId the sessionID on this host62 * @param sessionUser the user associated with the new session.63 *64 */65publicSessionMap(String sessionID, String sessionUser)
66 {
67this.sessionID = sessionID;
68this.sessionUser = sessionUser;
69 }
707172/***73 * Gets the user associated with this session.74 *75 * @return the user associated with this sessions.76 */77public String getUser()
78 {
79return sessionUser;
80 }
8182/***83 * Gets the Session ID associated with this session.84 *85 * @return the session ID associated with this sessions.86 */87public String getSessionID()
88 {
89return sessionID;
90 }
9192/***93 * Gets the Session State, for the servlet session.94 *95 * @return the a string describing the session state.96 */97public String getSessionState()
98 {
99return (active) ? "active" : "inactive";
100 }
101102/***103 * Gets the managed session count for this portal session.104 *105 * @return the managed session count for this session.106 */107publicint getSessionCount()
108 {
109returnthis.size();
110 }
111112/***113 * Gets the hitcount for this session.114 *115 * @return the hitcount for this session.116 */117publicint getHitCount()
118 {
119return hitCount;
120 }
121122/***123 * Increments the hitcount for this session.124 *125 */126publicvoid incHitCount()
127 {
128 hitCount++;
129 }
130131/***132 * Gets the cache count for this session.133 *134 * @return the cache count for this session.135 */136publicint getCacheCount()
137 {
138return cacheCount;
139 }
140141/***142 * Increments the hitcount for this session.143 *144 */145publicvoid incCacheCount()
146 {
147 cacheCount++;
148 }
149150151/***152 * This method is a session binding event callback.153 * It is called when the session is bound154 *155 */156publicvoid valueBound(HttpSessionBindingEvent event)
157 {
158 }
159160/***161 * This method is a session unbinding event callback.162 * It is called when the session is unbound.163 * We need to clean up all the site sessions associated with this Session.164 * The session is marked as 'not active' and is no longer useable.165 * It session object is then removed from the agent's cache 166 *167 */168publicvoid valueUnbound(HttpSessionBindingEvent event)
169 {
170 log.info("~~~ SessionMap UNBOUND as " + event.getName() + " from " + event.getSession().getId() );
171172// Now logout of all sessions173 Iterator it = values().iterator();
174while (it.hasNext())
175 {
176SiteSession hps = (SiteSession)it.next();
177try178 {
179 hps.logout(null);
180181 } catch(Exception e)
182 {
183// continue logging out even if one fails184 log.error("Unbound-Logout of Session: " + e);
185 }
186 }
187 active = false;
188 clear();
189 }
190191192 }