Class ManagedSession
java.lang.Object
org.eclipse.jetty.session.ManagedSession
- All Implemented Interfaces:
 Session, 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 Attributes
Attributes.Layer, Attributes.Lazy, Attributes.Mapped, Attributes.Synthetic, Attributes.WrapperNested classes/interfaces inherited from interface Session
Session.API, Session.LifeCycleListener, Session.ValueListener - 
Field Summary
FieldsModifier and TypeFieldDescriptionprotected Stringprotected AutoLockprotected final SessionManagerprotected booleanprotected booleanprotected longprotected booleanprotected final SessionDataprotected final SessionInactivityTimerprotected ManagedSession.Stateprotected Conditionstatic final StringDeprecated.Fields inherited from interface 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.generateSetCookie(String name, Map<String, String> attributes) <T extends Session.API>
TgetApi()AManagedSessionmay have an API wrapper (e.g.getAttribute(String name) Get an attribute by name.Get the immutable set of attribute names.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()lock()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) Remove an attributevoidForce a change to the id of a session.setAttribute(String name, Object value) Set an attributevoidsetExtendedId(String extendedId) voidsetMaxInactiveInterval(int secs) voidsetResident(boolean resident) toString()protected voiduse()Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface 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
 - 
_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
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 interfaceSession- 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
 - 
isInvalidOrInvalidating
public boolean isInvalidOrInvalidating() - 
getCookieSetTime
public long getCookieSetTime() - 
getCreationTime
- Throws:
 IllegalStateException
 - 
getId
 - 
encodeURI
 - 
getExtendedId
- Specified by:
 getExtendedIdin interfaceSession- Returns:
 - The session identifier as returned by 
Session.getId()extended with additional routing information. The additional information does not form part of the identity, but may be used by implementations and associated infrastructure to help route request for the same session to the same server. 
 - 
getVHost
 - 
getLastAccessedTime
public long getLastAccessedTime()- Specified by:
 getLastAccessedTimein interfaceSession- Returns:
 - the time, as represented by 
System.currentTimeMillis(), that the session was last accessed by a request. 
 - 
setMaxInactiveInterval
public void setMaxInactiveInterval(int secs) - Specified by:
 setMaxInactiveIntervalin interfaceSession- Parameters:
 secs- The period in secs in which the session will remain valid (unless explicitly invalidated) when not accessed by any requests.
 - 
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 interfaceSession- Returns:
 - The period in secs in which the session will remain valid (unless explicitly invalidated) when not accessed by any requests.
 
 - 
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
Description copied from interface:AttributesGet an attribute by name. Some attributes may be "hidden" attributes, in that they are only found by an explicit call togetAttribute(String)and they do not otherwise appear inAttributes.getAttributeNameSet()orAttributes.asAttributeMap().- Specified by:
 getAttributein interfaceAttributes- Parameters:
 name- the attribute to get- Returns:
 - the value of the attribute, or 
nullif no such attribute exists 
 - 
getAttributeNameSet
Description copied from interface:AttributesGet the immutable set of attribute names.- Specified by:
 getAttributeNameSetin interfaceAttributes- Returns:
 - Set of attribute names, or an empty set if there are no attributes.
 
 - 
setAttribute
Description copied from interface:AttributesSet an attribute- Specified by:
 setAttributein interfaceAttributes- Parameters:
 name- the attribute to setvalue- the value to set. A null value is equivalent to removing the attribute.- Returns:
 - the previous value of the attribute if set, else 
null 
 - 
removeAttribute
Description copied from interface:AttributesRemove an attribute- Specified by:
 removeAttributein interfaceAttributes- Parameters:
 name- the attribute to remove- Returns:
 - the value of the attribute if removed, else 
null 
 - 
renewId
 - 
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 interfaceSession
 - 
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 interfaceSession- Returns:
 trueif the session has been newly created within the scope of the current request.- Throws:
 IllegalStateException
 - 
onIdChanged
public void onIdChanged() - 
isSetCookieNeeded
public boolean isSetCookieNeeded() - 
getSessionData
 - 
setResident
public void setResident(boolean resident)  - 
isResident
public boolean isResident() - 
toString
 
 -