SessionCache
, Container
, Destroyable
, Dumpable
, LifeCycle
DefaultSessionCache
, NullSessionCache
@ManagedObject public abstract class AbstractSessionCache extends ContainerLifeCycle implements SessionCache
SessionCache
interface for managing a set of
Session objects pertaining to a context in memory.
This implementation ensures that multiple requests for the same session id
always return the same Session object.
It will delay writing out a session to the SessionDataStore until the
last request exits the session. If the SessionDataStore supports passivation
then the session passivation and activation listeners are called appropriately as
the session is written.
This implementation also supports evicting idle Session objects. An idle Session
is one that is still valid, has not expired, but has not been accessed by a
request for a configurable amount of time. An idle session will be first
passivated before it is evicted from the cache.Modifier and Type | Class | Description |
---|---|---|
protected class |
AbstractSessionCache.PlaceHolderSession |
PlaceHolder
|
AbstractLifeCycle.AbstractLifeCycleListener
Container.InheritedListener, Container.Listener
LifeCycle.Listener
Modifier and Type | Field | Description |
---|---|---|
protected SessionContext |
_context |
Information about the context to which this SessionCache pertains
|
protected int |
_evictionPolicy |
When, if ever, to evict sessions: never; only when the last request for them finishes; after inactivity time (expressed as secs)
|
protected SessionHandler |
_handler |
The SessionHandler related to this SessionCache
|
protected boolean |
_removeUnloadableSessions |
If true, a Session whose data cannot be read will be
deleted from the SessionDataStore.
|
protected boolean |
_saveOnCreate |
If true, as soon as a new session is created, it will be persisted to the SessionDataStore
|
protected boolean |
_saveOnInactiveEviction |
If true, a session that will be evicted from the cache because it has been
inactive too long will be saved before being evicted.
|
protected SessionDataStore |
_sessionDataStore |
The authoritative source of session data
|
FAILED, RUNNING, STARTED, STARTING, STOP_ON_FAILURE, STOPPED, STOPPING
EVICT_ON_INACTIVITY, EVICT_ON_SESSION_EXIT, NEVER_EVICT
Constructor | Description |
---|---|
AbstractSessionCache(SessionHandler handler) |
Modifier and Type | Method | Description |
---|---|---|
java.util.Set<java.lang.String> |
checkExpiration(java.util.Set<java.lang.String> candidates) |
Check a list of session ids that belong to potentially expired
sessions.
|
void |
checkInactiveSession(Session session) |
Check a session for being inactive and
thus being able to be evicted, if eviction
is enabled.
|
boolean |
contains(java.lang.String id) |
Check to see if this cache contains an entry for the session
corresponding to the session id.
|
Session |
delete(java.lang.String id) |
Remove a session object from this store and from any backing store.
|
abstract Session |
doDelete(java.lang.String id) |
Remove the session with this identity from the store
|
abstract Session |
doGet(java.lang.String id) |
Get the session matching the key
|
abstract Session |
doPutIfAbsent(java.lang.String id,
Session session) |
Put the session into the map if it wasn't already there
|
abstract boolean |
doReplace(java.lang.String id,
Session oldValue,
Session newValue) |
Replace the mapping from id to oldValue with newValue
|
protected void |
doStart() |
Starts the managed lifecycle beans in the order they were added.
|
protected void |
doStop() |
Stops the managed lifecycle beans in the reverse order they were added.
|
boolean |
exists(java.lang.String id) |
Check to see if a session corresponding to the id exists.
|
Session |
get(java.lang.String id) |
Get a session object.
|
int |
getEvictionPolicy() |
|
SessionDataStore |
getSessionDataStore() |
|
SessionHandler |
getSessionHandler() |
|
void |
initialize(SessionContext context) |
|
boolean |
isRemoveUnloadableSessions() |
|
boolean |
isSaveOnCreate() |
|
boolean |
isSaveOnInactiveEviction() |
Whether we should save a session that has been inactive before
we boot it from the cache.
|
Session |
newSession(HttpServletRequest request,
java.lang.String id,
long time,
long maxInactiveMs) |
Create an entirely new Session.
|
abstract Session |
newSession(HttpServletRequest request,
SessionData data) |
Create a new Session for a request.
|
abstract Session |
newSession(SessionData data) |
Create a new Session object from pre-existing session data
|
void |
put(java.lang.String id,
Session session) |
Put the Session object back into the session store.
|
Session |
renewSessionId(java.lang.String oldId,
java.lang.String newId) |
Change the id of a Session.
|
void |
setEvictionPolicy(int evictionTimeout) |
-1 means we never evict inactive sessions.
|
void |
setRemoveUnloadableSessions(boolean removeUnloadableSessions) |
If a session's data cannot be loaded from the store without error, remove
it from the persistent store.
|
void |
setSaveOnCreate(boolean saveOnCreate) |
Whether or not a session that is newly created should be
immediately saved.
|
void |
setSaveOnInactiveEviction(boolean saveOnEvict) |
Whether or not a a session that is about to be evicted should
be saved before being evicted.
|
void |
setSessionDataStore(SessionDataStore sessionStore) |
A SessionDataStore that is the authoritative source
of session information.
|
java.lang.String |
toString() |
addLifeCycleListener, getState, getState, getStopTimeout, isFailed, isRunning, isStarted, isStarting, isStopped, isStopping, removeLifeCycleListener, start, stop
addBean, addBean, addBean, addEventListener, addManaged, contains, destroy, dump, dump, dump, dump, dump, dumpBeans, dumpObject, dumpStdErr, dumpThis, getBean, getBeans, getBeans, getContainedBeans, getContainedBeans, isManaged, manage, removeBean, removeBeans, removeEventListener, setBeans, setStopTimeout, start, stop, unmanage, updateBean, updateBean, updateBeans
addLifeCycleListener, isFailed, isRunning, isStarted, isStarting, isStopped, isStopping, removeLifeCycleListener, start, start, stop, stop
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
shutdown
protected SessionDataStore _sessionDataStore
protected final SessionHandler _handler
protected SessionContext _context
protected int _evictionPolicy
protected boolean _saveOnCreate
protected boolean _saveOnInactiveEviction
protected boolean _removeUnloadableSessions
public AbstractSessionCache(SessionHandler handler)
handler
- the SessionHandler
to usepublic abstract Session newSession(SessionData data)
newSession
in interface SessionCache
data
- the session datapublic abstract Session newSession(HttpServletRequest request, SessionData data)
request
- the requestdata
- the session datapublic abstract Session doGet(java.lang.String id)
id
- session idpublic abstract Session doPutIfAbsent(java.lang.String id, Session session)
id
- the identity of the sessionsession
- the session objectpublic abstract boolean doReplace(java.lang.String id, Session oldValue, Session newValue)
id
- the idoldValue
- the old valuenewValue
- the new valuepublic abstract Session doDelete(java.lang.String id)
id
- the idpublic SessionHandler getSessionHandler()
getSessionHandler
in interface SessionCache
public void initialize(SessionContext context)
initialize
in interface SessionCache
context
- the SessionContext
to use for this cacheSessionCache.initialize(org.eclipse.jetty.server.session.SessionContext)
protected void doStart() throws java.lang.Exception
ContainerLifeCycle
doStart
in class ContainerLifeCycle
java.lang.Exception
AbstractLifeCycle.doStart()
protected void doStop() throws java.lang.Exception
ContainerLifeCycle
doStop
in class ContainerLifeCycle
java.lang.Exception
AbstractLifeCycle.doStop()
public SessionDataStore getSessionDataStore()
getSessionDataStore
in interface SessionCache
public void setSessionDataStore(SessionDataStore sessionStore)
SessionCache
setSessionDataStore
in interface SessionCache
sessionStore
- the SessionDataStore
to useSessionCache.setSessionDataStore(org.eclipse.jetty.server.session.SessionDataStore)
@ManagedAttribute(value="session eviction policy", readonly=true) public int getEvictionPolicy()
getEvictionPolicy
in interface SessionCache
SessionCache.getEvictionPolicy()
public void setEvictionPolicy(int evictionTimeout)
setEvictionPolicy
in interface SessionCache
evictionTimeout
- -1 is never evict; 0 is evict-on-exit; and any other positive
value is the time in seconds that a session can be idle before it can
be evicted.SessionCache.setEvictionPolicy(int)
@ManagedAttribute(value="immediately save new sessions", readonly=true) public boolean isSaveOnCreate()
isSaveOnCreate
in interface SessionCache
true
the newly created session will be saved immediatelypublic void setSaveOnCreate(boolean saveOnCreate)
SessionCache
setSaveOnCreate
in interface SessionCache
saveOnCreate
- true
to immediately save the newly created session@ManagedAttribute(value="delete unreadable stored sessions", readonly=true) public boolean isRemoveUnloadableSessions()
isRemoveUnloadableSessions
in interface SessionCache
public void setRemoveUnloadableSessions(boolean removeUnloadableSessions)
setRemoveUnloadableSessions
in interface SessionCache
removeUnloadableSessions
- if true
unloadable sessions will be removed from session storepublic Session get(java.lang.String id) throws java.lang.Exception
get
in interface SessionCache
id
- the session idjava.lang.Exception
- if any error occurredSessionCache.get(java.lang.String)
public void put(java.lang.String id, Session session) throws java.lang.Exception
put
in interface SessionCache
id
- the session idsession
- the current session objectjava.lang.Exception
- if any error occurredSessionCache.put(java.lang.String, org.eclipse.jetty.server.session.Session)
public boolean exists(java.lang.String id) throws java.lang.Exception
exists
in interface SessionCache
id
- the session idjava.lang.Exception
- the ExceptionSessionCache.exists(java.lang.String)
public boolean contains(java.lang.String id) throws java.lang.Exception
contains
in interface SessionCache
id
- the session idjava.lang.Exception
- if any error occurredSessionCache.contains(java.lang.String)
public Session delete(java.lang.String id) throws java.lang.Exception
delete
in interface SessionCache
id
- the session idjava.lang.Exception
- if any error occurredSessionCache.delete(java.lang.String)
public java.util.Set<java.lang.String> checkExpiration(java.util.Set<java.lang.String> candidates)
SessionCache
checkExpiration
in interface SessionCache
candidates
- the session ids to checkSessionCache.checkExpiration(Set)
public void checkInactiveSession(Session session)
checkInactiveSession
in interface SessionCache
session
- session to checkpublic Session renewSessionId(java.lang.String oldId, java.lang.String newId) throws java.lang.Exception
SessionCache
renewSessionId
in interface SessionCache
oldId
- the current session idnewId
- the new session idjava.lang.Exception
- if any error occurredSessionCache.renewSessionId(java.lang.String, java.lang.String)
public void setSaveOnInactiveEviction(boolean saveOnEvict)
SessionCache
setSaveOnInactiveEviction
in interface SessionCache
saveOnEvict
- true
if the session should be saved before being evictedSessionCache.setSaveOnInactiveEviction(boolean)
@ManagedAttribute(value="save sessions before evicting from cache", readonly=true) public boolean isSaveOnInactiveEviction()
isSaveOnInactiveEviction
in interface SessionCache
public Session newSession(HttpServletRequest request, java.lang.String id, long time, long maxInactiveMs)
SessionCache
newSession
in interface SessionCache
request
- the requestid
- the unique id associated to the sessiontime
- the timestamp of the session creationmaxInactiveMs
- the max inactive time in millisecondsSessionCache.newSession(javax.servlet.http.HttpServletRequest, java.lang.String, long, long)
public java.lang.String toString()
toString
in class java.lang.Object
Copyright © 1995–2018 Webtide. All rights reserved.