Class AbstractSessionCache
- java.lang.Object
-
- com.aspectran.core.component.session.AbstractSessionCache
-
- All Implemented Interfaces:
SessionCache
- Direct Known Subclasses:
DefaultSessionCache
public abstract class AbstractSessionCache extends java.lang.Object implements SessionCache
Created: 2017. 6. 24.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected class
AbstractSessionCache.PlaceHolderSession
PlaceHolder
-
Field Summary
Fields Modifier and Type Field Description 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
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 SessionDataStoreprotected 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
protected SessionHandler
sessionHandler
-
Fields inherited from interface com.aspectran.core.component.session.SessionCache
EVICT_ON_INACTIVITY, EVICT_ON_SESSION_EXIT, NEVER_EVICT
-
-
Constructor Summary
Constructors Constructor Description AbstractSessionCache(SessionHandler sessionHandler)
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description java.util.Set<java.lang.String>
checkExpiration(java.util.Set<java.lang.String> candidates)
Check a list of session ids that belong to potentially expired sessions.void
checkInactiveSession(Session session)
Check a session for being inactive and thus being able to be evicted, if eviction is enabled.boolean
contains(java.lang.String id)
Check to see if this cache contains an entry for the session corresponding to the session id.Session
delete(java.lang.String id)
Remove a session object from this store and from any backing store.abstract Session
doDelete(java.lang.String id)
Remove the session with this identity from the store.abstract Session
doGet(java.lang.String id)
Get the session matching the key.abstract Session
doPutIfAbsent(java.lang.String id, Session session)
Put the session into the map if it wasn't already there.abstract boolean
doReplace(java.lang.String id, Session oldValue, Session newValue)
Replace the mapping from id to oldValue with newValue.boolean
exists(java.lang.String id)
Check to see if a session corresponding to the id exists.Session
get(java.lang.String id)
Get a session object.int
getEvictionPolicy()
SessionDataStore
getSessionDataStore()
protected SessionHandler
getSessionHandler()
boolean
isRemoveUnloadableSessions()
boolean
isSaveOnCreate()
boolean
isSaveOnInactiveEviction()
Whether we should save a session that has been inactive before we boot it from the cache.abstract Session
newSession(SessionData data)
Create a new Session object from pre-existing session data.Session
newSession(java.lang.String id, long time, long maxInactiveIntervalMS)
void
put(java.lang.String id, Session session)
Put the Session object back into the session store.void
setEvictionPolicy(int evictionTimeout)
-1 means we never evict inactive sessions.void
setRemoveUnloadableSessions(boolean removeUnloadableSessions)
If a session's data cannot be loaded from the store without error, remove it from the persistent store.void
setSaveOnCreate(boolean saveOnCreate)
Whether or not a session that is newly created should be immediately saved.void
setSaveOnInactiveEviction(boolean saveOnEvict)
Whether or not a a session that is about to be evicted should be saved before being evicted.void
setSessionDataStore(SessionDataStore sessionDataStore)
A SessionDataStore that is the authoritative source of session information.-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface com.aspectran.core.component.session.SessionCache
clear, getSessionsCurrent, getSessionsMax, getSessionsTotal, resetStats
-
-
-
-
Field Detail
-
sessionHandler
protected final SessionHandler sessionHandler
-
sessionDataStore
protected SessionDataStore sessionDataStore
-
evictionPolicy
protected int evictionPolicy
When, if ever, to evict sessions: never; only when the last request for them finishes; after inactivity time (expressed as secs)
-
saveOnCreate
protected boolean saveOnCreate
If true, as soon as a new session is created, it will be persisted to the SessionDataStore
-
saveOnInactiveEviction
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.
-
removeUnloadableSessions
protected boolean removeUnloadableSessions
If true, a Session whose data cannot be read will be deleted from the SessionDataStore.
-
-
Constructor Detail
-
AbstractSessionCache
public AbstractSessionCache(SessionHandler sessionHandler)
-
-
Method Detail
-
getSessionHandler
protected SessionHandler getSessionHandler()
-
getSessionDataStore
public SessionDataStore getSessionDataStore()
- Specified by:
getSessionDataStore
in interfaceSessionCache
-
setSessionDataStore
public void setSessionDataStore(SessionDataStore sessionDataStore)
Description copied from interface:SessionCache
A SessionDataStore that is the authoritative source of session information.- Specified by:
setSessionDataStore
in interfaceSessionCache
- Parameters:
sessionDataStore
- the session data store
-
getEvictionPolicy
public int getEvictionPolicy()
- Specified by:
getEvictionPolicy
in interfaceSessionCache
-
setEvictionPolicy
public void setEvictionPolicy(int evictionTimeout)
-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- Specified by:
setEvictionPolicy
in interfaceSessionCache
- Parameters:
evictionTimeout
- -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.
-
isSaveOnCreate
public boolean isSaveOnCreate()
- Specified by:
isSaveOnCreate
in interfaceSessionCache
-
setSaveOnCreate
public void setSaveOnCreate(boolean saveOnCreate)
Description copied from interface:SessionCache
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.- Specified by:
setSaveOnCreate
in interfaceSessionCache
- Parameters:
saveOnCreate
- if true, immediately save the newly created session
-
isRemoveUnloadableSessions
public boolean isRemoveUnloadableSessions()
- Specified by:
isRemoveUnloadableSessions
in interfaceSessionCache
- Returns:
- true if sessions that can't be loaded are deleted from the store
-
setRemoveUnloadableSessions
public void setRemoveUnloadableSessions(boolean removeUnloadableSessions)
If a session's data cannot be loaded from the store without error, remove it from the persistent store.- Specified by:
setRemoveUnloadableSessions
in interfaceSessionCache
- Parameters:
removeUnloadableSessions
- whether to delete sessions that can not be loaded
-
isSaveOnInactiveEviction
public boolean isSaveOnInactiveEviction()
Whether we should save a session that has been inactive before we boot it from the cache.- Specified by:
isSaveOnInactiveEviction
in interfaceSessionCache
- Returns:
- true if an inactive session will be saved before being evicted
-
setSaveOnInactiveEviction
public void setSaveOnInactiveEviction(boolean saveOnEvict)
Description copied from interface:SessionCache
Whether or not a a session that is about to be evicted should be saved before being evicted.- Specified by:
setSaveOnInactiveEviction
in interfaceSessionCache
- Parameters:
saveOnEvict
- if true, save the session before eviction
-
get
public Session get(java.lang.String id) throws java.lang.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.- Specified by:
get
in interfaceSessionCache
- Parameters:
id
- the session id- Returns:
- the Session if one exists, null otherwise
- Throws:
java.lang.Exception
- if an error occurs
-
put
public void put(java.lang.String id, Session session) throws java.lang.Exception
Put the Session object back into the session store.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.
- Specified by:
put
in interfaceSessionCache
- Parameters:
id
- the session idsession
- the session object- Throws:
java.lang.Exception
- if an error occurs
-
exists
public boolean exists(java.lang.String id) throws java.lang.Exception
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.- Specified by:
exists
in interfaceSessionCache
- Parameters:
id
- the session id- Returns:
- true if the session exists; false otherwise
- Throws:
java.lang.Exception
- the Exception
-
contains
public boolean contains(java.lang.String id) throws java.lang.Exception
Check to see if this cache contains an entry for the session corresponding to the session id.- Specified by:
contains
in interfaceSessionCache
- Parameters:
id
- the session id- Returns:
- true if a Session object matching the id is present in the cache; false otherwise
- Throws:
java.lang.Exception
- if an error occurs
-
delete
public Session delete(java.lang.String id) throws java.lang.Exception
Remove a session object from this store and from any backing store.- Specified by:
delete
in interfaceSessionCache
- Parameters:
id
- the session id- Returns:
- the Session that was removed, null otherwise
- Throws:
java.lang.Exception
- if an error occurs when deleting a session
-
checkExpiration
public java.util.Set<java.lang.String> checkExpiration(java.util.Set<java.lang.String> candidates)
Description copied from interface:SessionCache
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.- Specified by:
checkExpiration
in interfaceSessionCache
- Parameters:
candidates
- the session ids to check- Returns:
- the set of session ids that have actually expired: this can be a superset of the original candidate list.
-
checkInactiveSession
public void checkInactiveSession(Session session)
Check a session for being inactive and thus being able to be evicted, if eviction is enabled.- Specified by:
checkInactiveSession
in interfaceSessionCache
- Parameters:
session
- session to check
-
newSession
public Session newSession(java.lang.String id, long time, long maxInactiveIntervalMS)
- Specified by:
newSession
in interfaceSessionCache
-
newSession
public abstract Session newSession(SessionData data)
Create a new Session object from pre-existing session data.- Specified by:
newSession
in interfaceSessionCache
- Parameters:
data
- the session data- Returns:
- a new Session object
-
doGet
public abstract Session doGet(java.lang.String id)
Get the session matching the key.- Parameters:
id
- the session id- Returns:
- the Session object matching the id
-
doPutIfAbsent
public abstract Session doPutIfAbsent(java.lang.String id, Session session)
Put the session into the map if it wasn't already there.- Parameters:
id
- the identity of the sessionsession
- the session object- Returns:
- null if the session wasn't already in the map, or the existing entry otherwise
-
doReplace
public abstract boolean doReplace(java.lang.String id, Session oldValue, Session newValue)
Replace the mapping from id to oldValue with newValue.- Parameters:
id
- the session idoldValue
- the old valuenewValue
- the new value- Returns:
- true if replacement was done
-
doDelete
public abstract Session doDelete(java.lang.String id)
Remove the session with this identity from the store.- Parameters:
id
- the session id- Returns:
- true if removed; false otherwise
-
-