Package org.eclipse.jetty.server.session
Class Session
java.lang.Object
org.eclipse.jetty.server.session.Session
- All Implemented Interfaces:
jakarta.servlet.http.HttpSession
,SessionHandler.SessionIf
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 SessionHandler
coordinates the lifecycle of Session objects with
the help of the SessionCache.- See Also:
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic enum
class
SessionInactivityTimer Each Session has a timer associated with it that fires whenever it has been idle (ie not accessed by a request) for a configurable amount of time, or the Session expires.static enum
State Validity states of a session -
Field Summary
Modifier and TypeFieldDescriptionprotected String
protected final SessionHandler
protected boolean
protected AutoLock
protected boolean
protected long
protected boolean
protected final SessionData
protected final Session.SessionInactivityTimer
protected Session.State
protected Condition
static final String
-
Constructor Summary
ConstructorDescriptionSession
(SessionHandler handler, jakarta.servlet.http.HttpServletRequest request, SessionData data) Create a new sessionSession
(SessionHandler handler, SessionData data) Re-inflate an existing session from some eg persistent store. -
Method Summary
Modifier and TypeMethodDescriptionprotected boolean
access
(long time) protected boolean
void
Bind value if value implementsHttpSessionBindingListener
(callsHttpSessionBindingListener.valueBound(HttpSessionBindingEvent)
)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
callSessionAttributeListeners
(String name, Object newValue, Object oldValue) Call binding and attribute listeners based on the new and old values of the attribute.protected void
Chech that the session data can be read.protected void
Check that the session can be modified.protected void
complete()
protected void
void
Call the activation listeners.protected void
Call HttpSessionAttributeListeners as part of invalidating a Session.getAttribute
(String name) int
long
long
getId()
long
int
getNames()
long
Returns the current number of requests that are active in the Session.jakarta.servlet.ServletContext
jakarta.servlet.http.HttpSessionContext
Deprecated.protected SessionData
Deprecated.String[]
Deprecated.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 sessionprotected boolean
isExpiredAt
(long time) Check to see if session has expired as at the time given.boolean
protected boolean
isIdleLongerThan
(int sec) Check if the Session has been idle longer than a number of seconds.boolean
boolean
isNew()
boolean
boolean
isValid()
lock()
Grab the lock on the sessionvoid
Deprecated.void
removeAttribute
(String name) void
removeValue
(String name) Deprecated.void
renewId
(jakarta.servlet.http.HttpServletRequest request) Force a change to the id of a session.void
setAttribute
(String name, Object value) void
setExtendedId
(String extendedId) void
setIdChanged
(boolean changed) void
setMaxInactiveInterval
(int secs) void
setResident
(boolean resident) toString()
void
unbindValue
(String name, Object value) Unbind value if value implementsHttpSessionBindingListener
(callsHttpSessionBindingListener.valueUnbound(HttpSessionBindingEvent)
)protected void
use()
void
Call the passivation listeners.
-
Field Details
-
SESSION_CREATED_SECURE
- See Also:
-
_sessionData
-
_handler
-
_extendedId
-
_requests
protected long _requests -
_idChanged
protected boolean _idChanged -
_newSession
protected boolean _newSession -
_state
-
_lock
-
_stateChangeCompleted
-
_resident
protected boolean _resident -
_sessionInactivityTimer
-
-
Constructor Details
-
Session
public Session(SessionHandler handler, jakarta.servlet.http.HttpServletRequest request, SessionData data) Create a new session- Parameters:
handler
- the SessionHandler that manages this sessionrequest
- the request the session should be based ondata
- the session data
-
Session
Re-inflate an existing session from some eg persistent store.- Parameters:
handler
- the SessionHandler managing the sessiondata
- the session data
-
-
Method Details
-
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
-
cookieSet
protected void cookieSet() -
use
protected void use() -
access
protected boolean access(long time) -
complete
protected void complete() -
isExpiredAt
protected 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
-
callSessionAttributeListeners
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
-
unbindValue
Unbind value if value implementsHttpSessionBindingListener
(callsHttpSessionBindingListener.valueUnbound(HttpSessionBindingEvent)
)- Parameters:
name
- the name with which the object is bound or unboundvalue
- the bound value
-
bindValue
Bind value if value implementsHttpSessionBindingListener
(callsHttpSessionBindingListener.valueBound(HttpSessionBindingEvent)
)- Parameters:
name
- the name with which the object is bound or unboundvalue
- the bound value
-
didActivate
public void didActivate()Call the activation listeners. This must be called holding the lock. -
willPassivate
public void willPassivate()Call the passivation listeners. This must be called holding the lock -
isValid
public boolean isValid() -
isInvalid
public boolean isInvalid() -
getCookieSetTime
public long getCookieSetTime() -
getCreationTime
- Specified by:
getCreationTime
in interfacejakarta.servlet.http.HttpSession
- Throws:
IllegalStateException
-
getId
- Specified by:
getId
in interfacejakarta.servlet.http.HttpSession
-
getExtendedId
-
getContextPath
-
getVHost
-
getLastAccessedTime
public long getLastAccessedTime()- Specified by:
getLastAccessedTime
in interfacejakarta.servlet.http.HttpSession
-
getServletContext
public jakarta.servlet.ServletContext getServletContext()- Specified by:
getServletContext
in interfacejakarta.servlet.http.HttpSession
-
setMaxInactiveInterval
public void setMaxInactiveInterval(int secs) - Specified by:
setMaxInactiveInterval
in interfacejakarta.servlet.http.HttpSession
-
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 interfacejakarta.servlet.http.HttpSession
-
getSessionContext
@Deprecated(since="Servlet API 2.1") public jakarta.servlet.http.HttpSessionContext getSessionContext()Deprecated.- Specified by:
getSessionContext
in interfacejakarta.servlet.http.HttpSession
-
getSessionHandler
-
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
- Specified by:
getAttribute
in interfacejakarta.servlet.http.HttpSession
-
getValue
Deprecated.- Specified by:
getValue
in interfacejakarta.servlet.http.HttpSession
-
getAttributeNames
- Specified by:
getAttributeNames
in interfacejakarta.servlet.http.HttpSession
-
getAttributes
public int getAttributes() -
getNames
-
getValueNames
Deprecated.As of Servlet 2.2, this method is replaced bygetAttributeNames()
- Specified by:
getValueNames
in interfacejakarta.servlet.http.HttpSession
- Throws:
IllegalStateException
-
setAttribute
- Specified by:
setAttribute
in interfacejakarta.servlet.http.HttpSession
-
putValue
Deprecated.- Specified by:
putValue
in interfacejakarta.servlet.http.HttpSession
-
removeAttribute
- Specified by:
removeAttribute
in interfacejakarta.servlet.http.HttpSession
-
removeValue
Deprecated.- Specified by:
removeValue
in interfacejakarta.servlet.http.HttpSession
-
renewId
public void renewId(jakarta.servlet.http.HttpServletRequest request) Force a change to the id of a 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:
invalidate
in interfacejakarta.servlet.http.HttpSession
- See Also:
-
HttpSession.invalidate()
-
lock
Grab the lock on the session- Returns:
- the lock
-
beginInvalidate
protected 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 interfacejakarta.servlet.http.HttpSession
- Throws:
IllegalStateException
-
setIdChanged
public void setIdChanged(boolean changed) -
isIdChanged
public boolean isIdChanged() -
getSession
- Specified by:
getSession
in interfaceSessionHandler.SessionIf
-
getSessionData
-
setResident
public void setResident(boolean resident) -
isResident
public boolean isResident() -
toString
-
getAttributeNames()