Class InMemorySessionManager
- java.lang.Object
-
- io.undertow.server.session.InMemorySessionManager
-
- All Implemented Interfaces:
SessionManager
,SessionManagerStatistics
public class InMemorySessionManager extends Object implements SessionManager, SessionManagerStatistics
The default in memory session manager. This basically just stores sessions in an in memory hash map.- Author:
- Stuart Douglas
-
-
Field Summary
-
Fields inherited from interface io.undertow.server.session.SessionManager
ATTACHMENT_KEY
-
-
Constructor Summary
Constructors Constructor Description InMemorySessionManager(SessionIdGenerator sessionIdGenerator, String deploymentName, int maxSessions, boolean expireOldestUnusedSessionOnMax)
InMemorySessionManager(SessionIdGenerator sessionIdGenerator, String deploymentName, int maxSessions, boolean expireOldestUnusedSessionOnMax, boolean statisticsEnabled)
InMemorySessionManager(String id)
InMemorySessionManager(String deploymentName, int maxSessions)
InMemorySessionManager(String deploymentName, int maxSessions, boolean expireOldestUnusedSessionOnMax)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Session
createSession(HttpServerExchange serverExchange, SessionConfig config)
Creates a new session.boolean
equals(Object object)
long
getActiveSessionCount()
Set<String>
getActiveSessions()
Returns the identifiers of those sessions that are active on this node, excluding passivated sessionsSet<String>
getAllSessions()
Returns the identifiers of all sessions, including both active and passivelong
getAverageSessionAliveTime()
long
getCreatedSessionCount()
String
getDeploymentName()
Uniquely identifies this session managerlong
getExpiredSessionCount()
long
getHighestSessionCount()
long
getMaxActiveSessions()
long
getMaxSessionAliveTime()
long
getRejectedSessions()
Session
getSession(HttpServerExchange serverExchange, SessionConfig config)
Session
getSession(String sessionId)
Retrieves a session with the given session idlong
getStartTime()
SessionManagerStatistics
getStatistics()
Returns the statistics for this session manager, or null, if statistics are not supported.Set<String>
getTransientSessions()
Returns the identifiers of those sessions that would be lost upon shutdown of this nodeint
hashCode()
void
registerSessionListener(SessionListener listener)
Registers a session listener for the session managervoid
removeSessionListener(SessionListener listener)
Removes a session listener from the session managervoid
setDefaultSessionTimeout(int timeout)
Sets the default session timeoutvoid
start()
Starts the session managervoid
stop()
stops the session managerString
toString()
-
-
-
Constructor Detail
-
InMemorySessionManager
public InMemorySessionManager(String deploymentName, int maxSessions, boolean expireOldestUnusedSessionOnMax)
-
InMemorySessionManager
public InMemorySessionManager(SessionIdGenerator sessionIdGenerator, String deploymentName, int maxSessions, boolean expireOldestUnusedSessionOnMax)
-
InMemorySessionManager
public InMemorySessionManager(SessionIdGenerator sessionIdGenerator, String deploymentName, int maxSessions, boolean expireOldestUnusedSessionOnMax, boolean statisticsEnabled)
-
InMemorySessionManager
public InMemorySessionManager(String deploymentName, int maxSessions)
-
InMemorySessionManager
public InMemorySessionManager(String id)
-
-
Method Detail
-
getDeploymentName
public String getDeploymentName()
Description copied from interface:SessionManager
Uniquely identifies this session manager- Specified by:
getDeploymentName
in interfaceSessionManager
- Returns:
- a unique identifier
-
start
public void start()
Description copied from interface:SessionManager
Starts the session manager- Specified by:
start
in interfaceSessionManager
-
stop
public void stop()
Description copied from interface:SessionManager
stops the session manager- Specified by:
stop
in interfaceSessionManager
-
createSession
public Session createSession(HttpServerExchange serverExchange, SessionConfig config)
Description copied from interface:SessionManager
Creates a new session. AnySessionListener
s registered with this manager will be notified of the session creation.This method *MUST* call
SessionConfig.findSessionId(io.undertow.server.HttpServerExchange)
(io.undertow.server.HttpServerExchange)} first to determine if an existing session ID is present in the exchange. If this id is present then it must be used as the new session ID. If a session with this ID already exists then anIllegalStateException
must be thrown.This requirement exists to allow forwards across servlet contexts to work correctly. The session manager is responsible for making sure that a newly created session is accessible to later calls to
SessionManager.getSession(io.undertow.server.HttpServerExchange, SessionConfig)
from the same request. It is recommended that a non static attachment key be used to store the newly created session as an attachment. The attachment key must be static to prevent different session managers from interfering with each other.- Specified by:
createSession
in interfaceSessionManager
- Returns:
- The created session
-
getSession
public Session getSession(HttpServerExchange serverExchange, SessionConfig config)
- Specified by:
getSession
in interfaceSessionManager
- Returns:
- An IoFuture that can be used to retrieve the session, or an IoFuture that will return null if not found
-
getSession
public Session getSession(String sessionId)
Description copied from interface:SessionManager
Retrieves a session with the given session id- Specified by:
getSession
in interfaceSessionManager
- Parameters:
sessionId
- The session ID- Returns:
- The session, or null if it does not exist
-
registerSessionListener
public void registerSessionListener(SessionListener listener)
Description copied from interface:SessionManager
Registers a session listener for the session manager- Specified by:
registerSessionListener
in interfaceSessionManager
- Parameters:
listener
- The listener
-
removeSessionListener
public void removeSessionListener(SessionListener listener)
Description copied from interface:SessionManager
Removes a session listener from the session manager- Specified by:
removeSessionListener
in interfaceSessionManager
- Parameters:
listener
- the listener
-
setDefaultSessionTimeout
public void setDefaultSessionTimeout(int timeout)
Description copied from interface:SessionManager
Sets the default session timeout- Specified by:
setDefaultSessionTimeout
in interfaceSessionManager
- Parameters:
timeout
- the timeout
-
getTransientSessions
public Set<String> getTransientSessions()
Description copied from interface:SessionManager
Returns the identifiers of those sessions that would be lost upon shutdown of this node- Specified by:
getTransientSessions
in interfaceSessionManager
-
getActiveSessions
public Set<String> getActiveSessions()
Description copied from interface:SessionManager
Returns the identifiers of those sessions that are active on this node, excluding passivated sessions- Specified by:
getActiveSessions
in interfaceSessionManager
-
getAllSessions
public Set<String> getAllSessions()
Description copied from interface:SessionManager
Returns the identifiers of all sessions, including both active and passive- Specified by:
getAllSessions
in interfaceSessionManager
-
getStatistics
public SessionManagerStatistics getStatistics()
Description copied from interface:SessionManager
Returns the statistics for this session manager, or null, if statistics are not supported.- Specified by:
getStatistics
in interfaceSessionManager
-
getCreatedSessionCount
public long getCreatedSessionCount()
- Specified by:
getCreatedSessionCount
in interfaceSessionManagerStatistics
- Returns:
- The number of sessions that this session manager has created
-
getMaxActiveSessions
public long getMaxActiveSessions()
- Specified by:
getMaxActiveSessions
in interfaceSessionManagerStatistics
- Returns:
- the maximum number of sessions this session manager supports
-
getHighestSessionCount
public long getHighestSessionCount()
- Specified by:
getHighestSessionCount
in interfaceSessionManagerStatistics
- Returns:
- the highest number of sessions that have been active at a single time, or -1 if this statistic is not supported
-
getActiveSessionCount
public long getActiveSessionCount()
- Specified by:
getActiveSessionCount
in interfaceSessionManagerStatistics
- Returns:
- The number of active sessions
-
getExpiredSessionCount
public long getExpiredSessionCount()
- Specified by:
getExpiredSessionCount
in interfaceSessionManagerStatistics
- Returns:
- The number of expired sessions
-
getRejectedSessions
public long getRejectedSessions()
- Specified by:
getRejectedSessions
in interfaceSessionManagerStatistics
- Returns:
- The number of rejected sessions
-
getMaxSessionAliveTime
public long getMaxSessionAliveTime()
- Specified by:
getMaxSessionAliveTime
in interfaceSessionManagerStatistics
- Returns:
- The longest a session has been alive for in milliseconds
-
getAverageSessionAliveTime
public long getAverageSessionAliveTime()
- Specified by:
getAverageSessionAliveTime
in interfaceSessionManagerStatistics
- Returns:
- The average session lifetime in milliseconds
-
getStartTime
public long getStartTime()
- Specified by:
getStartTime
in interfaceSessionManagerStatistics
- Returns:
- The timestamp at which the session manager started
-
-