Package org.eclipse.jetty.server.session
Class CachingSessionDataStore
- java.lang.Object
-
- org.eclipse.jetty.util.component.AbstractLifeCycle
-
- org.eclipse.jetty.util.component.ContainerLifeCycle
-
- org.eclipse.jetty.server.session.CachingSessionDataStore
-
- All Implemented Interfaces:
SessionDataMap,SessionDataStore,Container,Destroyable,Dumpable,Dumpable.DumpableContainer,LifeCycle
public class CachingSessionDataStore extends ContainerLifeCycle implements SessionDataStore
CachingSessionDataStore A SessionDataStore is a mechanism for (persistently) storing data associated with sessions. This implementation delegates to a pluggable SessionDataStore for actually storing the session data. It also uses a pluggable cache implementation in front of the delegate SessionDataStore to improve performance: accessing most persistent store technology can be expensive time-wise, so introducing a fronting cache can increase performance. The cache implementation can either be a local cache, a remote cache, or a clustered cache. The implementation here will try to read first from the cache and fallback to reading from the SessionDataStore if the session key is not found. On writes, the session data is written first to the SessionDataStore, and then to the cache. On deletes, the data is deleted first from the SessionDataStore, and then from the cache. There is no transaction manager ensuring atomic operations, so it is possible that failures can result in cache inconsistency.
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class org.eclipse.jetty.util.component.AbstractLifeCycle
AbstractLifeCycle.AbstractLifeCycleListener
-
Nested classes/interfaces inherited from interface org.eclipse.jetty.util.component.Container
Container.InheritedListener, Container.Listener
-
Nested classes/interfaces inherited from interface org.eclipse.jetty.util.component.Dumpable
Dumpable.DumpableContainer
-
Nested classes/interfaces inherited from interface org.eclipse.jetty.util.component.LifeCycle
LifeCycle.Listener
-
-
Field Summary
Fields Modifier and Type Field Description protected SessionDataMap_cacheThe fronting cacheprotected SessionDataStore_storeThe actual store for the session data
-
Constructor Summary
Constructors Constructor Description CachingSessionDataStore(SessionDataMap cache, SessionDataStore store)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description booleandelete(java.lang.String id)Delete session dataprotected voiddoStart()Starts the managed lifecycle beans in the order they were added.protected voiddoStop()Stops the managed lifecycle beans in the reverse order they were added.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.SessionDataMapgetSessionDataMap()SessionDataStoregetSessionStore()voidinitialize(SessionContext context)Initialize this data map for the given context.booleanisPassivating()True if this type of datastore will passivate session objectsSessionDataload(java.lang.String id)Read in session data.SessionDatanewSessionData(java.lang.String id, long created, long accessed, long lastAccessed, long maxInactiveMs)Create a new SessionDatavoidstore(java.lang.String id, SessionData data)Store the session data.-
Methods inherited from class org.eclipse.jetty.util.component.ContainerLifeCycle
addBean, addBean, addEventListener, addManaged, contains, destroy, dump, dump, dump, dump, dump, dumpBeans, dumpObject, dumpObjects, dumpStdErr, dumpThis, getBean, getBeans, getBeans, getContainedBeans, getContainedBeans, isAuto, isManaged, isUnmanaged, manage, removeBean, removeBeans, removeEventListener, setBeans, setStopTimeout, start, stop, unmanage, updateBean, updateBean, updateBeans
-
Methods inherited from class org.eclipse.jetty.util.component.AbstractLifeCycle
addLifeCycleListener, getState, getState, getStopTimeout, isFailed, isRunning, isStarted, isStarting, isStopped, isStopping, removeLifeCycleListener, start, stop, toString
-
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.Dumpable.DumpableContainer
isDumpable
-
Methods inherited from interface org.eclipse.jetty.util.component.LifeCycle
addLifeCycleListener, isFailed, isRunning, isStarted, isStarting, isStopped, isStopping, removeLifeCycleListener, start, stop
-
-
-
-
Field Detail
-
_store
protected SessionDataStore _store
The actual store for the session data
-
_cache
protected SessionDataMap _cache
The fronting cache
-
-
Constructor Detail
-
CachingSessionDataStore
public CachingSessionDataStore(SessionDataMap cache, SessionDataStore store)
- Parameters:
cache- the front cache to usestore- the actual store for the the session data
-
-
Method Detail
-
getSessionStore
public SessionDataStore getSessionStore()
- Returns:
- the delegate session store
-
getSessionDataMap
public SessionDataMap getSessionDataMap()
- Returns:
- the fronting cache for session data
-
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- See Also:
SessionDataMap.load(java.lang.String)
-
delete
public boolean delete(java.lang.String id) throws java.lang.ExceptionDescription copied from interface:SessionDataMapDelete session data- Specified by:
deletein interfaceSessionDataMap- Parameters:
id- identity of session to delete- Returns:
- true if the session was deleted
- Throws:
java.lang.Exception- if unable to delete session data- See Also:
SessionDataMap.delete(java.lang.String)
-
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
- See Also:
SessionDataStore.getExpired(Set)
-
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- See Also:
SessionDataMap.store(java.lang.String, org.eclipse.jetty.server.session.SessionData)
-
doStart
protected void doStart() throws java.lang.ExceptionDescription copied from class:ContainerLifeCycleStarts the managed lifecycle beans in the order they were added.- Overrides:
doStartin classContainerLifeCycle- Throws:
java.lang.Exception
-
doStop
protected void doStop() throws java.lang.ExceptionDescription copied from class:ContainerLifeCycleStops the managed lifecycle beans in the reverse order they were added.- Overrides:
doStopin classContainerLifeCycle- Throws:
java.lang.Exception
-
isPassivating
public boolean isPassivating()
Description copied from interface:SessionDataStoreTrue if this type of datastore will passivate session objects- Specified by:
isPassivatingin interfaceSessionDataStore- Returns:
- true if this store can passivate sessions, false otherwise
- See Also:
SessionDataStore.isPassivating()
-
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- See Also:
SessionDataStore.exists(java.lang.String)
-
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- See Also:
SessionDataMap.initialize(org.eclipse.jetty.server.session.SessionContext)
-
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
- See Also:
SessionDataStore.newSessionData(java.lang.String, long, long, long, long)
-
-