com.payneteasy.superfly.common.session.HashMapBackedSessionMapping Maven / Gradle / Ivy
package com.payneteasy.superfly.common.session;
import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import javax.servlet.http.HttpSession;
/**
* SessionMapping implementation which uses a HashMap.
*
* @author Roman Puchkovskiy
*/
public class HashMapBackedSessionMapping implements SessionMapping {
private Map mapping = new HashMap();
private Map idToKey = new HashMap();
private Map keyToId = new HashMap();
public synchronized void addSession(String key, HttpSession session) {
String id = session.getId();
mapping.put(key, session);
idToKey.put(id, key);
keyToId.put(key, id);
}
public synchronized HttpSession removeSessionByKey(String key) {
String id = keyToId.remove(key);
idToKey.remove(id);
return mapping.remove(key);
}
public synchronized HttpSession removeSessionById(String id) {
String key = idToKey.remove(id);
keyToId.remove(key);
return mapping.remove(key);
}
public synchronized Collection clear() {
idToKey.clear();
keyToId.clear();
Collection removedSessions = new HashSet(mapping.values());
mapping.clear();
return removedSessions;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy