Package org.eclipse.jetty.server.session
Class DefaultSessionCache
- java.lang.Object
-
- org.eclipse.jetty.util.component.AbstractLifeCycle
-
- org.eclipse.jetty.util.component.ContainerLifeCycle
-
- org.eclipse.jetty.server.session.AbstractSessionCache
-
- org.eclipse.jetty.server.session.DefaultSessionCache
-
- All Implemented Interfaces:
SessionCache
,Container
,Destroyable
,Dumpable
,Dumpable.DumpableContainer
,LifeCycle
@ManagedObject public class DefaultSessionCache extends AbstractSessionCache
DefaultSessionCache A session store that keeps its sessions in memory in a hashmap
-
-
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 java.util.concurrent.ConcurrentHashMap<java.lang.String,Session>
_sessions
The cache of sessions in a hashmap-
Fields inherited from class org.eclipse.jetty.server.session.AbstractSessionCache
_context, _evictionPolicy, _flushOnResponseCommit, _handler, _invalidateOnShutdown, _removeUnloadableSessions, _saveOnCreate, _saveOnInactiveEviction, _sessionDataStore
-
Fields inherited from class org.eclipse.jetty.util.component.AbstractLifeCycle
FAILED, RUNNING, STARTED, STARTING, STOPPED, STOPPING
-
Fields inherited from interface org.eclipse.jetty.server.session.SessionCache
EVICT_ON_INACTIVITY, EVICT_ON_SESSION_EXIT, NEVER_EVICT
-
-
Constructor Summary
Constructors Constructor Description DefaultSessionCache(SessionHandler manager)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected Session
doComputeIfAbsent(java.lang.String id, java.util.function.Function<java.lang.String,Session> mappingFunction)
Compute the mappingFunction to create a Session object iff the session with the given id isn't already in the map, otherwise return the existing Session.Session
doDelete(java.lang.String id)
Remove the session with this identity from the storeSession
doGet(java.lang.String id)
Get the session matching the key from the cache.Session
doPutIfAbsent(java.lang.String id, Session session)
Put the session into the map if it wasn't already thereboolean
doReplace(java.lang.String id, Session oldValue, Session newValue)
Replace the mapping from id to oldValue with newValuelong
getSessionsCurrent()
long
getSessionsMax()
long
getSessionsTotal()
Session
newSession(javax.servlet.http.HttpServletRequest request, SessionData data)
Create a new Session for a request.Session
newSession(SessionData data)
Create a new Session object from pre-existing session datavoid
resetStats()
void
shutdown()
-
Methods inherited from class org.eclipse.jetty.server.session.AbstractSessionCache
add, checkExpiration, checkInactiveSession, commit, contains, delete, doStart, doStop, exists, get, getAndEnter, getEvictionPolicy, getSessionDataStore, getSessionHandler, initialize, isFlushOnResponseCommit, isInvalidateOnShutdown, isRemoveUnloadableSessions, isSaveOnCreate, isSaveOnInactiveEviction, newSession, put, release, renewSessionId, renewSessionId, setEvictionPolicy, setFlushOnResponseCommit, setInvalidateOnShutdown, setRemoveUnloadableSessions, setSaveOnCreate, setSaveOnInactiveEviction, setSessionDataStore, toString
-
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
-
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
-
Methods inherited from interface org.eclipse.jetty.server.session.SessionCache
renewSessionId
-
-
-
-
Field Detail
-
_sessions
protected java.util.concurrent.ConcurrentHashMap<java.lang.String,Session> _sessions
The cache of sessions in a hashmap
-
-
Constructor Detail
-
DefaultSessionCache
public DefaultSessionCache(SessionHandler manager)
- Parameters:
manager
- The SessionHandler related to this SessionCache
-
-
Method Detail
-
getSessionsCurrent
@ManagedAttribute(value="current sessions in cache", readonly=true) public long getSessionsCurrent()
- Returns:
- the number of sessions in the cache
-
getSessionsMax
@ManagedAttribute(value="max sessions in cache", readonly=true) public long getSessionsMax()
- Returns:
- the max number of sessions in the cache
-
getSessionsTotal
@ManagedAttribute(value="total sessions in cache", readonly=true) public long getSessionsTotal()
- Returns:
- a running total of sessions in the cache
-
resetStats
@ManagedOperation(value="reset statistics", impact="ACTION") public void resetStats()
-
doGet
public Session doGet(java.lang.String id)
Description copied from class:AbstractSessionCache
Get the session matching the key from the cache. Does not load the session.- Specified by:
doGet
in classAbstractSessionCache
- Parameters:
id
- session id- Returns:
- the Session object matching the id
-
doPutIfAbsent
public Session doPutIfAbsent(java.lang.String id, Session session)
Description copied from class:AbstractSessionCache
Put the session into the map if it wasn't already there- Specified by:
doPutIfAbsent
in classAbstractSessionCache
- 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
-
doComputeIfAbsent
protected Session doComputeIfAbsent(java.lang.String id, java.util.function.Function<java.lang.String,Session> mappingFunction)
Description copied from class:AbstractSessionCache
Compute the mappingFunction to create a Session object iff the session with the given id isn't already in the map, otherwise return the existing Session. This method is expected to have precisely the same behaviour asConcurrentHashMap.computeIfAbsent(K, java.util.function.Function<? super K, ? extends V>)
- Specified by:
doComputeIfAbsent
in classAbstractSessionCache
- Parameters:
id
- the session idmappingFunction
- the function to load the data for the session- Returns:
- an existing Session from the cache
-
doDelete
public Session doDelete(java.lang.String id)
Description copied from class:AbstractSessionCache
Remove the session with this identity from the store- Specified by:
doDelete
in classAbstractSessionCache
- Parameters:
id
- the id- Returns:
- Session that was removed or null
-
shutdown
public void shutdown()
-
newSession
public Session newSession(javax.servlet.http.HttpServletRequest request, SessionData data)
Description copied from class:AbstractSessionCache
Create a new Session for a request.- Specified by:
newSession
in classAbstractSessionCache
- Parameters:
request
- the requestdata
- the session data- Returns:
- the new session
-
newSession
public Session newSession(SessionData data)
Description copied from class:AbstractSessionCache
Create a new Session object from pre-existing session data- Specified by:
newSession
in interfaceSessionCache
- Specified by:
newSession
in classAbstractSessionCache
- Parameters:
data
- the session data- Returns:
- a new Session object
-
doReplace
public boolean doReplace(java.lang.String id, Session oldValue, Session newValue)
Description copied from class:AbstractSessionCache
Replace the mapping from id to oldValue with newValue- Specified by:
doReplace
in classAbstractSessionCache
- Parameters:
id
- the idoldValue
- the old valuenewValue
- the new value- Returns:
- true if replacement was done
-
-