com.jwebmp.guicedservlets.GuicedServletSessionManager Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of guiced-servlets Show documentation
Show all versions of guiced-servlets Show documentation
An integration library for Servlets in the Guiced Injection Framework
package com.jwebmp.guicedservlets;
import javax.servlet.annotation.WebListener;
import javax.servlet.http.*;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
/**
* A listener for current sessions
*/
@WebListener
public class GuicedServletSessionManager
implements HttpSessionBindingListener, HttpSessionListener
{
/**
* A session mapping
*/
private static final Map sessionMap = new ConcurrentHashMap<>();
/**
* Returns a map of all the currently allocated sessions
*
* @return A map of string and http sessions
*/
public static Map getSessionMap()
{
return sessionMap;
}
/**
* Method valueBound ...
*
* @param event
* of type HttpSessionBindingEvent
*/
@Override
public void valueBound(HttpSessionBindingEvent event)
{
sessionMap.put(event.getSession()
.getId(), event.getSession());
}
/**
* Method valueUnbound ...
*
* @param event
* of type HttpSessionBindingEvent
*/
@Override
public void valueUnbound(HttpSessionBindingEvent event)
{
sessionMap.remove(event.getSession()
.getId());
}
/**
* Method sessionCreated ...
*
* @param se
* of type HttpSessionEvent
*/
@Override
public void sessionCreated(HttpSessionEvent se)
{
sessionMap.put(se.getSession()
.getId(), se.getSession());
}
/**
* Method sessionDestroyed ...
*
* @param se
* of type HttpSessionEvent
*/
@Override
public void sessionDestroyed(HttpSessionEvent se)
{
sessionMap.remove(se.getSession()
.getId());
}
}