Package org.eclipse.jetty.session
Class ManagedSession
java.lang.Object
org.eclipse.jetty.session.ManagedSession
- All Implemented Interfaces:
Session
,Attributes
Session
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
Modifier and TypeClassDescriptionstatic enum
State of the session idstatic enum
Validity states of a sessionNested classes/interfaces inherited from interface org.eclipse.jetty.util.Attributes
Attributes.Layer, Attributes.Lazy, Attributes.Mapped, Attributes.Synthetic, Attributes.Wrapper
Nested classes/interfaces inherited from interface org.eclipse.jetty.server.Session
Session.API, Session.LifeCycleListener, Session.ValueListener
-
Field Summary
Modifier and TypeFieldDescriptionprotected String
protected AutoLock
protected final SessionManager
protected boolean
protected boolean
protected long
protected boolean
protected final SessionData
protected final SessionInactivityTimer
protected ManagedSession.State
protected Condition
static final String
Deprecated.Fields inherited from interface org.eclipse.jetty.util.Attributes
NULL
-
Constructor Summary
ConstructorDescriptionManagedSession
(SessionManager manager, SessionData data) Create a new session object. -
Method Summary
Modifier and TypeMethodDescriptionboolean
access
(long time) boolean
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.protected void
Chech that the session data can be read.protected void
Check that the session can be modified.void
Call HttpSessionAttributeListeners as part of invalidating a Session.generateSetCookie
(String name, Map<String, String> attributes) <T extends Session.API>
TgetApi()
AManagedSession
may have an API wrapper (e.g.getAttribute
(String name) Get an attributeGet the immutable set of attribute names.long
long
getId()
long
int
long
Returns the current number of requests that are active in the Session.getVHost()
void
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 sessionboolean
isExpiredAt
(long time) Check to see if session has expired as at the time given.protected boolean
isIdleLongerThan
(int sec) Check if the Session has been idle longer than a number of seconds.boolean
boolean
isNew()
boolean
boolean
boolean
isValid()
lock()
Grab the lock on the sessionvoid
void
Call the activation listeners.protected void
onSessionAttributeUpdate
(String name, Object newValue, Object oldValue) Call binding and attribute listeners based on the new and old values of the attribute.void
Call the passivation listeners.removeAttribute
(String name) Remove an attributevoid
Force a change to the id of a session.setAttribute
(String name, Object value) Set an attributevoid
setExtendedId
(String extendedId) void
setMaxInactiveInterval
(int secs) void
setResident
(boolean resident) toString()
protected void
use()
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.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
ManagedSession
may have an API wrapper (e.g. Servlet API), that is created by theSessionManager.newSessionAPIWrapper(ManagedSession)
method during construction of aManagedSession
instance.- Specified by:
getApi
in interfaceSession
- Type Parameters:
T
- The type of theSession.API
- Returns:
- The
Session.API
wrapper 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) -
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() -
isInvalidOrInvalidating
public boolean isInvalidOrInvalidating() -
getCookieSetTime
public long getCookieSetTime() -
getCreationTime
- Throws:
IllegalStateException
-
getId
-
encodeURI
-
getExtendedId
- Specified by:
getExtendedId
in 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:
getLastAccessedTime
in 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:
setMaxInactiveInterval
in 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:
getMaxInactiveInterval
in 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:Attributes
Get an attribute- Specified by:
getAttribute
in interfaceAttributes
- Parameters:
name
- the attribute to get- Returns:
- the value of the attribute, or
null
if no such attribute exists
-
getAttributeNameSet
Description copied from interface:Attributes
Get the immutable set of attribute names.- Specified by:
getAttributeNameSet
in interfaceAttributes
- Returns:
- Set of attribute names, or an empty set if there are no attributes.
-
setAttribute
Description copied from interface:Attributes
Set an attribute- Specified by:
setAttribute
in 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:Attributes
Remove an attribute- Specified by:
removeAttribute
in interfaceAttributes
- Parameters:
name
- the attribute to remove- Returns:
- the value of the attribute if removed, else
null
-
renewId
Force a change to the id of a session. -
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:
invalidate
in interfaceSession
-
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:
isNew
in interfaceSession
- Returns:
true
if 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
-