public class MapSessionRepository extends Object implements SessionRepository<ExpiringSession>
SessionRepository backed by a Map and that uses a MapSession. By default a
ConcurrentHashMap is used, but a custom Map can be injected to use
distributed maps provided by NoSQL stores like Redis and Hazelcast.
The implementation does NOT support firing SessionDestroyedEvent.
| Constructor and Description |
|---|
MapSessionRepository()
Creates an instance backed by a
ConcurrentHashMap |
MapSessionRepository(Map<String,ExpiringSession> sessions)
Creates a new instance backed by the provided
Map. |
| Modifier and Type | Method and Description |
|---|---|
ExpiringSession |
createSession()
Creates a new
Session that is capable of being persisted by this SessionRepository. |
void |
delete(String id)
|
ExpiringSession |
getSession(String id)
|
void |
save(ExpiringSession session)
Ensures the
Session created by SessionRepository.createSession() is saved. |
void |
setDefaultMaxInactiveInterval(int defaultMaxInactiveInterval)
If non-null, this value is used to override
ExpiringSession.setMaxInactiveIntervalInSeconds(int). |
public MapSessionRepository()
ConcurrentHashMappublic MapSessionRepository(Map<String,ExpiringSession> sessions)
sessions - the Map to use. Cannot be null.public void setDefaultMaxInactiveInterval(int defaultMaxInactiveInterval)
ExpiringSession.setMaxInactiveIntervalInSeconds(int).defaultMaxInactiveInterval - the number of seconds that the Session should be kept alive between client requests.public void save(ExpiringSession session)
SessionRepositorySession created by SessionRepository.createSession() is saved.
Some implementations may choose to save as the Session is updated by returning a Session that
immediately persists any changes. In this case, this method may not actually do anything.
save in interface SessionRepository<ExpiringSession>session - the Session to savepublic ExpiringSession getSession(String id)
SessionRepositorySession by the Session.getId() or null if no Session is found.
If the Session extends ExpiringSession, then ExpiringSession.getLastAccessedTime() will be
updated on the returned object. In order to persist this change, SessionRepository.save(Session) must be invoked on the returned
instance.
getSession in interface SessionRepository<ExpiringSession>id - the Session.getId() to lookupSession by the Session.getId() or null if no Session is found.public void delete(String id)
SessionRepositorydelete in interface SessionRepository<ExpiringSession>id - the Session.getId() to deletepublic ExpiringSession createSession()
SessionRepositorySession that is capable of being persisted by this SessionRepository.
This allows optimizations and customizations in how the Session is persisted. For example, the
implementation returned might keep track of the changes ensuring that only the delta needs to be persisted on
a save.
createSession in interface SessionRepository<ExpiringSession>Session that is capable of being persisted by this SessionRepository