io.undertow.server.session

## 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 and 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
`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 sessions
`Set<String>` `getAllSessions()` Returns the identifiers of all sessions, including both active and passive
`long` `getAverageSessionAliveTime()`
`long` `getCreatedSessionCount()`
`String` `getDeploymentName()` Uniquely identifies this session manager
`long` `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 id
`long` `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 node
`int` `hashCode()`
`void` `registerSessionListener(SessionListener listener)` Registers a session listener for the session manager
`void` `removeSessionListener(SessionListener listener)` Removes a session listener from the session manager
`void` `setDefaultSessionTimeout(int timeout)` Sets the default session timeout
`void` `start()` Starts the session manager
`void` `stop()` stops the session manager
`String` `toString()`

### Methods inherited from class java.lang.Object

`clone, finalize, getClass, notify, notifyAll, wait, wait, wait`

### 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 interface `SessionManager`
Returns:
  a unique identifier

#### start

    public void start()

Description copied from interface: `SessionManager`
Starts the session manager

Specified by:
  `start` in interface `SessionManager`

#### stop

    public void stop()

Description copied from interface: `SessionManager`
stops the session manager

Specified by:
  `stop` in interface `SessionManager`

#### createSession

    public Session createSession(HttpServerExchange serverExchange,
                                 SessionConfig config)

Description copied from interface: `SessionManager`
Creates a new session. Any `SessionListener`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 an `IllegalStateException` 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 interface `SessionManager`
Returns:
  The created session

#### getSession

    public Session getSession(HttpServerExchange serverExchange,
                              SessionConfig config)

Specified by:
  `getSession` in interface `SessionManager`
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 interface `SessionManager`
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 interface `SessionManager`
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 interface `SessionManager`
Parameters:
  `listener` - the listener

#### setDefaultSessionTimeout

    public void setDefaultSessionTimeout(int timeout)

Description copied from interface: `SessionManager`
Sets the default session timeout

Specified by:
  `setDefaultSessionTimeout` in interface `SessionManager`
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 interface `SessionManager`

#### 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 interface `SessionManager`

#### 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 interface `SessionManager`

#### equals

    public boolean equals(Object object)

Overrides:
  `equals` in class `Object`

#### hashCode

    public int hashCode()

Overrides:
  `hashCode` in class `Object`

#### toString

    public String toString()

Overrides:
  `toString` in class `Object`

#### 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 interface `SessionManager`

#### getCreatedSessionCount

    public long getCreatedSessionCount()

Specified by:
  `getCreatedSessionCount` in interface `SessionManagerStatistics`
Returns:
  The number of sessions that this session manager has created

#### getMaxActiveSessions

    public long getMaxActiveSessions()

Specified by:
  `getMaxActiveSessions` in interface `SessionManagerStatistics`
Returns:
  the maximum number of sessions this session manager supports

#### getHighestSessionCount

    public long getHighestSessionCount()

Specified by:
  `getHighestSessionCount` in interface `SessionManagerStatistics`
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 interface `SessionManagerStatistics`
Returns:
  The number of active sessions

#### getExpiredSessionCount

    public long getExpiredSessionCount()

Specified by:
  `getExpiredSessionCount` in interface `SessionManagerStatistics`
Returns:
  The number of expired sessions

#### getRejectedSessions

    public long getRejectedSessions()

Specified by:
  `getRejectedSessions` in interface `SessionManagerStatistics`
Returns:
  The number of rejected sessions

#### getMaxSessionAliveTime

    public long getMaxSessionAliveTime()

Specified by:
  `getMaxSessionAliveTime` in interface `SessionManagerStatistics`
Returns:
  The longest a session has been alive for in milliseconds

#### getAverageSessionAliveTime

    public long getAverageSessionAliveTime()

Specified by:
  `getAverageSessionAliveTime` in interface `SessionManagerStatistics`
Returns:
  The average session lifetime in milliseconds

#### getStartTime

    public long getStartTime()

Specified by:
  `getStartTime` in interface `SessionManagerStatistics`
Returns:
  The timestamp at which the session manager started