public class MapSessionRepository extends java.lang.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 SessionDeletedEvent
or
SessionExpiredEvent
.
Constructor and Description |
---|
MapSessionRepository()
Creates an instance backed by a
ConcurrentHashMap . |
MapSessionRepository(java.util.Map<java.lang.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(java.lang.String id)
|
ExpiringSession |
getSession(java.lang.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()
ConcurrentHashMap
.public MapSessionRepository(java.util.Map<java.lang.String,ExpiringSession> sessions)
Map
. This allows
injecting a distributed Map
.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)
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<ExpiringSession>
session
- the Session
to savepublic ExpiringSession getSession(java.lang.String id)
SessionRepository
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(java.lang.String id)
SessionRepository
delete
in interface SessionRepository<ExpiringSession>
id
- the Session.getId()
to deletepublic ExpiringSession 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<ExpiringSession>
Session
that is capable of being persisted by this
SessionRepository