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 void
addSessionListener(SessionListener listener)
Adds an event listener for session-related events.void
clearSessionListeners()
Removes all event listeners for session-related events.BasicSession
createSession(java.lang.String id)
Create an entirely new Session.java.lang.String
createSessionId(long seedTerm)
Create a new Session ID.protected void
doDestroy()
protected void
doInitialize()
void
fireSessionAttributeListeners(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.void
fireSessionDestroyedListeners(Session session)
Call the session lifecycle listeners.java.lang.String
getComponentName()
Returns the component name.int
getDefaultMaxIdleSecs()
HouseKeeper
getHouseKeeper()
Scheduler
getScheduler()
BasicSession
getSession(java.lang.String id)
Get a known existing session.SessionCache
getSessionCache()
SessionIdGenerator
getSessionIdGenerator()
long
getSessionTimeMax()
long
getSessionTimeMean()
double
getSessionTimeStdDev()
long
getSessionTimeTotal()
java.lang.String
getWorkerName()
void
invalidate(java.lang.String id)
Called when a session has expired.void
invalidate(java.lang.String id, Session.DestroyedReason reason)
void
recordSessionTime(BasicSession session)
Record length of time session has been active.void
releaseSession(BasicSession session)
BasicSession
removeSession(java.lang.String id, boolean invalidate)
Remove session from manager.BasicSession
removeSession(java.lang.String id, boolean invalidate, Session.DestroyedReason reason)
void
removeSessionListener(SessionListener listener)
Removes an event listener for for session-related events.java.lang.String
renewSessionId(java.lang.String oldId, java.lang.String newId)
Change the id of a Session.void
scavenge()
Called periodically by the HouseKeeper to handle the list of sessions that have expired since the last call to scavenge.void
sessionInactivityTimerExpired(BasicSession 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.void
setDefaultMaxIdleSecs(int defaultMaxIdleSecs)
protected void
setHouseKeeper(HouseKeeper houseKeeper)
protected void
setSessionCache(SessionCache sessionCache)
protected void
setSessionIdGenerator(SessionIdGenerator sessionIdGenerator)
void
setWorkerName(java.lang.String workerName)
void
statsReset()
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
-
getWorkerName
public java.lang.String getWorkerName()
- Specified by:
getWorkerName
in interfaceSessionHandler
-
setWorkerName
public void setWorkerName(java.lang.String workerName)
-
getScheduler
public Scheduler getScheduler()
- Specified by:
getScheduler
in interfaceSessionHandler
-
getSessionIdGenerator
public SessionIdGenerator getSessionIdGenerator()
- Specified by:
getSessionIdGenerator
in interfaceSessionHandler
-
setSessionIdGenerator
protected void setSessionIdGenerator(SessionIdGenerator sessionIdGenerator)
-
getSessionCache
public SessionCache getSessionCache()
- Specified by:
getSessionCache
in interfaceSessionHandler
-
setSessionCache
protected void setSessionCache(SessionCache sessionCache)
-
getHouseKeeper
public HouseKeeper getHouseKeeper()
-
setHouseKeeper
protected void setHouseKeeper(HouseKeeper houseKeeper)
-
getDefaultMaxIdleSecs
public int getDefaultMaxIdleSecs()
- Specified by:
getDefaultMaxIdleSecs
in interfaceSessionHandler
-
setDefaultMaxIdleSecs
public void setDefaultMaxIdleSecs(int defaultMaxIdleSecs)
- Specified by:
setDefaultMaxIdleSecs
in interfaceSessionHandler
-
getSession
public BasicSession getSession(java.lang.String id)
Description copied from interface:SessionHandler
Get a known existing session.- Specified by:
getSession
in interfaceSessionHandler
- Parameters:
id
- the session id- Returns:
- a Session or null if none exists
-
createSession
public BasicSession createSession(java.lang.String id)
Description copied from interface:SessionHandler
Create an entirely new Session.- Specified by:
createSession
in interfaceSessionHandler
- Parameters:
id
- identity of session to create- Returns:
- the new session object
-
releaseSession
public void releaseSession(BasicSession session)
- Specified by:
releaseSession
in interfaceSessionHandler
-
createSessionId
public java.lang.String createSessionId(long seedTerm)
Description copied from interface:SessionHandler
Create a new Session ID.- Specified by:
createSessionId
in 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:SessionHandler
Change the id of a Session.- Specified by:
renewSessionId
in interfaceSessionHandler
- Parameters:
oldId
- the current session idnewId
- the new session id- Returns:
- the Session after changing its id
-
removeSession
public BasicSession removeSession(java.lang.String id, boolean invalidate)
Description copied from interface:SessionHandler
Remove session from manager.- Specified by:
removeSession
in interfaceSessionHandler
- Parameters:
id
- the session to removeinvalidate
- if false, only remove from cache- Returns:
- if the session was removed
-
removeSession
public BasicSession removeSession(java.lang.String id, boolean invalidate, Session.DestroyedReason reason)
- Specified by:
removeSession
in interfaceSessionHandler
-
invalidate
public void invalidate(java.lang.String id)
Description copied from interface:SessionHandler
Called when a session has expired.- Specified by:
invalidate
in interfaceSessionHandler
- Parameters:
id
- the id to invalidate
-
invalidate
public void invalidate(java.lang.String id, Session.DestroyedReason reason)
- Specified by:
invalidate
in interfaceSessionHandler
-
sessionInactivityTimerExpired
public void sessionInactivityTimerExpired(BasicSession session, long now)
Description copied from interface:SessionHandler
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. 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:
sessionInactivityTimerExpired
in interfaceSessionHandler
- Parameters:
session
- the basic sessionnow
- the time at which to check for expiry
-
scavenge
public void scavenge()
Description copied from interface:SessionHandler
Called periodically by the HouseKeeper to handle the list of sessions that have expired since the last call to scavenge.- Specified by:
scavenge
in interfaceSessionHandler
-
addSessionListener
public void addSessionListener(SessionListener listener)
Description copied from interface:SessionHandler
Adds an event listener for session-related events.- Specified by:
addSessionListener
in interfaceSessionHandler
- Parameters:
listener
- the session listener- See Also:
SessionHandler.removeSessionListener(SessionListener)
-
removeSessionListener
public void removeSessionListener(SessionListener listener)
Description copied from interface:SessionHandler
Removes an event listener for for session-related events.- Specified by:
removeSessionListener
in interfaceSessionHandler
- Parameters:
listener
- the session listener to remove- See Also:
SessionHandler.addSessionListener(SessionListener)
-
clearSessionListeners
public void clearSessionListeners()
Description copied from interface:SessionHandler
Removes all event listeners for session-related events.- Specified by:
clearSessionListeners
in 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:SessionHandler
Call binding and attribute listeners based on the new and old values of the attribute.- Specified by:
fireSessionAttributeListeners
in interfaceSessionHandler
name
- name of the attributeoldValue
- previous value of the attributenewValue
- new value of the attribute
-
fireSessionDestroyedListeners
public void fireSessionDestroyedListeners(Session session)
Description copied from interface:SessionHandler
Call the session lifecycle listeners.- Specified by:
fireSessionDestroyedListeners
in interfaceSessionHandler
- Parameters:
session
- the session on which to call the lifecycle listeners
-
recordSessionTime
public void recordSessionTime(BasicSession session)
Description copied from interface:SessionHandler
Record length of time session has been active. Called when the session is about to be invalidated.- Specified by:
recordSessionTime
in interfaceSessionHandler
- Parameters:
session
- the session whose time to record
-
getSessionTimeMax
public long getSessionTimeMax()
- Specified by:
getSessionTimeMax
in interfaceSessionHandler
- Returns:
- the maximum amount of time session remained valid
-
getSessionTimeTotal
public long getSessionTimeTotal()
- Specified by:
getSessionTimeTotal
in interfaceSessionHandler
- Returns:
- the total amount of time all sessions remained valid
-
getSessionTimeMean
public long getSessionTimeMean()
- Specified by:
getSessionTimeMean
in interfaceSessionHandler
- Returns:
- the mean amount of time session remained valid
-
getSessionTimeStdDev
public double getSessionTimeStdDev()
- Specified by:
getSessionTimeStdDev
in interfaceSessionHandler
- Returns:
- the standard deviation of amount of time session remained valid
-
statsReset
public void statsReset()
Description copied from interface:SessionHandler
Resets the session usage statistics.- Specified by:
statsReset
in interfaceSessionHandler
-
doInitialize
protected void doInitialize() throws java.lang.Exception
- Specified by:
doInitialize
in classAbstractComponent
- Throws:
java.lang.Exception
-
doDestroy
protected void doDestroy() throws java.lang.Exception
- Specified by:
doDestroy
in classAbstractComponent
- Throws:
java.lang.Exception
-
getComponentName
public java.lang.String getComponentName()
Description copied from interface:Component
Returns the component name.- Specified by:
getComponentName
in interfaceComponent
- Overrides:
getComponentName
in classAbstractComponent
- Returns:
- the component name
-
-