Package org.eclipse.jetty.server.session
Class Session
- java.lang.Object
-
- org.eclipse.jetty.server.session.Session
-
- All Implemented Interfaces:
javax.servlet.http.HttpSession
,SessionHandler.SessionIf
public class Session extends java.lang.Object implements SessionHandler.SessionIf
Session A heavy-weight Session object representing an HttpSession. Session objects relating to a context are kept in aSessionCache
. 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. TheSessionHandler
coordinates the lifecycle of Session objects with the help of the SessionCache.- See Also:
SessionHandler
,SessionIdManager
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
Session.IdState
class
Session.SessionInactivityTimer
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 class
Session.State
State Validity states of a session
-
Field Summary
Fields Modifier and Type Field Description protected java.lang.String
_extendedId
protected SessionHandler
_handler
protected boolean
_idChanged
protected Locker
_lock
protected boolean
_newSession
protected long
_requests
protected boolean
_resident
protected SessionData
_sessionData
protected Session.SessionInactivityTimer
_sessionInactivityTimer
protected Session.State
_state
protected java.util.concurrent.locks.Condition
_stateChangeCompleted
static java.lang.String
SESSION_CREATED_SECURE
-
Constructor Summary
Constructors Constructor Description Session(SessionHandler handler, javax.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
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description protected boolean
access(long time)
protected boolean
beginInvalidate()
void
bindValue(java.lang.String name, java.lang.Object value)
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(java.lang.String name, java.lang.Object newValue, java.lang.Object oldValue)
Call binding and attribute listeners based on the new and old values of the attribute.protected void
checkLocked()
protected void
checkValidForRead()
Chech that the session data can be read.protected void
checkValidForWrite()
Check that the session can be modified.protected void
complete()
protected void
cookieSet()
void
didActivate()
Call the activation listeners.protected void
doInvalidate()
Deprecated.protected void
finishInvalidate()
Call HttpSessionAttributeListeners as part of invalidating a Session.java.lang.Object
getAttribute(java.lang.String name)
java.util.Enumeration<java.lang.String>
getAttributeNames()
int
getAttributes()
java.lang.String
getContextPath()
long
getCookieSetTime()
long
getCreationTime()
java.lang.String
getExtendedId()
java.lang.String
getId()
long
getLastAccessedTime()
int
getMaxInactiveInterval()
java.util.Set<java.lang.String>
getNames()
long
getRequests()
Returns the current number of requests that are active in the Session.javax.servlet.ServletContext
getServletContext()
Session
getSession()
javax.servlet.http.HttpSessionContext
getSessionContext()
Deprecated.protected SessionData
getSessionData()
SessionHandler
getSessionHandler()
java.lang.Object
getValue(java.lang.String name)
Deprecated.java.lang.String[]
getValueNames()
Deprecated.As of Version 2.2, this method is replaced bygetAttributeNames()
java.lang.String
getVHost()
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 sessionboolean
isChanging()
protected boolean
isExpiredAt(long time)
Check to see if session has expired as at the time given.boolean
isIdChanged()
protected boolean
isIdleLongerThan(int sec)
Check if the Session has been idle longer than a number of seconds.boolean
isInvalid()
boolean
isNew()
boolean
isResident()
boolean
isValid()
Locker.Lock
lock()
Grab the lock on the sessionvoid
putValue(java.lang.String name, java.lang.Object value)
Deprecated.void
removeAttribute(java.lang.String name)
void
removeValue(java.lang.String name)
Deprecated.void
renewId(javax.servlet.http.HttpServletRequest request)
Force a change to the id of a session.void
setAttribute(java.lang.String name, java.lang.Object value)
void
setExtendedId(java.lang.String extendedId)
void
setIdChanged(boolean changed)
void
setMaxInactiveInterval(int secs)
void
setResident(boolean resident)
java.lang.String
toString()
void
unbindValue(java.lang.String name, java.lang.Object value)
Unbind value if value implementsHttpSessionBindingListener
(callsHttpSessionBindingListener.valueUnbound(HttpSessionBindingEvent)
)void
updateInactivityTimer()
Deprecated.protected void
use()
void
willPassivate()
Call the passivation listeners.
-
-
-
Field Detail
-
SESSION_CREATED_SECURE
public static final java.lang.String SESSION_CREATED_SECURE
- See Also:
- Constant Field Values
-
_sessionData
protected final SessionData _sessionData
-
_handler
protected final SessionHandler _handler
-
_extendedId
protected java.lang.String _extendedId
-
_requests
protected long _requests
-
_idChanged
protected boolean _idChanged
-
_newSession
protected boolean _newSession
-
_state
protected Session.State _state
-
_lock
protected Locker _lock
-
_stateChangeCompleted
protected java.util.concurrent.locks.Condition _stateChangeCompleted
-
_resident
protected boolean _resident
-
_sessionInactivityTimer
protected final Session.SessionInactivityTimer _sessionInactivityTimer
-
-
Constructor Detail
-
Session
public Session(SessionHandler handler, javax.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
public Session(SessionHandler handler, SessionData data)
Re-inflate an existing session from some eg persistent store.- Parameters:
handler
- the SessionHandler managing the sessiondata
- the session data
-
-
Method Detail
-
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
public void setExtendedId(java.lang.String extendedId)
-
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
protected void callSessionAttributeListeners(java.lang.String name, java.lang.Object newValue, java.lang.Object oldValue)
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:
java.lang.IllegalStateException
- if no session manager can be find
-
unbindValue
public void unbindValue(java.lang.String name, java.lang.Object value)
Unbind value if value implementsHttpSessionBindingListener
(callsHttpSessionBindingListener.valueUnbound(HttpSessionBindingEvent)
)- Parameters:
name
- the name with which the object is bound or unboundvalue
- the bound value
-
bindValue
public void bindValue(java.lang.String name, java.lang.Object value)
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()
-
isChanging
public boolean isChanging()
-
getCookieSetTime
public long getCookieSetTime()
-
getCreationTime
public long getCreationTime() throws java.lang.IllegalStateException
- Specified by:
getCreationTime
in interfacejavax.servlet.http.HttpSession
- Throws:
java.lang.IllegalStateException
-
getId
public java.lang.String getId()
- Specified by:
getId
in interfacejavax.servlet.http.HttpSession
- See Also:
HttpSession.getId()
-
getExtendedId
public java.lang.String getExtendedId()
-
getContextPath
public java.lang.String getContextPath()
-
getVHost
public java.lang.String getVHost()
-
getLastAccessedTime
public long getLastAccessedTime()
- Specified by:
getLastAccessedTime
in interfacejavax.servlet.http.HttpSession
- See Also:
HttpSession.getLastAccessedTime()
-
getServletContext
public javax.servlet.ServletContext getServletContext()
- Specified by:
getServletContext
in interfacejavax.servlet.http.HttpSession
- See Also:
HttpSession.getServletContext()
-
setMaxInactiveInterval
public void setMaxInactiveInterval(int secs)
- Specified by:
setMaxInactiveInterval
in interfacejavax.servlet.http.HttpSession
- See Also:
HttpSession.setMaxInactiveInterval(int)
-
updateInactivityTimer
@Deprecated public void updateInactivityTimer()
Deprecated.
-
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 interfacejavax.servlet.http.HttpSession
- See Also:
HttpSession.getMaxInactiveInterval()
-
getSessionContext
@Deprecated public javax.servlet.http.HttpSessionContext getSessionContext()
Deprecated.- Specified by:
getSessionContext
in interfacejavax.servlet.http.HttpSession
- See Also:
HttpSession.getSessionContext()
-
getSessionHandler
public SessionHandler getSessionHandler()
-
checkValidForWrite
protected void checkValidForWrite() throws java.lang.IllegalStateException
Check that the session can be modified.- Throws:
java.lang.IllegalStateException
- if the session is invalid
-
checkValidForRead
protected void checkValidForRead() throws java.lang.IllegalStateException
Chech that the session data can be read.- Throws:
java.lang.IllegalStateException
- if the session is invalid
-
checkLocked
protected void checkLocked() throws java.lang.IllegalStateException
- Throws:
java.lang.IllegalStateException
-
getAttribute
public java.lang.Object getAttribute(java.lang.String name)
- Specified by:
getAttribute
in interfacejavax.servlet.http.HttpSession
- See Also:
HttpSession.getAttribute(java.lang.String)
-
getValue
@Deprecated public java.lang.Object getValue(java.lang.String name)
Deprecated.- Specified by:
getValue
in interfacejavax.servlet.http.HttpSession
- See Also:
HttpSession.getValue(java.lang.String)
-
getAttributeNames
public java.util.Enumeration<java.lang.String> getAttributeNames()
- Specified by:
getAttributeNames
in interfacejavax.servlet.http.HttpSession
- See Also:
HttpSession.getAttributeNames()
-
getAttributes
public int getAttributes()
-
getNames
public java.util.Set<java.lang.String> getNames()
-
getValueNames
@Deprecated public java.lang.String[] getValueNames() throws java.lang.IllegalStateException
Deprecated.As of Version 2.2, this method is replaced bygetAttributeNames()
- Specified by:
getValueNames
in interfacejavax.servlet.http.HttpSession
- Throws:
java.lang.IllegalStateException
-
setAttribute
public void setAttribute(java.lang.String name, java.lang.Object value)
- Specified by:
setAttribute
in interfacejavax.servlet.http.HttpSession
- See Also:
HttpSession.setAttribute(java.lang.String, java.lang.Object)
-
putValue
@Deprecated public void putValue(java.lang.String name, java.lang.Object value)
Deprecated.- Specified by:
putValue
in interfacejavax.servlet.http.HttpSession
- See Also:
HttpSession.putValue(java.lang.String, java.lang.Object)
-
removeAttribute
public void removeAttribute(java.lang.String name)
- Specified by:
removeAttribute
in interfacejavax.servlet.http.HttpSession
- See Also:
HttpSession.removeAttribute(java.lang.String)
-
removeValue
@Deprecated public void removeValue(java.lang.String name)
Deprecated.- Specified by:
removeValue
in interfacejavax.servlet.http.HttpSession
- See Also:
HttpSession.removeValue(java.lang.String)
-
renewId
public void renewId(javax.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 interfacejavax.servlet.http.HttpSession
- See Also:
HttpSession.invalidate()
-
lock
public Locker.Lock 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.
-
doInvalidate
@Deprecated protected void doInvalidate() throws java.lang.IllegalStateException
Deprecated.Call HttpSessionAttributeListeners as part of invalidating a Session.- Throws:
java.lang.IllegalStateException
- if no session manager can be find
-
finishInvalidate
protected void finishInvalidate() throws java.lang.IllegalStateException
Call HttpSessionAttributeListeners as part of invalidating a Session.- Throws:
java.lang.IllegalStateException
- if no session manager can be find
-
isNew
public boolean isNew() throws java.lang.IllegalStateException
- Specified by:
isNew
in interfacejavax.servlet.http.HttpSession
- Throws:
java.lang.IllegalStateException
-
setIdChanged
public void setIdChanged(boolean changed)
-
isIdChanged
public boolean isIdChanged()
-
getSession
public Session getSession()
- Specified by:
getSession
in interfaceSessionHandler.SessionIf
-
getSessionData
protected SessionData getSessionData()
-
setResident
public void setResident(boolean resident)
-
isResident
public boolean isResident()
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
-