Top Description Inners Fields Constructors Methods
org.eclipse.jetty.session

public Class ManagedSession

extends Object
implements Session
Class Inheritance
All Implemented Interfaces
org.eclipse.jetty.server.Session, org.eclipse.jetty.util.Attributes
Imports
java.util.Collections, .List, .Map, .Objects, .Set, java.util.concurrent.CopyOnWriteArrayList, java.util.concurrent.locks.Condition, org.eclipse.jetty.http.HttpCookie, org.eclipse.jetty.server.Request, .Response, .Session, org.eclipse.jetty.util.thread.AutoLock, org.slf4j.Logger, .LoggerFactory

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
SessionManager, org.eclipse.jetty.session.SessionIdManager

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static enum
ManagedSession.IdState

State of the session id

public static enum
ManagedSession.State

Validity states of a session

Field Summary

Modifier and TypeField and Description
private final Session.API
protected 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
private final List<Session.ValueListener>
private static final Logger
public static final String
SESSION_CREATED_SECURE

Deprecated
Attribute set if the session is secure

Constructor Summary

AccessConstructor and Description
public
ManagedSession(SessionManager
the SessionHandler that manages this session
manager
,
SessionData
the session data
data
)

Create a new session object.

Method Summary

Modifier and TypeMethod and Description
public boolean
access(long time)

public boolean
beginInvalidate()

Returns: true if the session is not already invalid or being invalidated.

public long

Returns:

