Class InMemorySessionManager
- java.lang.Object
-
- io.undertow.server.session.InMemorySessionManager
-
- All Implemented Interfaces:
SessionManager,SessionManagerStatistics
public class InMemorySessionManager extends java.lang.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, java.lang.String deploymentName, int maxSessions, boolean expireOldestUnusedSessionOnMax)InMemorySessionManager(SessionIdGenerator sessionIdGenerator, java.lang.String deploymentName, int maxSessions, boolean expireOldestUnusedSessionOnMax, boolean statisticsEnabled)InMemorySessionManager(java.lang.String id)InMemorySessionManager(java.lang.String deploymentName, int maxSessions)InMemorySessionManager(java.lang.String deploymentName, int maxSessions, boolean expireOldestUnusedSessionOnMax)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description SessioncreateSession(HttpServerExchange serverExchange, SessionConfig config)Creates a new session.booleanequals(java.lang.Object object)longgetActiveSessionCount()java.util.Set<java.lang.String>getActiveSessions()Returns the identifiers of those sessions that are active on this node, excluding passivated sessionsjava.util.Set<java.lang.String>getAllSessions()Returns the identifiers of all sessions, including both active and passivelonggetAverageSessionAliveTime()longgetCreatedSessionCount()java.lang.StringgetDeploymentName()Uniquely identifies this session managerlonggetExpiredSessionCount()longgetHighestSessionCount()longgetMaxActiveSessions()longgetMaxSessionAliveTime()longgetRejectedSessions()SessiongetSession(HttpServerExchange serverExchange, SessionConfig config)SessiongetSession(java.lang.String sessionId)Retrieves a session with the given session idlonggetStartTime()SessionManagerStatisticsgetStatistics()Returns the statistics for this session manager, or null, if statistics are not supported.java.util.Set<java.lang.String>getTransientSessions()Returns the identifiers of those sessions that would be lost upon shutdown of this nodeinthashCode()voidregisterSessionListener(SessionListener listener)Registers a session listener for the session managervoidremoveSessionListener(SessionListener listener)Removes a session listener from the session managervoidsetDefaultSessionTimeout(int timeout)Sets the default session timeoutvoidstart()Starts the session managervoidstop()stops the session managerjava.lang.StringtoString()
-
-
-
Constructor Detail
-
InMemorySessionManager
public InMemorySessionManager(java.lang.String deploymentName, int maxSessions, boolean expireOldestUnusedSessionOnMax)
-
InMemorySessionManager
public InMemorySessionManager(SessionIdGenerator sessionIdGenerator, java.lang.String deploymentName, int maxSessions, boolean expireOldestUnusedSessionOnMax)
-
InMemorySessionManager
public InMemorySessionManager(SessionIdGenerator sessionIdGenerator, java.lang.String deploymentName, int maxSessions, boolean expireOldestUnusedSessionOnMax, boolean statisticsEnabled)
-
InMemorySessionManager
public InMemorySessionManager(java.lang.String deploymentName, int maxSessions)
-
InMemorySessionManager
public InMemorySessionManager(java.lang.String id)
-
-
Method Detail
-
getDeploymentName
public java.lang.String getDeploymentName()
Description copied from interface:SessionManagerUniquely identifies this session manager- Specified by:
getDeploymentNamein interfaceSessionManager- Returns:
- a unique identifier
-
start
public void start()
Description copied from interface:SessionManagerStarts the session manager- Specified by:
startin interfaceSessionManager
-
stop
public void stop()
Description copied from interface:SessionManagerstops the session manager- Specified by:
stopin interfaceSessionManager
-
createSession
public Session createSession(HttpServerExchange serverExchange, SessionConfig config)
Description copied from interface:SessionManagerCreates a new session. AnySessionListeners 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 anIllegalStateExceptionmust 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:
createSessionin interfaceSessionManager- Returns:
- The created session
-
getSession
public Session getSession(HttpServerExchange serverExchange, SessionConfig config)
- Specified by:
getSessionin 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(java.lang.String sessionId)
Description copied from interface:SessionManagerRetrieves a session with the given session id- Specified by:
getSessionin 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:SessionManagerRegisters a session listener for the session manager- Specified by:
registerSessionListenerin interfaceSessionManager- Parameters:
listener- The listener
-
removeSessionListener
public void removeSessionListener(SessionListener listener)
Description copied from interface:SessionManagerRemoves a session listener from the session manager- Specified by:
removeSessionListenerin interfaceSessionManager- Parameters:
listener- the listener
-
setDefaultSessionTimeout
public void setDefaultSessionTimeout(int timeout)
Description copied from interface:SessionManagerSets the default session timeout- Specified by:
setDefaultSessionTimeoutin interfaceSessionManager- Parameters:
timeout- the timeout
-
getTransientSessions
public java.util.Set<java.lang.String> getTransientSessions()
Description copied from interface:SessionManagerReturns the identifiers of those sessions that would be lost upon shutdown of this node- Specified by:
getTransientSessionsin interfaceSessionManager
-
getActiveSessions
public java.util.Set<java.lang.String> getActiveSessions()
Description copied from interface:SessionManagerReturns the identifiers of those sessions that are active on this node, excluding passivated sessions- Specified by:
getActiveSessionsin interfaceSessionManager
-
getAllSessions
public java.util.Set<java.lang.String> getAllSessions()
Description copied from interface:SessionManagerReturns the identifiers of all sessions, including both active and passive- Specified by:
getAllSessionsin interfaceSessionManager
-
equals
public boolean equals(java.lang.Object object)
- Overrides:
equalsin classjava.lang.Object
-
hashCode
public int hashCode()
- Overrides:
hashCodein classjava.lang.Object
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
getStatistics
public SessionManagerStatistics getStatistics()
Description copied from interface:SessionManagerReturns the statistics for this session manager, or null, if statistics are not supported.- Specified by:
getStatisticsin interfaceSessionManager
-
getCreatedSessionCount
public long getCreatedSessionCount()
- Specified by:
getCreatedSessionCountin interfaceSessionManagerStatistics- Returns:
- The number of sessions that this session manager has created
-
getMaxActiveSessions
public long getMaxActiveSessions()
- Specified by:
getMaxActiveSessionsin interfaceSessionManagerStatistics- Returns:
- the maximum number of sessions this session manager supports
-
getHighestSessionCount
public long getHighestSessionCount()
- Specified by:
getHighestSessionCountin 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:
getActiveSessionCountin interfaceSessionManagerStatistics- Returns:
- The number of active sessions
-
getExpiredSessionCount
public long getExpiredSessionCount()
- Specified by:
getExpiredSessionCountin interfaceSessionManagerStatistics- Returns:
- The number of expired sessions
-
getRejectedSessions
public long getRejectedSessions()
- Specified by:
getRejectedSessionsin interfaceSessionManagerStatistics- Returns:
- The number of rejected sessions
-
getMaxSessionAliveTime
public long getMaxSessionAliveTime()
- Specified by:
getMaxSessionAliveTimein interfaceSessionManagerStatistics- Returns:
- The longest a session has been alive for in milliseconds
-
getAverageSessionAliveTime
public long getAverageSessionAliveTime()
- Specified by:
getAverageSessionAliveTimein interfaceSessionManagerStatistics- Returns:
- The average session lifetime in milliseconds
-
getStartTime
public long getStartTime()
- Specified by:
getStartTimein interfaceSessionManagerStatistics- Returns:
- The timestamp at which the session manager started
-
-