SessionCache interface for managing a set of
Session objects pertaining to a context in memory.
This implementation ensures that multiple requests for the same session id
always return the same Session object.
It will delay writing out a session to the SessionDataStore until the
last request exits the session. If the SessionDataStore supports passivation
then the session passivation and activation listeners are called appropriately as
the session is written.
This implementation also supports evicting idle Session objects. An idle Session
is one that is still valid, has not expired, but has not been accessed by a
request for a configurable amount of time. An idle session will be first
passivated before it is evicted from the cache.
| Modifier and Type | Field and Description |
|---|---|
| protected SessionContext | _context
Information about the context to which this SessionCache pertains |
| protected int | _evictionPolicy
When, if ever, to evict sessions: never; only when the last request for them finishes; after inactivity time (expressed as secs) |
| protected boolean | _flushOnResponseCommit
If true, when a response is about to be committed back to the client, a dirty session will be flushed to the session store. |
| protected boolean | _invalidateOnShutdown
If true, when the server shuts down, all sessions in the cache will be invalidated before being removed. |
| protected final SessionManager | _manager
The SessionManager related to this SessionCache |
| protected boolean | _removeUnloadableSessions
If true, a Session whose data cannot be read will be deleted from the SessionDataStore. |
| protected boolean | _saveOnCreate
If true, as soon as a new session is created, it will be persisted to the SessionDataStore |
| protected boolean | _saveOnInactiveEviction
If true, a session that will be evicted from the cache because it has been inactive too long will be saved before being evicted. |
| protected SessionDataStore | _sessionDataStore
The authoritative source of session data |
| private static final Logger |
| Access | Constructor and Description |
|---|---|
| public |
| Modifier and Type | Method and Description |
|---|---|
| public void | add(String
the id id, ManagedSession the session session)Implements org. Add an entirely new session (created by the application calling Request.getSession(true)) to the cache. |
| public Set | checkExpiration(Set<String>
the session ids to check candidates)Implements org. Check a list of session ids that belong to potentially expired sessions. |
| public void | checkInactiveSession(ManagedSession
session to check session)Implements org. Check a session for being inactive and thus being able to be evicted, if eviction is enabled. |
| public void | commit(ManagedSession session)
Implements org. A response that has accessed this session is about to be returned to the client. |
| public boolean | contains(String
the session id id)Implements org. Check to see if this cache contains an entry for the session corresponding to the session id. |
| public ManagedSession | delete(String
the session id id)Implements org. Remove a session object from this store and from any backing store. |
| protected abstract ManagedSession | Returns: an existing Session from the cachethe session id id, Function<String, ManagedSession> the function to load the data for the session mappingFunction)Compute the mappingFunction to create a Session object iff the session with the given id isn't already in the map, otherwise return the existing Session. |
| public abstract ManagedSession | |
| protected abstract ManagedSession | |
| protected abstract Session | Returns: null if the session wasn't already in the map, or the existing entry otherwisethe identity of the session id, ManagedSession the session object session)Put the session into the map if it wasn't already there |
| protected abstract boolean | Returns: true if replacement was donethe id id, ManagedSession the old value oldValue, ManagedSession the new value newValue)Replace the mapping from id to oldValue with newValue |
| protected void | doStart()
Overrides org. Starts the managed lifecycle beans in the order they were added. |
| protected void | doStop()
Overrides org. Stops the managed lifecycle beans in the reverse order they were added. |
| public boolean | exists(String
the session id id)Implements org. Check to see if a session corresponding to the id exists. |
| public ManagedSession | get(String
the session id id)Implements org. Get a session object. |
| protected ManagedSession | Returns: the session if it exists, null otherwiseThe session to retrieve id, boolean if true, the usage count of the session will be incremented enter)Get a session object. |
| public int | |
| public SessionDataStore | getSessionDataStore()
Implements org. Returns: the SessionDataStore or null if there isn't one |
| public SessionManager | getSessionManager()
Implements org. Returns: the SessionManger |
| public void | initialize(SessionContext
the context)SessionContext to use for this cacheImplements org.
|
| public boolean | |
| public boolean | |
| public boolean | isRemoveUnloadableSessions()
Implements org. Returns: true if sessions that can't be loaded are deleted from the store |
| public boolean | |
| public boolean | Returns: true if an inactive session will be saved before being evictedImplements org. Whether we should save a session that has been inactive before we boot it from the cache. |
| private ManagedSession | Returns: a Session object filled with data or null if the session doesn't existthe id id)Load the info for the session from the session data store |
| public abstract ManagedSession | Returns: a new Session objectthe session data data)Redeclares org. Create a new Session object from pre-existing session data |
| public ManagedSession | newSession(String
the unique id associated to the session id, long the timestamp of the session creation time, long the max inactive time in milliseconds maxInactiveMs)Implements org. Create an entirely new Session. |
| public void | release(ManagedSession
the current session object session)Implements org. Finish using the Session object. |
| public ManagedSession | renewSessionId(String
the current session id oldId, String the new session id newId, String the current extended session id oldExtendedId, String the new extended session id newExtendedId)Implements org. Change the id of a Session. |
| protected void | renewSessionId(ManagedSession
the session for which to do the swap session, String the new id newId, String the full id plus node id newExtendedId)Swap the id on a session. |
| public void | setEvictionPolicy(int
-1 is never evict; 0 is evict-on-exit; and any other positive
value is the time in seconds that a session can be idle before it can
be evicted. evictionTimeout)Implements org. -1 means we never evict inactive sessions. |
| public void | setFlushOnResponseCommit(boolean flushOnResponseCommit)
Implements org. If true, a dirty session will be written to the SessionDataStore just before a response is returned to the client. |
| public void | setInvalidateOnShutdown(boolean
true invalidate all sessions in cache on server shutdown invalidateOnShutdown)Implements org. If true, all existing sessions in the cache will be invalidated when the server shuts down. |
| public void | setRemoveUnloadableSessions(boolean
if removeUnloadableSessions)true unloadable sessions will be removed from session storeImplements org. If a session's data cannot be loaded from the store without error, remove it from the persistent store. |
| public void | setSaveOnCreate(boolean
true to immediately save the newly created sessionImplements org. Whether or not a session that is newly created should be immediately saved. |
| public void | setSaveOnInactiveEviction(boolean
true if the session should be saved before being evictedImplements org. Whether or not a a session that is about to be evicted should be saved before being evicted. |
| public void | setSessionDataStore(SessionDataStore
the sessionStore)SessionDataStore to useImplements org. A SessionDataStore that is the authoritative source of session information. |
| public String | toString()
Overrides org. Returns a string representation of the object. |
| _context | back to summary |
|---|---|
| protected SessionContext _context Information about the context to which this SessionCache pertains | |
| _evictionPolicy | back to summary |
|---|---|
| protected int _evictionPolicy When, if ever, to evict sessions: never; only when the last request for them finishes; after inactivity time (expressed as secs) | |
| _flushOnResponseCommit | back to summary |
|---|---|
| protected boolean _flushOnResponseCommit If true, when a response is about to be committed back to the client, a dirty session will be flushed to the session store. | |
| _invalidateOnShutdown | back to summary |
|---|---|
| protected boolean _invalidateOnShutdown If true, when the server shuts down, all sessions in the cache will be invalidated before being removed. | |
| _manager | back to summary |
|---|---|
| protected final SessionManager _manager The SessionManager related to this SessionCache | |
| _removeUnloadableSessions | back to summary |
|---|---|
| protected boolean _removeUnloadableSessions If true, a Session whose data cannot be read will be deleted from the SessionDataStore. | |
| _saveOnCreate | back to summary |
|---|---|
| protected boolean _saveOnCreate If true, as soon as a new session is created, it will be persisted to the SessionDataStore | |
| _saveOnInactiveEviction | back to summary |
|---|---|
| protected boolean _saveOnInactiveEviction If true, a session that will be evicted from the cache because it has been inactive too long will be saved before being evicted. | |
| _sessionDataStore | back to summary |
|---|---|
| protected SessionDataStore _sessionDataStore The authoritative source of session data | |
| LOG | back to summary |
|---|---|
| private static final Logger LOG Hides org. | |
| AbstractSessionCache | back to summary |
|---|---|
public AbstractSessionCache(SessionManager handler)
| |
| add | back to summary |
|---|---|
| public void add(String id, ManagedSession session) throws Exception Implements org. Add an entirely new session (created by the application calling Request.getSession(true)) to the cache. The usage count of the fresh session is incremented.
| |
| checkExpiration | back to summary |
|---|---|
| public Set Implements org. Doc from org. Check a list of session ids that belong to potentially expired sessions. The Session in the cache should be checked, but also the SessionDataStore, as that is the authoritative source of all session information. | |
| checkInactiveSession | back to summary |
|---|---|
| public void checkInactiveSession(ManagedSession session) Implements org. Check a session for being inactive and thus being able to be evicted, if eviction is enabled.
| |
| commit | back to summary |
|---|---|
| public void commit(ManagedSession session) throws Exception Implements org. A response that has accessed this session is about to be returned to the client. Pass the session to the store to persist, so that any changes will be visible to subsequent requests on the same node (if using NullSessionCache), or on other nodes.
| |
| contains | back to summary |
|---|---|
| public boolean contains(String id) throws Exception Implements org. Check to see if this cache contains an entry for the session corresponding to the session id.
| |
| delete | back to summary |
|---|---|
| public ManagedSession delete(String id) throws Exception Implements org. Remove a session object from this store and from any backing store.
| |
| doComputeIfAbsent | back to summary |
|---|---|
| protected abstract ManagedSession doComputeIfAbsent(String id, Function<String, ManagedSession> mappingFunction) Compute the mappingFunction to create a Session object iff the session
with the given id isn't already in the map, otherwise return the existing Session.
This method is expected to have precisely the same behaviour as
| |
| doDelete | back to summary |
|---|---|
| public abstract ManagedSession doDelete(String id) Remove the session with this identity from the store
| |
| doGet | back to summary |
|---|---|
| protected abstract ManagedSession doGet(String id) Get the session matching the key from the cache. Does not load the session.
| |
| doPutIfAbsent | back to summary |
|---|---|
| protected abstract Session doPutIfAbsent(String id, ManagedSession session) Put the session into the map if it wasn't already there
| |
| doReplace | back to summary |
|---|---|
| protected abstract boolean doReplace(String id, ManagedSession oldValue, ManagedSession newValue) Replace the mapping from id to oldValue with newValue
| |
| doStart | back to summary |
|---|---|
| protected void doStart() throws Exception Overrides org. Doc from org. Starts the managed lifecycle beans in the order they were added.
| |
| doStop | back to summary |
|---|---|
| protected void doStop() throws Exception Overrides org. Doc from org. Stops the managed lifecycle beans in the reverse order they were added.
| |
| exists | back to summary |
|---|---|
| public boolean exists(String id) throws Exception Implements org. Check to see if a session corresponding to the id exists. This method will first check with the object store. If it doesn't exist in the object store (might be passivated etc), it will check with the data store.
| |
| get | back to summary |
|---|---|
| public ManagedSession get(String id) throws Exception Implements org. Get a session object. If the session object is not in this session store, try getting the data for it from a SessionDataStore associated with the session manager. The usage count of the session is incremented.
| |
| getAndEnter | back to summary |
|---|---|
| protected ManagedSession getAndEnter(String id, boolean enter) throws Exception Get a session object. If the session object is not in this session store, try getting the data for it from a SessionDataStore associated with the session manager.
| |
| getEvictionPolicy | back to summary |
|---|---|
| public int getEvictionPolicy() Implements org.
| |
| getSessionDataStore | back to summary |
|---|---|
| public SessionDataStore getSessionDataStore() Implements org.
| |
| getSessionManager | back to summary |
|---|---|
| public SessionManager getSessionManager() Implements org.
| |
| initialize | back to summary |
|---|---|
| public void initialize(SessionContext context) Implements org.
| |
| isFlushOnResponseCommit | back to summary |
|---|---|
| public boolean isFlushOnResponseCommit() Implements org.
| |
| isInvalidateOnShutdown | back to summary |
|---|---|
| public boolean isInvalidateOnShutdown() Implements org.
| |
| isRemoveUnloadableSessions | back to summary |
|---|---|
| public boolean isRemoveUnloadableSessions() Implements org.
| |
| isSaveOnCreate | back to summary |
|---|---|
| public boolean isSaveOnCreate() Implements org.
| |
| isSaveOnInactiveEviction | back to summary |
|---|---|
| public boolean isSaveOnInactiveEviction() Implements org. Whether we should save a session that has been inactive before we boot it from the cache.
| |
| loadSession | back to summary |
|---|---|
| private ManagedSession loadSession(String id) throws Exception Load the info for the session from the session data store
| |
| newSession | back to summary |
|---|---|
| public abstract ManagedSession newSession(SessionData data) Redeclares org. Create a new Session object from pre-existing session data
| |
| newSession | back to summary |
|---|---|
| public ManagedSession newSession(String id, long time, long maxInactiveMs) Implements org. Doc from org. Create an entirely new Session.
| |
| release | back to summary |
|---|---|
| public void release(ManagedSession session) throws Exception Implements org. Finish using the Session object. This should be called when a request exists the session. Only when the last simultaneous request exists the session will any action be taken. If there is a SessionDataStore write the session data through to it. If the SessionDataStore supports passivation, call the passivate/active listeners. If the evictionPolicy == SessionCache.EVICT_ON_SESSION_EXIT then after we have saved the session, we evict it from the cache.
| |
| renewSessionId | back to summary |
|---|---|
| public ManagedSession renewSessionId(String oldId, String newId, String oldExtendedId, String newExtendedId) throws Exception Implements org. Doc from org. Change the id of a Session. | |
| renewSessionId | back to summary |
|---|---|
| protected void renewSessionId(ManagedSession session, String newId, String newExtendedId) throws Exception Swap the id on a session.
| |
| setEvictionPolicy | back to summary |
|---|---|
| public void setEvictionPolicy(int evictionTimeout) Implements org. -1 means we never evict inactive sessions. 0 means we evict a session after the last request for it exits >0 is the number of seconds after which we evict inactive sessions from the cache
| |
| setFlushOnResponseCommit | back to summary |
|---|---|
| public void setFlushOnResponseCommit(boolean flushOnResponseCommit) Implements org. Doc from org. If true, a dirty session will be written to the SessionDataStore just before a response is returned to the client. This ensures that subsequent requests to either the same node or a different node see the changed session data.
| |
| setInvalidateOnShutdown | back to summary |
|---|---|
| public void setInvalidateOnShutdown(boolean invalidateOnShutdown) Implements org. Doc from org. If true, all existing sessions in the cache will be invalidated when the server shuts down. Default is false.
| |
| setRemoveUnloadableSessions | back to summary |
|---|---|
| public void setRemoveUnloadableSessions(boolean removeUnloadableSessions) Implements org. If a session's data cannot be loaded from the store without error, remove it from the persistent store.
| |
| setSaveOnCreate | back to summary |
|---|---|
| public void setSaveOnCreate(boolean saveOnCreate) Implements org. Doc from org. Whether or not a session that is newly created should be immediately saved. If false, a session that is created and invalidated within a single request is never persisted.
| |
| setSaveOnInactiveEviction | back to summary |
|---|---|
| public void setSaveOnInactiveEviction(boolean saveOnEvict) Implements org. Doc from org. Whether or not a a session that is about to be evicted should be saved before being evicted.
| |
| setSessionDataStore | back to summary |
|---|---|
| public void setSessionDataStore(SessionDataStore sessionStore) Implements org. Doc from org. A SessionDataStore that is the authoritative source of session information.
| |
| toString | back to summary |
|---|---|
| public String toString() Overrides org. Doc from java. Returns a string representation of the object.
Satisfying this method's contract implies a non- | |