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. TheSessionHandlercoordinates the lifecycle of Session objects with the help of the SessionCache.- See Also:
- SessionHandler,- SessionIdManager
 
- 
- 
Nested Class SummaryNested Classes Modifier and Type Class Description static classSession.IdStateclassSession.SessionInactivityTimerSessionInactivityTimer 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 classSession.StateState Validity states of a session
 - 
Field SummaryFields Modifier and Type Field Description protected java.lang.String_extendedIdprotected SessionHandler_handlerprotected boolean_idChangedprotected Locker_lockprotected boolean_newSessionprotected long_requestsprotected boolean_residentprotected SessionData_sessionDataprotected Session.SessionInactivityTimer_sessionInactivityTimerprotected Session.State_stateprotected java.util.concurrent.locks.Condition_stateChangeCompletedstatic java.lang.StringSESSION_CREATED_SECURE
 - 
Constructor SummaryConstructors 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 SummaryAll Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description protected booleanaccess(long time)protected booleanbeginInvalidate()voidbindValue(java.lang.String name, java.lang.Object value)Bind value if value implementsHttpSessionBindingListener(callsHttpSessionBindingListener.valueBound(HttpSessionBindingEvent))longcalculateInactivityTimeout(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 voidcallSessionAttributeListeners(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 voidcheckLocked()protected voidcheckValidForRead()Chech that the session data can be read.protected voidcheckValidForWrite()Check that the session can be modified.protected voidcomplete()protected voidcookieSet()voiddidActivate()Call the activation listeners.protected voiddoInvalidate()Deprecated.protected voidfinishInvalidate()Call HttpSessionAttributeListeners as part of invalidating a Session.java.lang.ObjectgetAttribute(java.lang.String name)java.util.Enumeration<java.lang.String>getAttributeNames()intgetAttributes()java.lang.StringgetContextPath()longgetCookieSetTime()longgetCreationTime()java.lang.StringgetExtendedId()java.lang.StringgetId()longgetLastAccessedTime()intgetMaxInactiveInterval()java.util.Set<java.lang.String>getNames()longgetRequests()Returns the current number of requests that are active in the Session.javax.servlet.ServletContextgetServletContext()SessiongetSession()javax.servlet.http.HttpSessionContextgetSessionContext()Deprecated.protected SessionDatagetSessionData()SessionHandlergetSessionHandler()java.lang.ObjectgetValue(java.lang.String name)Deprecated.java.lang.String[]getValueNames()Deprecated.As of Version 2.2, this method is replaced bygetAttributeNames()java.lang.StringgetVHost()voidinvalidate()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 sessionbooleanisChanging()protected booleanisExpiredAt(long time)Check to see if session has expired as at the time given.booleanisIdChanged()protected booleanisIdleLongerThan(int sec)Check if the Session has been idle longer than a number of seconds.booleanisInvalid()booleanisNew()booleanisResident()booleanisValid()Locker.Locklock()Grab the lock on the sessionvoidputValue(java.lang.String name, java.lang.Object value)Deprecated.voidremoveAttribute(java.lang.String name)voidremoveValue(java.lang.String name)Deprecated.voidrenewId(javax.servlet.http.HttpServletRequest request)Force a change to the id of a session.voidsetAttribute(java.lang.String name, java.lang.Object value)voidsetExtendedId(java.lang.String extendedId)voidsetIdChanged(boolean changed)voidsetMaxInactiveInterval(int secs)voidsetResident(boolean resident)java.lang.StringtoString()voidunbindValue(java.lang.String name, java.lang.Object value)Unbind value if value implementsHttpSessionBindingListener(callsHttpSessionBindingListener.valueUnbound(HttpSessionBindingEvent))voidupdateInactivityTimer()Deprecated.protected voiduse()voidwillPassivate()Call the passivation listeners.
 
- 
- 
- 
Field Detail- 
SESSION_CREATED_SECUREpublic static final java.lang.String SESSION_CREATED_SECURE - See Also:
- Constant Field Values
 
 - 
_sessionDataprotected final SessionData _sessionData 
 - 
_handlerprotected final SessionHandler _handler 
 - 
_extendedIdprotected java.lang.String _extendedId 
 - 
_requestsprotected long _requests 
 - 
_idChangedprotected boolean _idChanged 
 - 
_newSessionprotected boolean _newSession 
 - 
_stateprotected Session.State _state 
 - 
_lockprotected Locker _lock 
 - 
_stateChangeCompletedprotected java.util.concurrent.locks.Condition _stateChangeCompleted 
 - 
_residentprotected boolean _resident 
 - 
_sessionInactivityTimerprotected final Session.SessionInactivityTimer _sessionInactivityTimer 
 
- 
 - 
Constructor Detail- 
Sessionpublic Session(SessionHandler handler, javax.servlet.http.HttpServletRequest request, SessionData data) Create a new session- Parameters:
- handler- the SessionHandler that manages this session
- request- the request the session should be based on
- data- the session data
 
 - 
Sessionpublic Session(SessionHandler handler, SessionData data) Re-inflate an existing session from some eg persistent store.- Parameters:
- handler- the SessionHandler managing the session
- data- the session data
 
 
- 
 - 
Method Detail- 
getRequestspublic long getRequests() Returns the current number of requests that are active in the Session.- Returns:
- the number of active requests for this session
 
 - 
setExtendedIdpublic void setExtendedId(java.lang.String extendedId) 
 - 
cookieSetprotected void cookieSet() 
 - 
useprotected void use() 
 - 
accessprotected boolean access(long time) 
 - 
completeprotected void complete() 
 - 
isExpiredAtprotected 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
 
 - 
isIdleLongerThanprotected 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
 
 - 
callSessionAttributeListenersprotected 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 attribute
- newValue- new value of the attribute
- oldValue- previous value of the attribute
- Throws:
- java.lang.IllegalStateException- if no session manager can be find
 
 - 
unbindValuepublic 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 unbound
- value- the bound value
 
 - 
bindValuepublic 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 unbound
- value- the bound value
 
 - 
didActivatepublic void didActivate() Call the activation listeners. This must be called holding the lock.
 - 
willPassivatepublic void willPassivate() Call the passivation listeners. This must be called holding the lock
 - 
isValidpublic boolean isValid() 
 - 
isInvalidpublic boolean isInvalid() 
 - 
isChangingpublic boolean isChanging() 
 - 
getCookieSetTimepublic long getCookieSetTime() 
 - 
getCreationTimepublic long getCreationTime() throws java.lang.IllegalStateException- Specified by:
- getCreationTimein interface- javax.servlet.http.HttpSession
- Throws:
- java.lang.IllegalStateException
 
 - 
getIdpublic java.lang.String getId() - Specified by:
- getIdin interface- javax.servlet.http.HttpSession
- See Also:
- HttpSession.getId()
 
 - 
getExtendedIdpublic java.lang.String getExtendedId() 
 - 
getContextPathpublic java.lang.String getContextPath() 
 - 
getVHostpublic java.lang.String getVHost() 
 - 
getLastAccessedTimepublic long getLastAccessedTime() - Specified by:
- getLastAccessedTimein interface- javax.servlet.http.HttpSession
- See Also:
- HttpSession.getLastAccessedTime()
 
 - 
getServletContextpublic javax.servlet.ServletContext getServletContext() - Specified by:
- getServletContextin interface- javax.servlet.http.HttpSession
- See Also:
- HttpSession.getServletContext()
 
 - 
setMaxInactiveIntervalpublic void setMaxInactiveInterval(int secs) - Specified by:
- setMaxInactiveIntervalin interface- javax.servlet.http.HttpSession
- See Also:
- HttpSession.setMaxInactiveInterval(int)
 
 - 
updateInactivityTimer@Deprecated public void updateInactivityTimer() Deprecated.
 - 
calculateInactivityTimeoutpublic 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
 
 - 
getMaxInactiveIntervalpublic int getMaxInactiveInterval() - Specified by:
- getMaxInactiveIntervalin interface- javax.servlet.http.HttpSession
- See Also:
- HttpSession.getMaxInactiveInterval()
 
 - 
getSessionContext@Deprecated public javax.servlet.http.HttpSessionContext getSessionContext() Deprecated.- Specified by:
- getSessionContextin interface- javax.servlet.http.HttpSession
- See Also:
- HttpSession.getSessionContext()
 
 - 
getSessionHandlerpublic SessionHandler getSessionHandler() 
 - 
checkValidForWriteprotected void checkValidForWrite() throws java.lang.IllegalStateExceptionCheck that the session can be modified.- Throws:
- java.lang.IllegalStateException- if the session is invalid
 
 - 
checkValidForReadprotected void checkValidForRead() throws java.lang.IllegalStateExceptionChech that the session data can be read.- Throws:
- java.lang.IllegalStateException- if the session is invalid
 
 - 
checkLockedprotected void checkLocked() throws java.lang.IllegalStateException- Throws:
- java.lang.IllegalStateException
 
 - 
getAttributepublic java.lang.Object getAttribute(java.lang.String name) - Specified by:
- getAttributein interface- javax.servlet.http.HttpSession
- See Also:
- HttpSession.getAttribute(java.lang.String)
 
 - 
getValue@Deprecated public java.lang.Object getValue(java.lang.String name) Deprecated.- Specified by:
- getValuein interface- javax.servlet.http.HttpSession
- See Also:
- HttpSession.getValue(java.lang.String)
 
 - 
getAttributeNamespublic java.util.Enumeration<java.lang.String> getAttributeNames() - Specified by:
- getAttributeNamesin interface- javax.servlet.http.HttpSession
- See Also:
- HttpSession.getAttributeNames()
 
 - 
getAttributespublic int getAttributes() 
 - 
getNamespublic java.util.Set<java.lang.String> getNames() 
 - 
getValueNames@Deprecated public java.lang.String[] getValueNames() throws java.lang.IllegalStateExceptionDeprecated.As of Version 2.2, this method is replaced bygetAttributeNames()- Specified by:
- getValueNamesin interface- javax.servlet.http.HttpSession
- Throws:
- java.lang.IllegalStateException
 
 - 
setAttributepublic void setAttribute(java.lang.String name, java.lang.Object value)- Specified by:
- setAttributein interface- javax.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:
- putValuein interface- javax.servlet.http.HttpSession
- See Also:
- HttpSession.putValue(java.lang.String, java.lang.Object)
 
 - 
removeAttributepublic void removeAttribute(java.lang.String name) - Specified by:
- removeAttributein interface- javax.servlet.http.HttpSession
- See Also:
- HttpSession.removeAttribute(java.lang.String)
 
 - 
removeValue@Deprecated public void removeValue(java.lang.String name) Deprecated.- Specified by:
- removeValuein interface- javax.servlet.http.HttpSession
- See Also:
- HttpSession.removeValue(java.lang.String)
 
 - 
renewIdpublic 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.
 
 - 
invalidatepublic 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 interface- javax.servlet.http.HttpSession
- See Also:
- HttpSession.invalidate()
 
 - 
lockpublic Locker.Lock lock() Grab the lock on the session- Returns:
- the lock
 
 - 
beginInvalidateprotected boolean beginInvalidate() - Returns:
- true if the session is not already invalid or being invalidated.
 
 - 
doInvalidate@Deprecated protected void doInvalidate() throws java.lang.IllegalStateExceptionDeprecated.Call HttpSessionAttributeListeners as part of invalidating a Session.- Throws:
- java.lang.IllegalStateException- if no session manager can be find
 
 - 
finishInvalidateprotected void finishInvalidate() throws java.lang.IllegalStateExceptionCall HttpSessionAttributeListeners as part of invalidating a Session.- Throws:
- java.lang.IllegalStateException- if no session manager can be find
 
 - 
isNewpublic boolean isNew() throws java.lang.IllegalStateException- Specified by:
- isNewin interface- javax.servlet.http.HttpSession
- Throws:
- java.lang.IllegalStateException
 
 - 
setIdChangedpublic void setIdChanged(boolean changed) 
 - 
isIdChangedpublic boolean isIdChanged() 
 - 
getSessionpublic Session getSession() - Specified by:
- getSessionin interface- SessionHandler.SessionIf
 
 - 
getSessionDataprotected SessionData getSessionData() 
 - 
setResidentpublic void setResident(boolean resident) 
 - 
isResidentpublic boolean isResident() 
 - 
toStringpublic java.lang.String toString() - Overrides:
- toStringin class- java.lang.Object
 
 
- 
 
-