Interface Session

All Superinterfaces:
Map<Serializable,Serializable>
All Known Implementing Classes:
InMemorySession

public interface Session extends Map<Serializable,Serializable>
Represents a browser session.

Session objects are used to store data related to the browser session. Servers with a small number of clients usually keep session objects and the associated data in memory. Servers with a large number of clients may choose to only keep a LRU cache of session objects in memory and swap out (persist) other session objects. Therefore the keys and values stored using a session object must be serializable.

Occasionally, data associated with a session object is already persisted anyway, because its lifetime is beyond that of a session. To avoid persisting such data twice, the session provides a special area for “transient data”. If components choose to store data in this area, they must always check before use if the data is available and recover it if necessary. Using this approach, the components automatically profit from the LRU caching mechanism provided by the session manager. As an alternative, components can use the session id() as key to manage the data on their own.

Before removal, the SessionManager calls the close() method. The default implementation iterates through all values in the transient data map and calls AutoCloseable.close() for each one that implements the AutoCloseable interface.

Implementations should override Object.hashCode() and Object.equals(Object) in such a way that the session id is the only relevant attribute (cannot be done by default methods of the interface).

Note that a browser can issue several requests related to the same session in parallel. Implementations of this interface must therefore ensure the thread safety of all methods provided by Map. Operations that require consistency across several operations should synchronize on the session object.