Class AbstractSessionCache
- java.lang.Object
-
- com.aspectran.core.component.AbstractComponent
-
- com.aspectran.core.component.session.AbstractSessionCache
-
- All Implemented Interfaces:
Component,SessionCache
- Direct Known Subclasses:
DefaultSessionCache
public abstract class AbstractSessionCache extends AbstractComponent implements SessionCache
A base implementation of theSessionCacheinterface for managing a set of Session objects pertaining to a context in memory.Created: 2017. 6. 24.
-
-
Field Summary
-
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, SessionStore sessionStore, boolean clustered)
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description DefaultSessionadd(java.lang.String id, long time, long maxInactiveInterval)Add an entirely new session to the cache.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.voidcheckInactiveSession(DefaultSession session)Check a session for being inactive and thus being able to be evicted, if eviction is enabled.booleancontains(java.lang.String id)Check to see if a Session is in the cache.DefaultSessiondelete(java.lang.String id)Remove a Session completely: from both this cache and the SessionStore.abstract DefaultSessiondoDelete(java.lang.String id)Remove the session with this identity from the store.abstract DefaultSessiondoGet(java.lang.String id)Get the session matching the key.abstract DefaultSessiondoPutIfAbsent(java.lang.String id, DefaultSession session)Put the session into the map if it wasn't already there.abstract booleandoReplace(java.lang.String id, DefaultSession oldValue, DefaultSession newValue)Replace the mapping from id to oldValue with newValue.booleanexists(java.lang.String id)Check to see if a session exists: WILL consult the SessionStore.DefaultSessionget(java.lang.String id)Get an existing Session.intgetEvictionIdleSecs()protected SessionHandlergetSessionHandler()protected SessionStoregetSessionStore()booleanisClustered()booleanisRemoveUnloadableSessions()booleanisSaveOnCreate()booleanisSaveOnInactiveEviction()Whether we should save a session that has been inactive before we boot it from the cache.voidrelease(java.lang.String id, DefaultSession session)Finish using a Session.protected voidrenewSessionId(DefaultSession session, java.lang.String newId)Swap the id on a session.DefaultSessionrenewSessionId(java.lang.String oldId, java.lang.String newId)Change the id of a Session.voidsetEvictionIdleSecs(int evictionTimeout)-1 means we never evict inactive sessions.voidsetRemoveUnloadableSessions(boolean removeUnloadableSessions)If a session's data cannot be loaded from the store without error, remove it from the persistent store.voidsetSaveOnCreate(boolean saveOnCreate)Whether or not a session that is newly created should be immediately saved.voidsetSaveOnInactiveEviction(boolean saveOnEvict)Whether or not a a session that is about to be evicted should be saved before being evicted.-
Methods inherited from class com.aspectran.core.component.AbstractComponent
destroy, doDestroy, doInitialize, getComponentName, initialize, isAvailable, isDestroyed, isDestroying, isInitialized
-
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
destroy, getActiveSessionCount, getAllSessions, getCreatedSessionCount, getExpiredSessionCount, getHighestSessionCount, getMaxSessions, getRejectedSessionCount, resetStatistics, setMaxSessions
-
-
-
-
Constructor Detail
-
AbstractSessionCache
public AbstractSessionCache(SessionHandler sessionHandler, SessionStore sessionStore, boolean clustered)
-
-
Method Detail
-
getSessionHandler
protected SessionHandler getSessionHandler()
-
getSessionStore
protected SessionStore getSessionStore()
-
isClustered
public boolean isClustered()
- Specified by:
isClusteredin interfaceSessionCache
-
getEvictionIdleSecs
public int getEvictionIdleSecs()
- Specified by:
getEvictionIdleSecsin interfaceSessionCache
-
setEvictionIdleSecs
public void setEvictionIdleSecs(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:
setEvictionIdleSecsin 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:
isSaveOnCreatein interfaceSessionCache- Returns:
- if true the newly created session will be saved immediately
-
setSaveOnCreate
public void setSaveOnCreate(boolean saveOnCreate)
Description copied from interface:SessionCacheWhether 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:
setSaveOnCreatein interfaceSessionCache- Parameters:
saveOnCreate- if true, immediately save the newly created session
-
isSaveOnInactiveEviction
public boolean isSaveOnInactiveEviction()
Whether we should save a session that has been inactive before we boot it from the cache.- Specified by:
isSaveOnInactiveEvictionin interfaceSessionCache- Returns:
- true if an inactive session will be saved before being evicted
-
setSaveOnInactiveEviction
public void setSaveOnInactiveEviction(boolean saveOnEvict)
Description copied from interface:SessionCacheWhether or not a a session that is about to be evicted should be saved before being evicted.- Specified by:
setSaveOnInactiveEvictionin interfaceSessionCache- Parameters:
saveOnEvict- if true, save the session before eviction
-
isRemoveUnloadableSessions
public boolean isRemoveUnloadableSessions()
- Specified by:
isRemoveUnloadableSessionsin 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:
setRemoveUnloadableSessionsin interfaceSessionCache- Parameters:
removeUnloadableSessions- whether to delete sessions that can not be loaded
-
get
public DefaultSession get(java.lang.String id) throws java.lang.Exception
Description copied from interface:SessionCacheGet an existing Session. If necessary, the cache will load the data for the session from the configured SessionStore.- Specified by:
getin interfaceSessionCache- Parameters:
id- the session id- Returns:
- the Session if one exists, null otherwise
- Throws:
java.lang.Exception- if an error occurs
-
add
public DefaultSession add(java.lang.String id, long time, long maxInactiveInterval) throws java.lang.Exception
Description copied from interface:SessionCacheAdd an entirely new session to the cache.- Specified by:
addin interfaceSessionCache- Parameters:
id- the session idtime- the timestamp of the session creationmaxInactiveInterval- the max inactive time in milliseconds- Throws:
java.lang.Exception
-
release
public void release(java.lang.String id, DefaultSession session) throws java.lang.ExceptionDescription copied from interface:SessionCacheFinish using a Session. This is called by the SessionHandler once a request is finished with a Session. SessionCache implementations may want to delay writing out Session contents until the last request exits a Session.- Specified by:
releasein 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.ExceptionDescription copied from interface:SessionCacheCheck to see if a session exists: WILL consult the SessionStore.- Specified by:
existsin interfaceSessionCache- Parameters:
id- the session id- Returns:
- true if the session exists; false otherwise
- Throws:
java.lang.Exception- if an error occurs
-
contains
public boolean contains(java.lang.String id) throws java.lang.ExceptionDescription copied from interface:SessionCacheCheck to see if a Session is in the cache. Does NOT consult the SessionStore.- Specified by:
containsin 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 DefaultSession delete(java.lang.String id) throws java.lang.Exception
Description copied from interface:SessionCacheRemove a Session completely: from both this cache and the SessionStore.- Specified by:
deletein 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
-
doGet
public abstract DefaultSession 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 DefaultSession doPutIfAbsent(java.lang.String id, DefaultSession 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, DefaultSession oldValue, DefaultSession 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 DefaultSession 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
-
renewSessionId
public DefaultSession renewSessionId(java.lang.String oldId, java.lang.String newId) throws java.lang.Exception
Description copied from interface:SessionCacheChange the id of a Session.- Specified by:
renewSessionIdin interfaceSessionCache- Parameters:
oldId- the current session idnewId- the new session id- Returns:
- the Session after changing its id
- Throws:
java.lang.Exception- if any error occurred
-
renewSessionId
protected void renewSessionId(DefaultSession session, java.lang.String newId) throws java.lang.Exception
Swap the id on a session.- Parameters:
session- the session for which to do the swapnewId- the new id- Throws:
java.lang.Exception- if there was a failure saving the change
-
checkExpiration
public java.util.Set<java.lang.String> checkExpiration(java.util.Set<java.lang.String> candidates)
Description copied from interface:SessionCacheCheck a list of session ids that belong to potentially expired sessions. The Session in the cache should be checked, but also the SessionStore, as that is the authoritative source of all session information.- Specified by:
checkExpirationin 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(DefaultSession session)
Check a session for being inactive and thus being able to be evicted, if eviction is enabled.- Specified by:
checkInactiveSessionin interfaceSessionCache- Parameters:
session- the session to check
-
-