public class MapSessionRepository extends java.lang.Object implements SessionRepository<MapSession>
SessionRepository
backed by a Map
and that uses a
MapSession
. The injected Map
can be backed by a distributed
NoSQL store like Hazelcast, for instance. Note that the supplied map itself is
responsible for purging the expired sessions.
The implementation does NOT support firing SessionDeletedEvent
or
SessionExpiredEvent
.
Constructor and Description |
---|
MapSessionRepository(java.util.Map<java.lang.String,Session> sessions)
Creates a new instance backed by the provided
Map . |
Modifier and Type | Method and Description |
---|---|
MapSession |
createSession()
Creates a new
Session that is capable of being persisted by this
SessionRepository . |
void |
deleteById(java.lang.String id)
|
MapSession |
findById(java.lang.String id)
|
void |
save(MapSession session)
Ensures the
Session created by
SessionRepository.createSession() is saved. |
void |
setDefaultMaxInactiveInterval(int defaultMaxInactiveInterval)
If non-null, this value is used to override
Session.setMaxInactiveInterval(Duration) . |
public MapSessionRepository(java.util.Map<java.lang.String,Session> sessions)
Map
. This allows
injecting a distributed Map
.sessions
- the Map
to use. Cannot be null.public void setDefaultMaxInactiveInterval(int defaultMaxInactiveInterval)
Session.setMaxInactiveInterval(Duration)
.defaultMaxInactiveInterval
- the number of seconds that the Session
should be kept alive between client requests.public void save(MapSession session)
SessionRepository
Session
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<MapSession>
session
- the Session
to savepublic MapSession findById(java.lang.String id)
SessionRepository
findById
in interface SessionRepository<MapSession>
id
- the Session.getId()
to lookupSession
by the Session.getId()
or null if no
Session
is found.public void deleteById(java.lang.String id)
SessionRepository
deleteById
in interface SessionRepository<MapSession>
id
- the Session.getId()
to deletepublic MapSession createSession()
SessionRepository
Session
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<MapSession>
Session
that is capable of being persisted by this
SessionRepository