the time remaining before expiry or inactivity timeout
calculateInactivityTimeout
(long
the time at which to calculate remaining expiry
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
checkValidForRead()

Chech that the session data can be read.

protected void
checkValidForWrite()

Check that the session can be modified.

public String
encodeURI(Request request, String uri, boolean cookiesInUse)

Implements org.eclipse.jetty.server.Session.encodeURI.

public void
finishInvalidate()

Call HttpSessionAttributeListeners as part of invalidating a Session.

public HttpCookie
public <
The type of the API
T extends Session.API
>
T

Returns:

The API wrapper of this core ManagedSession.
getApi
()

Implements org.eclipse.jetty.server.Session.getApi.

A ManagedSession may have an API wrapper (e.g. Servlet API), that is created by the SessionManager#newSessionAPIWrapper(ManagedSession) method during construction of a ManagedSession instance.

public Object
getAttribute(String
the attribute to get
name
)

Implements org.eclipse.jetty.util.Attributes.getAttribute.

Get an attribute

public Set<String>
getAttributeNameSet()

Implements org.eclipse.jetty.util.Attributes.getAttributeNameSet.

Get the immutable set of attribute names.

public long
public long
public String
public String
public long
public int
public long

Returns:

the number of active requests for this session
getRequests
()

Returns the current number of requests that are active in the Session.

public SessionData
public SessionManager
public String
public void
invalidate()

Implements org.eclipse.jetty.server.Session.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

public boolean

Returns:

true if expired
isExpiredAt
(long
the time since the epoch in ms
time
)

Check to see if session has expired as at the time given.

protected boolean

Returns:

true if the session has been idle longer than the interval
isIdleLongerThan
(int
the number of seconds
sec
)

Check if the Session has been idle longer than a number of seconds.

public boolean
public boolean
public boolean
public boolean
public boolean
public AutoLock

Returns:

the lock
lock
()

Grab the lock on the session

public void
public void
onSessionActivation()

Call the activation listeners.

protected void
onSessionAttributeUpdate(String
name of the attribute
name
,
Object
new value of the attribute
newValue
,
Object
previous value of the attribute
oldValue
)

Call binding and attribute listeners based on the new and old values of the attribute.

public void
onSessionPassivation()

Call the passivation listeners.

pack-priv void
onSetCookieGenerated()

Set the time that the cookie was set and clear the idChanged flag.

pack-priv void
public Object
removeAttribute(String
the attribute to remove
name
)

Implements org.eclipse.jetty.util.Attributes.removeAttribute.

Remove an attribute

public void
renewId(Request
the Request associated with the call to change id.
request
,
Response
The response which may be updated with the new session identity.
response
)

Implements org.eclipse.jetty.server.Session.renewId.

Force a change to the id of a session.

public Object
setAttribute(String
the attribute to set
name
,
Object
the value to set. A null value is equivalent to removing the attribute.
value
)

Implements org.eclipse.jetty.util.Attributes.setAttribute.

Set an attribute

public void
setExtendedId(String extendedId)

public void
setMaxInactiveInterval(int
The period in secs in which the session will remain valid (unless explicitly invalidated) when not accessed by any requests.
secs
)

Implements org.eclipse.jetty.server.Session.setMaxInactiveInterval.

public void
setResident(boolean resident)

public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.

protected void
use()

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAllwaitwaitwait

Field Detail

_apiback to summary
private final Session.API _api
_extendedIdback to summary
protected String _extendedId
_lockback to summary
protected AutoLock _lock
_managerback to summary
protected final SessionManager _manager
_needSetCookieback to summary
protected boolean _needSetCookie
_newSessionback to summary
protected boolean _newSession
_requestsback to summary
protected long _requests
_residentback to summary
protected boolean _resident
_sessionDataback to summary
protected final SessionData _sessionData
_sessionInactivityTimerback to summary
protected final SessionInactivityTimer _sessionInactivityTimer
_stateback to summary
protected ManagedSession.State _state
_stateChangeCompletedback to summary
protected Condition _stateChangeCompleted
_valueListenerListback to summary
private final List<Session.ValueListener> _valueListenerList
LOGback to summary
private static final Logger LOG
SESSION_CREATED_SECUREback to summary
public static final String SESSION_CREATED_SECURE

Deprecated

Attribute set if the session is secure

Annotations
@Deprecated

Constructor Detail

ManagedSessionback to summary
public ManagedSession(SessionManager manager, SessionData data)

Create a new session object. The session could be an entirely new session, or could be being re-inflated from persistent store.

Parameters
manager:SessionManager

the SessionHandler that manages this session

data:SessionData

the session data

Method Detail

accessback to summary
public boolean access(long time)
beginInvalidateback to summary
public boolean beginInvalidate()
Returns:boolean

true if the session is not already invalid or being invalidated.

calculateInactivityTimeoutback to summary
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:long

the time at which to calculate remaining expiry

Returns:long

the time remaining before expiry or inactivity timeout

checkValidForReadback to summary
protected void checkValidForRead() throws IllegalStateException

Chech that the session data can be read.

Exceptions
IllegalStateException:
if the session is invalid
checkValidForWriteback to summary
protected void checkValidForWrite() throws IllegalStateException

Check that the session can be modified.

Exceptions
IllegalStateException:
if the session is invalid
encodeURIback to summary
public String encodeURI(Request request, String uri, boolean cookiesInUse)

Implements org.eclipse.jetty.server.Session.encodeURI.

Annotations
@Override
finishInvalidateback to summary
public void finishInvalidate() throws IllegalStateException

Call HttpSessionAttributeListeners as part of invalidating a Session.

Exceptions
IllegalStateException:
if no session manager can be find
generateSetCookieback to summary
public HttpCookie generateSetCookie(String name, Map<String, String> attributes)
getApiback to summary
public <T extends Session.API> T getApi()

Implements org.eclipse.jetty.server.Session.getApi.

A ManagedSession may have an API wrapper (e.g. Servlet API), that is created by the SessionManager#newSessionAPIWrapper(ManagedSession) method during construction of a ManagedSession instance.

Parameters
<T>
The type of the API
Returns:T

The API wrapper of this core ManagedSession.

Annotations
@Override
@SuppressWarnings:unchecked
getAttributeback to summary
public Object getAttribute(String name)

Implements org.eclipse.jetty.util.Attributes.getAttribute.

Doc from org.eclipse.jetty.util.Attributes.getAttribute.

Get an attribute

Parameters
name:String

the attribute to get

Returns:Object

the value of the attribute

Annotations
@Override
getAttributeNameSetback to summary
public Set<String> getAttributeNameSet()

Implements org.eclipse.jetty.util.Attributes.getAttributeNameSet.

Doc from org.eclipse.jetty.util.Attributes.getAttributeNameSet.

Get the immutable set of attribute names.

Returns:Set<String>

Set of attribute names

Annotations
@Override
getCookieSetTimeback to summary
public long getCookieSetTime()
getCreationTimeback to summary
public long getCreationTime() throws IllegalStateException
getExtendedIdback to summary
public String getExtendedId()

Implements org.eclipse.jetty.server.Session.getExtendedId.

Returns:String

Doc from org.eclipse.jetty.server.Session.getExtendedId.

The session identifier as returned by 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.

Annotations
@Override
getIdback to summary
public String getId()

Implements org.eclipse.jetty.server.Session.getId.

Returns:String

Doc from org.eclipse.jetty.server.Session.getId.

A identifier for the session. Depending on the implementation may be unique within the context, the server, the JVM or a cluster.

Annotations
@Override
getLastAccessedTimeback to summary
public long getLastAccessedTime()

Implements org.eclipse.jetty.server.Session.getLastAccessedTime.

Returns:long

Doc from org.eclipse.jetty.server.Session.getLastAccessedTime.

the time, as represented by System#currentTimeMillis(), that the session was last accessed by a request.

Annotations
@Override
getMaxInactiveIntervalback to summary
public int getMaxInactiveInterval()

Implements org.eclipse.jetty.server.Session.getMaxInactiveInterval.

Returns:int

Doc from org.eclipse.jetty.server.Session.getMaxInactiveInterval.

The period in secs in which the session will remain valid (unless explicitly invalidated) when not accessed by any requests.

Annotations
@Override
getRequestsback to summary
public long getRequests()

Returns the current number of requests that are active in the Session.

Returns:long

the number of active requests for this session

getSessionDataback to summary
public SessionData getSessionData()
getSessionManagerback to summary
public SessionManager getSessionManager()
getVHostback to summary
public String getVHost()
invalidateback to summary
public void invalidate()

Implements org.eclipse.jetty.server.Session.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

Annotations
@Override
isExpiredAtback to summary
public boolean isExpiredAt(long time)

Check to see if session has expired as at the time given.

Parameters
time:long

the time since the epoch in ms

Returns:boolean

true if expired

isIdleLongerThanback to summary
protected boolean isIdleLongerThan(int sec)

Check if the Session has been idle longer than a number of seconds.

Parameters
sec:int

the number of seconds

Returns:boolean

true if the session has been idle longer than the interval

isInvalidOrInvalidatingback to summary
public boolean isInvalidOrInvalidating()
isNewback to summary
public boolean isNew() throws IllegalStateException

Implements org.eclipse.jetty.server.Session.isNew.

Returns:boolean

Doc from org.eclipse.jetty.server.Session.isNew.

true if the session has been newly created within the scope of the current request.

Annotations
@Override
isResidentback to summary
public boolean isResident()
isSetCookieNeededback to summary
public boolean isSetCookieNeeded()
isValidback to summary
public boolean isValid()

Implements org.eclipse.jetty.server.Session.isValid.

Returns:boolean

Doc from org.eclipse.jetty.server.Session.isValid.

true if the session is has not been invalidated nor expired due to inactivity.

Annotations
@Override
lockback to summary
public AutoLock lock()

Grab the lock on the session

Returns:AutoLock

the lock

onIdChangedback to summary
public void onIdChanged()
onSessionActivationback to summary
public void onSessionActivation()

Call the activation listeners. This must be called holding the lock.

onSessionAttributeUpdateback to summary
protected void onSessionAttributeUpdate(String name, Object newValue, Object oldValue)

Call binding and attribute listeners based on the new and old values of the attribute.

Parameters
name:String

name of the attribute

newValue:Object

new value of the attribute

oldValue:Object

previous value of the attribute

Exceptions
IllegalStateException:
if no session manager can be find
onSessionPassivationback to summary
public void onSessionPassivation()

Call the passivation listeners. This must be called holding the lock

onSetCookieGeneratedback to summary
pack-priv void onSetCookieGenerated()

Set the time that the cookie was set and clear the idChanged flag.

releaseback to summary
pack-priv void release()
removeAttributeback to summary
public Object removeAttribute(String name)

Implements org.eclipse.jetty.util.Attributes.removeAttribute.

Doc from org.eclipse.jetty.util.Attributes.removeAttribute.

Remove an attribute

Parameters
name:String

the attribute to remove

Returns:Object

the value of the attribute if removed, else null

Annotations
@Override
renewIdback to summary
public void renewId(Request request, Response response)

Implements org.eclipse.jetty.server.Session.renewId.

Force a change to the id of a session.

Parameters
request:Request

the Request associated with the call to change id.

response:Response

Doc from org.eclipse.jetty.server.Session.renewId.

The response which may be updated with the new session identity.

Annotations
@Override
setAttributeback to summary
public Object setAttribute(String name, Object value)

Implements org.eclipse.jetty.util.Attributes.setAttribute.

Doc from org.eclipse.jetty.util.Attributes.setAttribute.

Set an attribute

Parameters
name:String

the attribute to set

value:Object

the value to set. A null value is equivalent to removing the attribute.

Returns:Object

the previous value of the attribute if set, else null

Annotations
@Override
setExtendedIdback to summary
public void setExtendedId(String extendedId)
setMaxInactiveIntervalback to summary
public void setMaxInactiveInterval(int secs)

Implements org.eclipse.jetty.server.Session.setMaxInactiveInterval.

Parameters
secs:int

Doc from org.eclipse.jetty.server.Session.setMaxInactiveInterval.

The period in secs in which the session will remain valid (unless explicitly invalidated) when not accessed by any requests.

Annotations
@Override
setResidentback to summary
public void setResident(boolean resident)
toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object. Satisfying this method's contract implies a non-null result must be returned.

Returns:String

a string representation of the object

Annotations
@Override
useback to summary
protected void use()
org.eclipse.jetty.session back to summary

public final Enum ManagedSession.IdState

extends Enum<ManagedSession.IdState>
Class Inheritance

State of the session id

Field Summary

Modifier and TypeField and Description
public static final ManagedSession.IdState
public static final ManagedSession.IdState

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public static ManagedSession.IdState
public static ManagedSession.IdState[]
Inherited from java.lang.Enum:
clonecompareTodescribeConstableequalsfinalizegetDeclaringClasshashCodenameordinaltoStringvalueOf

Field Detail

CHANGINGback to summary
public static final ManagedSession.IdState CHANGING
SETback to summary
public static final ManagedSession.IdState SET

Constructor Detail

IdStateback to summary
private IdState()

Method Detail

valueOfback to summary
public static ManagedSession.IdState valueOf(String name)
valuesback to summary
public static ManagedSession.IdState[] values()
org.eclipse.jetty.session back to summary

public final Enum ManagedSession.State

extends Enum<ManagedSession.State>
Class Inheritance

Validity states of a session

Field Summary

Modifier and TypeField and Description
public static final ManagedSession.State
public static final ManagedSession.State
public static final ManagedSession.State
public static final ManagedSession.State

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public static ManagedSession.State
public static ManagedSession.State[]
Inherited from java.lang.Enum:
clonecompareTodescribeConstableequalsfinalizegetDeclaringClasshashCodenameordinaltoStringvalueOf

Field Detail

CHANGINGback to summary
public static final ManagedSession.State CHANGING
INVALIDback to summary
public static final ManagedSession.State INVALID
INVALIDATINGback to summary
public static final ManagedSession.State INVALIDATING
VALIDback to summary
public static final ManagedSession.State VALID

Constructor Detail

Stateback to summary
private State()

Method Detail

valueOfback to summary
public static ManagedSession.State valueOf(String name)
valuesback to summary
public static ManagedSession.State[] values()