Class AbstractSessionHandler
- java.lang.Object
-
- com.aspectran.core.component.AbstractComponent
-
- com.aspectran.core.component.session.AbstractSessionHandler
-
- All Implemented Interfaces:
Component,SessionHandler
- Direct Known Subclasses:
DefaultSessionManager
public abstract class AbstractSessionHandler extends AbstractComponent implements SessionHandler
Abstract Implementation of SessionHandler.Created: 2017. 6. 12.
-
-
Constructor Summary
Constructors Constructor Description AbstractSessionHandler()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddSessionListener(SessionListener listener)Adds an event listener for session-related events.voidclearSessionListeners()Removes all event listeners for session-related events.DefaultSessioncreateSession(java.lang.String id)Create an entirely new Session.java.lang.StringcreateSessionId(long seedTerm)Create a new Session ID.protected voiddoDestroy()protected voiddoInitialize()voidfireSessionAttributeListeners(Session session, java.lang.String name, java.lang.Object oldValue, java.lang.Object newValue)Call binding and attribute listeners based on the new and old values of the attribute.voidfireSessionDestroyedListeners(Session session)Call the session lifecycle listeners.java.lang.StringgetComponentName()Returns the component name.intgetDefaultMaxIdleSecs()HouseKeepergetHouseKeeper()SchedulergetScheduler()DefaultSessiongetSession(java.lang.String id)Get a known existing session.SessionCachegetSessionCache()SessionIdGeneratorgetSessionIdGenerator()longgetSessionTimeMax()longgetSessionTimeMean()doublegetSessionTimeStdDev()longgetSessionTimeTotal()java.lang.StringgetWorkerName()voidinvalidate(java.lang.String id)Called when a session has expired.voidinvalidate(java.lang.String id, Session.DestroyedReason reason)voidrecordSessionTime(DefaultSession session)Record length of time session has been active.voidreleaseSession(DefaultSession session)DefaultSessionremoveSession(java.lang.String id, boolean invalidate)Remove session from manager.DefaultSessionremoveSession(java.lang.String id, boolean invalidate, Session.DestroyedReason reason)voidremoveSessionListener(SessionListener listener)Removes an event listener for for session-related events.java.lang.StringrenewSessionId(java.lang.String oldId, java.lang.String newId)Change the id of a Session.voidscavenge()Called periodically by the HouseKeeper to handle the list of sessions that have expired since the last call to scavenge.voidsessionInactivityTimerExpired(DefaultSession session, long now)Each session has a timer that is configured to go off when either the session has not been accessed for a configurable amount of time, or the session itself has passed its expiry.voidsetDefaultMaxIdleSecs(int defaultMaxIdleSecs)protected voidsetHouseKeeper(HouseKeeper houseKeeper)protected voidsetSessionCache(SessionCache sessionCache)protected voidsetSessionIdGenerator(SessionIdGenerator sessionIdGenerator)protected voidsetWorkerName(java.lang.String workerName)voidstatsReset()Resets the session usage statistics.-
Methods inherited from class com.aspectran.core.component.AbstractComponent
destroy, 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.Component
destroy, initialize, isAvailable, isDestroyed, isDestroying, isInitialized
-
-
-
-
Method Detail
-
getScheduler
public Scheduler getScheduler()
- Specified by:
getSchedulerin interfaceSessionHandler
-
getWorkerName
public java.lang.String getWorkerName()
- Specified by:
getWorkerNamein interfaceSessionHandler
-
setWorkerName
protected void setWorkerName(java.lang.String workerName)
-
getSessionIdGenerator
public SessionIdGenerator getSessionIdGenerator()
- Specified by:
getSessionIdGeneratorin interfaceSessionHandler
-
setSessionIdGenerator
protected void setSessionIdGenerator(SessionIdGenerator sessionIdGenerator)
-
getSessionCache
public SessionCache getSessionCache()
- Specified by:
getSessionCachein interfaceSessionHandler
-
setSessionCache
protected void setSessionCache(SessionCache sessionCache)
-
getHouseKeeper
public HouseKeeper getHouseKeeper()
-
setHouseKeeper
protected void setHouseKeeper(HouseKeeper houseKeeper)
-
getDefaultMaxIdleSecs
public int getDefaultMaxIdleSecs()
- Specified by:
getDefaultMaxIdleSecsin interfaceSessionHandler
-
setDefaultMaxIdleSecs
public void setDefaultMaxIdleSecs(int defaultMaxIdleSecs)
- Specified by:
setDefaultMaxIdleSecsin interfaceSessionHandler
-
getSession
public DefaultSession getSession(java.lang.String id)
Description copied from interface:SessionHandlerGet a known existing session.- Specified by:
getSessionin interfaceSessionHandler- Parameters:
id- the session id- Returns:
- a Session or null if none exists
-
createSession
public DefaultSession createSession(java.lang.String id)
Description copied from interface:SessionHandlerCreate an entirely new Session.- Specified by:
createSessionin interfaceSessionHandler- Parameters:
id- identity of session to create- Returns:
- the new session object
-
releaseSession
public void releaseSession(DefaultSession session)
- Specified by:
releaseSessionin interfaceSessionHandler
-
createSessionId
public java.lang.String createSessionId(long seedTerm)
Description copied from interface:SessionHandlerCreate a new Session ID.- Specified by:
createSessionIdin interfaceSessionHandler- Parameters:
seedTerm- the seed for RNG- Returns:
- the new session id
-
renewSessionId
public java.lang.String renewSessionId(java.lang.String oldId, java.lang.String newId)Description copied from interface:SessionHandlerChange the id of a Session.- Specified by:
renewSessionIdin interfaceSessionHandler- Parameters:
oldId- the current session idnewId- the new session id- Returns:
- the Session after changing its id
-
removeSession
public DefaultSession removeSession(java.lang.String id, boolean invalidate)
Description copied from interface:SessionHandlerRemove session from manager.- Specified by:
removeSessionin interfaceSessionHandler- Parameters:
id- the session to removeinvalidate- if false, only remove from cache- Returns:
- if the session was removed
-
removeSession
public DefaultSession removeSession(java.lang.String id, boolean invalidate, Session.DestroyedReason reason)
- Specified by:
removeSessionin interfaceSessionHandler
-
invalidate
public void invalidate(java.lang.String id)
Description copied from interface:SessionHandlerCalled when a session has expired.- Specified by:
invalidatein interfaceSessionHandler- Parameters:
id- the id to invalidate
-
invalidate
public void invalidate(java.lang.String id, Session.DestroyedReason reason)- Specified by:
invalidatein interfaceSessionHandler
-
sessionInactivityTimerExpired
public void sessionInactivityTimerExpired(DefaultSession session, long now)
Description copied from interface:SessionHandlerEach session has a timer that is configured to go off when either the session has not been accessed for a configurable amount of time, or the session itself has passed its expiry. If it has passed its expiry, then we will mark it for scavenging by next run of the HouseKeeper; if it has been idle longer than the configured eviction period, we evict from the cache. If none of the above are true, then the System timer is inconsistent and the caller of this method will need to reset the timer.- Specified by:
sessionInactivityTimerExpiredin interfaceSessionHandler- Parameters:
session- the default sessionnow- the time at which to check for expiry
-
scavenge
public void scavenge()
Description copied from interface:SessionHandlerCalled periodically by the HouseKeeper to handle the list of sessions that have expired since the last call to scavenge.- Specified by:
scavengein interfaceSessionHandler
-
addSessionListener
public void addSessionListener(SessionListener listener)
Description copied from interface:SessionHandlerAdds an event listener for session-related events.- Specified by:
addSessionListenerin interfaceSessionHandler- Parameters:
listener- the session listener- See Also:
SessionHandler.removeSessionListener(SessionListener)
-
removeSessionListener
public void removeSessionListener(SessionListener listener)
Description copied from interface:SessionHandlerRemoves an event listener for for session-related events.- Specified by:
removeSessionListenerin interfaceSessionHandler- Parameters:
listener- the session listener to remove- See Also:
SessionHandler.addSessionListener(SessionListener)
-
clearSessionListeners
public void clearSessionListeners()
Description copied from interface:SessionHandlerRemoves all event listeners for session-related events.- Specified by:
clearSessionListenersin interfaceSessionHandler- See Also:
SessionHandler.removeSessionListener(SessionListener)
-
fireSessionAttributeListeners
public void fireSessionAttributeListeners(Session session, java.lang.String name, java.lang.Object oldValue, java.lang.Object newValue)
Description copied from interface:SessionHandlerCall binding and attribute listeners based on the new and old values of the attribute.- Specified by:
fireSessionAttributeListenersin interfaceSessionHandlername- name of the attributeoldValue- previous value of the attributenewValue- new value of the attribute
-
fireSessionDestroyedListeners
public void fireSessionDestroyedListeners(Session session)
Description copied from interface:SessionHandlerCall the session lifecycle listeners.- Specified by:
fireSessionDestroyedListenersin interfaceSessionHandler- Parameters:
session- the session on which to call the lifecycle listeners
-
recordSessionTime
public void recordSessionTime(DefaultSession session)
Description copied from interface:SessionHandlerRecord length of time session has been active. Called when the session is about to be invalidated.- Specified by:
recordSessionTimein interfaceSessionHandler- Parameters:
session- the session whose time to record
-
getSessionTimeMax
public long getSessionTimeMax()
- Specified by:
getSessionTimeMaxin interfaceSessionHandler- Returns:
- the maximum amount of time session remained valid
-
getSessionTimeTotal
public long getSessionTimeTotal()
- Specified by:
getSessionTimeTotalin interfaceSessionHandler- Returns:
- the total amount of time all sessions remained valid
-
getSessionTimeMean
public long getSessionTimeMean()
- Specified by:
getSessionTimeMeanin interfaceSessionHandler- Returns:
- the mean amount of time session remained valid
-
getSessionTimeStdDev
public double getSessionTimeStdDev()
- Specified by:
getSessionTimeStdDevin interfaceSessionHandler- Returns:
- the standard deviation of amount of time session remained valid
-
statsReset
public void statsReset()
Description copied from interface:SessionHandlerResets the session usage statistics.- Specified by:
statsResetin interfaceSessionHandler
-
doInitialize
protected void doInitialize() throws java.lang.Exception- Specified by:
doInitializein classAbstractComponent- Throws:
java.lang.Exception
-
doDestroy
protected void doDestroy() throws java.lang.Exception- Specified by:
doDestroyin classAbstractComponent- Throws:
java.lang.Exception
-
getComponentName
public java.lang.String getComponentName()
Description copied from interface:ComponentReturns the component name.- Specified by:
getComponentNamein interfaceComponent- Overrides:
getComponentNamein classAbstractComponent- Returns:
- the component name
-
-