Module org.eclipse.jetty.server
Package org.eclipse.jetty.server.session
Class AbstractSessionDataStore
- java.lang.Object
-
- org.eclipse.jetty.util.component.AbstractLifeCycle
-
- org.eclipse.jetty.util.component.ContainerLifeCycle
-
- org.eclipse.jetty.server.session.AbstractSessionDataStore
-
- All Implemented Interfaces:
SessionDataMap,SessionDataStore,org.eclipse.jetty.util.component.Container,org.eclipse.jetty.util.component.Destroyable,org.eclipse.jetty.util.component.Dumpable,org.eclipse.jetty.util.component.Dumpable.DumpableContainer,org.eclipse.jetty.util.component.LifeCycle
- Direct Known Subclasses:
FileSessionDataStore,JDBCSessionDataStore,NullSessionDataStore
@ManagedObject public abstract class AbstractSessionDataStore extends org.eclipse.jetty.util.component.ContainerLifeCycle implements SessionDataStore
AbstractSessionDataStore
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class org.eclipse.jetty.util.component.AbstractLifeCycle
org.eclipse.jetty.util.component.AbstractLifeCycle.AbstractLifeCycleListener, org.eclipse.jetty.util.component.AbstractLifeCycle.StopException
-
Nested classes/interfaces inherited from interface org.eclipse.jetty.util.component.Container
org.eclipse.jetty.util.component.Container.InheritedListener, org.eclipse.jetty.util.component.Container.Listener
-
-
Field Summary
Fields Modifier and Type Field Description protected SessionContext_contextprotected int_gracePeriodSecprotected long_lastExpiryCheckTimeprotected long_lastOrphanSweepTimeprotected int_savePeriodSecstatic intDEFAULT_GRACE_PERIOD_SECstatic intDEFAULT_SAVE_PERIOD_SEC
-
Constructor Summary
Constructors Constructor Description AbstractSessionDataStore()
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected voidcheckStarted()voidcleanOrphans(long timeLimit)Remove all sessions for any context that expired at or before the given time.abstract java.util.Set<java.lang.String>doCheckExpired(java.util.Set<java.lang.String> candidates, long time)Implemented by subclasses to resolve which sessions in this context that are being managed by this node that should be expired.abstract voiddoCleanOrphans(long time)Implemented by subclasses to delete sessions for other contexts that expired at or before the timeLimit.abstract booleandoExists(java.lang.String id)Check if a session for the given id exists.abstract java.util.Set<java.lang.String>doGetExpired(long before)Implemented by subclasses to find sessions for this context in the store that expired at or before the time limit and thus not being actively managed by any node.abstract SessionDatadoLoad(java.lang.String id)Load the session from persistent store.protected voiddoStart()abstract voiddoStore(java.lang.String id, SessionData data, long lastSaveTime)Store the session data persistently.booleanexists(java.lang.String id)Test if data exists for a given session id.java.util.Set<java.lang.String>getExpired(java.util.Set<java.lang.String> candidates)Called periodically, this method should search the data store for sessions that have been expired for a 'reasonable' amount of time.intgetGracePeriodSec()intgetSavePeriodSec()voidinitialize(SessionContext context)Initialize this data map for the given context.SessionDataload(java.lang.String id)Read in session data.SessionDatanewSessionData(java.lang.String id, long created, long accessed, long lastAccessed, long maxInactiveMs)Create a new SessionDatavoidsetGracePeriodSec(int sec)voidsetSavePeriodSec(int savePeriodSec)The minimum time in seconds between save operations.voidstore(java.lang.String id, SessionData data)Store the session data.java.lang.StringtoString()-
Methods inherited from class org.eclipse.jetty.util.component.ContainerLifeCycle
addBean, addBean, addEventListener, addManaged, contains, destroy, doStop, dump, dump, dump, dumpObjects, dumpStdErr, getBean, getBeans, getBeans, getContainedBeans, getContainedBeans, isAuto, isManaged, isUnmanaged, manage, removeBean, removeBeans, removeEventListener, setBeans, start, stop, unmanage, updateBean, updateBean, updateBeans, updateBeans
-
Methods inherited from class org.eclipse.jetty.util.component.AbstractLifeCycle
getEventListeners, getState, getState, isFailed, isRunning, isStarted, isStarting, isStopped, isStopping, setEventListeners, start, stop
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface org.eclipse.jetty.util.component.Container
getCachedBeans, getEventListeners
-
Methods inherited from interface org.eclipse.jetty.util.component.Dumpable.DumpableContainer
isDumpable
-
Methods inherited from interface org.eclipse.jetty.util.component.LifeCycle
addEventListener, isFailed, isRunning, isStarted, isStarting, isStopped, isStopping, removeEventListener, start, stop
-
Methods inherited from interface org.eclipse.jetty.server.session.SessionDataMap
delete
-
Methods inherited from interface org.eclipse.jetty.server.session.SessionDataStore
isPassivating
-
-
-
-
Field Detail
-
DEFAULT_GRACE_PERIOD_SEC
public static final int DEFAULT_GRACE_PERIOD_SEC
- See Also:
- Constant Field Values
-
DEFAULT_SAVE_PERIOD_SEC
public static final int DEFAULT_SAVE_PERIOD_SEC
- See Also:
- Constant Field Values
-
_context
protected SessionContext _context
-
_gracePeriodSec
protected int _gracePeriodSec
-
_lastExpiryCheckTime
protected long _lastExpiryCheckTime
-
_lastOrphanSweepTime
protected long _lastOrphanSweepTime
-
_savePeriodSec
protected int _savePeriodSec
-
-
Method Detail
-
doExists
public abstract boolean doExists(java.lang.String id) throws java.lang.ExceptionCheck if a session for the given id exists.- Parameters:
id- the session id to check- Returns:
- true if the session exists in the persistent store, false otherwise
- Throws:
java.lang.Exception
-
doStore
public abstract void doStore(java.lang.String id, SessionData data, long lastSaveTime) throws java.lang.ExceptionStore the session data persistently.- Parameters:
id- identity of session to storedata- info of the sessionlastSaveTime- time of previous save or 0 if never saved- Throws:
java.lang.Exception- if unable to store data
-
doLoad
public abstract SessionData doLoad(java.lang.String id) throws java.lang.Exception
Load the session from persistent store.- Parameters:
id- the id of the session to load- Returns:
- the re-inflated session
- Throws:
java.lang.Exception- if unable to load the session
-
doCheckExpired
public abstract java.util.Set<java.lang.String> doCheckExpired(java.util.Set<java.lang.String> candidates, long time)Implemented by subclasses to resolve which sessions in this context that are being managed by this node that should be expired.- Parameters:
candidates- the ids of sessions the SessionCache thinks has expiredtime- the time at which to check for expiry- Returns:
- the reconciled set of session ids that have been checked in the store
-
doGetExpired
public abstract java.util.Set<java.lang.String> doGetExpired(long before)
Implemented by subclasses to find sessions for this context in the store that expired at or before the time limit and thus not being actively managed by any node. This method is only called periodically (the period is configurable) to avoid putting too much load on the store.- Parameters:
before- the upper limit of expiry times to check. Sessions expired at or before this timestamp will match.- Returns:
- the empty set if there are no sessions expired as at the time, or otherwise a set of session ids.
-
doCleanOrphans
public abstract void doCleanOrphans(long time)
Implemented by subclasses to delete sessions for other contexts that expired at or before the timeLimit. These are 'orphaned' sessions that are no longer being actively managed by any node. These are explicitly sessions that do NOT belong to this context (other mechanisms such as doGetExpired take care of those). As they don't belong to this context, they cannot be loaded by us. This is called only periodically to avoid placing excessive load on the store.- Parameters:
time- the upper limit of the expiry time to check in msec
-
initialize
public void initialize(SessionContext context) throws java.lang.Exception
Description copied from interface:SessionDataMapInitialize this data map for the given context. A SessionDataMap can only be used by one context(/session manager).- Specified by:
initializein interfaceSessionDataMap- Parameters:
context- context associated- Throws:
java.lang.Exception- if unable to initialize the
-
cleanOrphans
public void cleanOrphans(long timeLimit)
Remove all sessions for any context that expired at or before the given time.- Parameters:
timeLimit- the time before which the sessions must have expired.
-
load
public SessionData load(java.lang.String id) throws java.lang.Exception
Description copied from interface:SessionDataMapRead in session data.- Specified by:
loadin interfaceSessionDataMap- Parameters:
id- identity of session to load- Returns:
- the SessionData matching the id
- Throws:
java.lang.Exception- if unable to load session data
-
store
public void store(java.lang.String id, SessionData data) throws java.lang.ExceptionDescription copied from interface:SessionDataMapStore the session data.- Specified by:
storein interfaceSessionDataMap- Parameters:
id- identity of session to storedata- info of session to store- Throws:
java.lang.Exception- if unable to write session data
-
exists
public boolean exists(java.lang.String id) throws java.lang.ExceptionDescription copied from interface:SessionDataStoreTest if data exists for a given session id.- Specified by:
existsin interfaceSessionDataStore- Parameters:
id- Identity of session whose existence should be checked- Returns:
- true if valid, non-expired session exists
- Throws:
java.lang.Exception- if problem checking existence with persistence layer
-
getExpired
public java.util.Set<java.lang.String> getExpired(java.util.Set<java.lang.String> candidates)
Description copied from interface:SessionDataStoreCalled periodically, this method should search the data store for sessions that have been expired for a 'reasonable' amount of time.- Specified by:
getExpiredin interfaceSessionDataStore- Parameters:
candidates- if provided, these are keys of sessions that the SessionDataStore thinks has expired and should be verified by the SessionDataStore- Returns:
- set of session ids
-
newSessionData
public SessionData newSessionData(java.lang.String id, long created, long accessed, long lastAccessed, long maxInactiveMs)
Description copied from interface:SessionDataStoreCreate a new SessionData- Specified by:
newSessionDatain interfaceSessionDataStore- Parameters:
id- the idcreated- the timestamp when createdaccessed- the timestamp when accessedlastAccessed- the timestamp when last accessedmaxInactiveMs- the max inactive time in milliseconds- Returns:
- a new SessionData object
-
checkStarted
protected void checkStarted() throws java.lang.IllegalStateException- Throws:
java.lang.IllegalStateException
-
doStart
protected void doStart() throws java.lang.Exception- Overrides:
doStartin classorg.eclipse.jetty.util.component.ContainerLifeCycle- Throws:
java.lang.Exception
-
getGracePeriodSec
@ManagedAttribute(value="interval in secs to prevent too eager session scavenging", readonly=true) public int getGracePeriodSec()
-
setGracePeriodSec
public void setGracePeriodSec(int sec)
-
getSavePeriodSec
@ManagedAttribute(value="min secs between saves", readonly=true) public int getSavePeriodSec()- Returns:
- the savePeriodSec
-
setSavePeriodSec
public void setSavePeriodSec(int savePeriodSec)
The minimum time in seconds between save operations. Saves normally occur every time the last request exits as session. If nothing changes on the session except for the access time and the persistence technology is slow, this can cause delays.By default the value is 0, which means we save after the last request exists. A non zero value means that we will skip doing the save if the session isn't dirty if the elapsed time since the session was last saved does not exceed this value.
- Parameters:
savePeriodSec- the savePeriodSec to set
-
toString
public java.lang.String toString()
- Overrides:
toStringin classorg.eclipse.jetty.util.component.AbstractLifeCycle
-
-