java.lang.Object
org.eclipse.jetty.session.ManagedSession
- All Implemented Interfaces:
org.eclipse.jetty.server.Session,org.eclipse.jetty.util.Attributes
A heavy-weight Session object representing an HttpSession. Session objects
relating to a context are kept in a
SessionCache. The purpose of the
SessionCache is to keep the working set of Session objects in memory so that
they may be accessed quickly, and facilitate the sharing of a Session object
amongst multiple simultaneous requests referring to the same session id.
The SessionManager coordinates the lifecycle of Session objects with
the help of the SessionCache/SessionDataStore.
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enumState of the session idstatic enumValidity states of a sessionNested classes/interfaces inherited from interface org.eclipse.jetty.util.Attributes
org.eclipse.jetty.util.Attributes.Layer, org.eclipse.jetty.util.Attributes.Lazy, org.eclipse.jetty.util.Attributes.Mapped, org.eclipse.jetty.util.Attributes.Synthetic, org.eclipse.jetty.util.Attributes.WrapperNested classes/interfaces inherited from interface org.eclipse.jetty.server.Session
org.eclipse.jetty.server.Session.API, org.eclipse.jetty.server.Session.LifeCycleListener, org.eclipse.jetty.server.Session.ValueListener -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected Stringprotected org.eclipse.jetty.util.thread.AutoLockprotected final SessionManagerprotected booleanprotected booleanprotected longprotected booleanprotected final SessionDataprotected final SessionInactivityTimerprotected ManagedSession.Stateprotected Conditionstatic final StringDeprecated.Fields inherited from interface org.eclipse.jetty.util.Attributes
NULL -
Constructor Summary
ConstructorsConstructorDescriptionManagedSession(SessionManager manager, SessionData data) Create a new session object. -
Method Summary
Modifier and TypeMethodDescriptionbooleanaccess(long time) booleanlongcalculateInactivityTimeout(long now) Calculate what the session timer setting should be based on: the time remaining before the session expires and any idle eviction time configured.protected voidChech that the session data can be read.protected voidCheck that the session can be modified.voidCall HttpSessionAttributeListeners as part of invalidating a Session.org.eclipse.jetty.http.HttpCookiegenerateSetCookie(String name, Map<String, String> attributes) <T extends org.eclipse.jetty.server.Session.API>
TgetApi()AManagedSessionmay have an API wrapper (e.g.getAttribute(String name) longlonggetId()longintlongReturns the current number of requests that are active in the Session.getVHost()voidCalled by users to invalidate a session, or called by the access method as a request enters the session if the session has expired, or called by manager as a result of scavenger expiring sessionbooleanisExpiredAt(long time) Check to see if session has expired as at the time given.protected booleanisIdleLongerThan(int sec) Check if the Session has been idle longer than a number of seconds.booleanbooleanisNew()booleanbooleanbooleanisValid()org.eclipse.jetty.util.thread.AutoLocklock()Grab the lock on the sessionvoidvoidCall the activation listeners.protected voidonSessionAttributeUpdate(String name, Object newValue, Object oldValue) Call binding and attribute listeners based on the new and old values of the attribute.voidCall the passivation listeners.voidrelease()removeAttribute(String name) voidrenewId(org.eclipse.jetty.server.Request request, org.eclipse.jetty.server.Response response) Force a change to the id of a session.setAttribute(String name, Object value) voidsetExtendedId(String extendedId) voidsetMaxInactiveInterval(int secs) voidsetResident(boolean resident) toString()protected voiduse()Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface org.eclipse.jetty.util.Attributes
asAttributeMap, clearAttributes, equals, hashCode
-
Field Details
-
SESSION_CREATED_SECURE
Deprecated.Attribute set if the session is secure- See Also:
-
_sessionData
-
_manager
-
_extendedId
-
_requests
protected long _requests -
_needSetCookie
protected boolean _needSetCookie -
_newSession
protected boolean _newSession -
_state
-
_lock
protected org.eclipse.jetty.util.thread.AutoLock _lock -
_stateChangeCompleted
-
_resident
protected boolean _resident -
_sessionInactivityTimer
-
-
Constructor Details
-
ManagedSession
Create a new session object. The session could be an entirely new session, or could be being re-inflated from persistent store.- Parameters:
manager- the SessionHandler that manages this sessiondata- the session data
-
-
Method Details
-
getApi
public <T extends org.eclipse.jetty.server.Session.API> T getApi()A
ManagedSessionmay have an API wrapper (e.g. Servlet API), that is created by theSessionManager.newSessionAPIWrapper(ManagedSession)method during construction of aManagedSessioninstance.- Specified by:
getApiin interfaceorg.eclipse.jetty.server.Session- Type Parameters:
T- The type of theSession.API- Returns:
- The
Session.APIwrapper of this coreManagedSession.
-
getRequests
public long getRequests()Returns the current number of requests that are active in the Session.- Returns:
- the number of active requests for this session
-
setExtendedId
-
generateSetCookie
-
use
protected void use() -
access
public boolean access(long time) -
release
public void release() -
isExpiredAt
public boolean isExpiredAt(long time) Check to see if session has expired as at the time given.- Parameters:
time- the time since the epoch in ms- Returns:
- true if expired
-
isIdleLongerThan
protected boolean isIdleLongerThan(int sec) Check if the Session has been idle longer than a number of seconds.- Parameters:
sec- the number of seconds- Returns:
- true if the session has been idle longer than the interval
-
onSessionAttributeUpdate
Call binding and attribute listeners based on the new and old values of the attribute.- Parameters:
name- name of the attributenewValue- new value of the attributeoldValue- previous value of the attribute- Throws:
IllegalStateException- if no session manager can be find
-
onSessionActivation
public void onSessionActivation()Call the activation listeners. This must be called holding the lock. -
onSessionPassivation
public void onSessionPassivation()Call the passivation listeners. This must be called holding the lock -
isValid
public boolean isValid()- Specified by:
isValidin interfaceorg.eclipse.jetty.server.Session
-
isInvalidOrInvalidating
public boolean isInvalidOrInvalidating() -
getCookieSetTime
public long getCookieSetTime() -
getCreationTime
- Throws:
IllegalStateException
-
getId
- Specified by:
getIdin interfaceorg.eclipse.jetty.server.Session
-
encodeURI
-
getExtendedId
- Specified by:
getExtendedIdin interfaceorg.eclipse.jetty.server.Session
-
getVHost
-
getLastAccessedTime
public long getLastAccessedTime()- Specified by:
getLastAccessedTimein interfaceorg.eclipse.jetty.server.Session
-
setMaxInactiveInterval
public void setMaxInactiveInterval(int secs) - Specified by:
setMaxInactiveIntervalin interfaceorg.eclipse.jetty.server.Session
-
calculateInactivityTimeout
public long calculateInactivityTimeout(long now) Calculate what the session timer setting should be based on: the time remaining before the session expires and any idle eviction time configured. The timer value will be the lesser of the above.- Parameters:
now- the time at which to calculate remaining expiry- Returns:
- the time remaining before expiry or inactivity timeout
-
getMaxInactiveInterval
public int getMaxInactiveInterval()- Specified by:
getMaxInactiveIntervalin interfaceorg.eclipse.jetty.server.Session
-
getSessionManager
-
checkValidForWrite
Check that the session can be modified.- Throws:
IllegalStateException- if the session is invalid
-
checkValidForRead
Chech that the session data can be read.- Throws:
IllegalStateException- if the session is invalid
-
getAttribute
-
getAttributeNameSet
-
setAttribute
-
removeAttribute
-
renewId
public void renewId(org.eclipse.jetty.server.Request request, org.eclipse.jetty.server.Response response) Force a change to the id of a session.- Specified by:
renewIdin interfaceorg.eclipse.jetty.server.Session- Parameters:
request- the Request associated with the call to change id.
-
invalidate
public void invalidate()Called by users to invalidate a session, or called by the access method as a request enters the session if the session has expired, or called by manager as a result of scavenger expiring session- Specified by:
invalidatein interfaceorg.eclipse.jetty.server.Session
-
lock
public org.eclipse.jetty.util.thread.AutoLock lock()Grab the lock on the session- Returns:
- the lock
-
beginInvalidate
public boolean beginInvalidate()- Returns:
- true if the session is not already invalid or being invalidated.
-
finishInvalidate
Call HttpSessionAttributeListeners as part of invalidating a Session.- Throws:
IllegalStateException- if no session manager can be find
-
isNew
- Specified by:
isNewin interfaceorg.eclipse.jetty.server.Session- Throws:
IllegalStateException
-
onIdChanged
public void onIdChanged() -
isSetCookieNeeded
public boolean isSetCookieNeeded() -
getSessionData
-
setResident
public void setResident(boolean resident) -
isResident
public boolean isResident() -
toString
-