Package org.eclipse.jetty.server.session
Class Session
- java.lang.Object
-
- org.eclipse.jetty.server.session.Session
-
- All Implemented Interfaces:
HttpSession,SessionHandler.SessionIf
- Direct Known Subclasses:
AbstractSessionCache.PlaceHolderSession
public class Session extends Object implements SessionHandler.SessionIf
Session A heavy-weight Session object representing a 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 Summary
Nested Classes Modifier and Type Class Description classSession.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 Summary
Fields Modifier and Type Field Description protected String_extendedIdprotected SessionHandler_handlerprotected boolean_idChangedprotected org.eclipse.jetty.util.thread.Locker_lockprotected boolean_newSessionprotected long_requestsprotected boolean_residentprotected SessionData_sessionDataprotected Session.SessionInactivityTimer_sessionInactivityTimerprotected Session.State_statestatic StringSESSION_CREATED_SECURE
-
Constructor Summary
Constructors Constructor Description Session(SessionHandler handler, 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 booleanaccess(long time)protected booleanbeginInvalidate()voidbindValue(String name, Object value)Bind value if value implementsHttpSessionBindingListener(callsHttpSessionBindingListener.valueBound(HttpSessionBindingEvent))protected voidcallSessionAttributeListeners(String name, Object newValue, 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.ObjectgetAttribute(String name)Enumeration<String>getAttributeNames()intgetAttributes()StringgetContextPath()longgetCookieSetTime()longgetCreationTime()StringgetExtendedId()StringgetId()longgetLastAccessedTime()intgetMaxInactiveInterval()Set<String>getNames()longgetRequests()Returns the current number of requests that are active in the Session.ServletContextgetServletContext()SessiongetSession()HttpSessionContextgetSessionContext()Deprecated.protected SessionDatagetSessionData()SessionHandlergetSessionHandler()ObjectgetValue(String name)Deprecated.String[]getValueNames()Deprecated.As of Version 2.2, this method is replaced bygetAttributeNames()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 sessionprotected 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.booleanisNew()booleanisResident()booleanisValid()org.eclipse.jetty.util.thread.Locker.Locklock()Grab the lock on the sessionorg.eclipse.jetty.util.thread.Locker.LocklockIfNotHeld()Grab the lock on the session if it isn't locked alreadyvoidputValue(String name, Object value)Deprecated.voidremoveAttribute(String name)voidremoveValue(String name)Deprecated.voidrenewId(HttpServletRequest request)Force a change to the id of a session.voidsetAttribute(String name, Object value)voidsetExtendedId(String extendedId)voidsetIdChanged(boolean changed)voidsetMaxInactiveInterval(int secs)voidsetResident(boolean resident)voidunbindValue(String name, Object value)Unbind value if value implementsHttpSessionBindingListener(callsHttpSessionBindingListener.valueUnbound(HttpSessionBindingEvent))voidupdateInactivityTimer()Set the inactivity timer to the smaller of the session maxInactivity (ie session-timeout from web.xml), or the inactive eviction time.voidwillPassivate()Call the passivation listeners.
-
-
-
Field Detail
-
SESSION_CREATED_SECURE
public static final String SESSION_CREATED_SECURE
- See Also:
- Constant Field Values
-
_sessionData
protected final SessionData _sessionData
-
_handler
protected final SessionHandler _handler
-
_extendedId
protected String _extendedId
-
_requests
protected long _requests
-
_idChanged
protected boolean _idChanged
-
_newSession
protected boolean _newSession
-
_state
protected Session.State _state
-
_lock
protected org.eclipse.jetty.util.thread.Locker _lock
-
_resident
protected boolean _resident
-
_sessionInactivityTimer
protected final Session.SessionInactivityTimer _sessionInactivityTimer
-
-
Constructor Detail
-
Session
public Session(SessionHandler handler, 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(String extendedId)
-
cookieSet
protected void cookieSet()
-
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(String name, Object newValue, 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:
IllegalStateException- if no session manager can be find
-
unbindValue
public void unbindValue(String name, 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(String name, 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()
-
getCookieSetTime
public long getCookieSetTime()
-
getCreationTime
public long getCreationTime() throws IllegalStateException- Specified by:
getCreationTimein interfaceHttpSession- Throws:
IllegalStateException
-
getId
public String getId()
- Specified by:
getIdin interfaceHttpSession- See Also:
HttpSession.getId()
-
getExtendedId
public String getExtendedId()
-
getContextPath
public String getContextPath()
-
getVHost
public String getVHost()
-
getLastAccessedTime
public long getLastAccessedTime()
- Specified by:
getLastAccessedTimein interfaceHttpSession- See Also:
HttpSession.getLastAccessedTime()
-
getServletContext
public ServletContext getServletContext()
- Specified by:
getServletContextin interfaceHttpSession- See Also:
HttpSession.getServletContext()
-
setMaxInactiveInterval
public void setMaxInactiveInterval(int secs)
- Specified by:
setMaxInactiveIntervalin interfaceHttpSession- See Also:
HttpSession.setMaxInactiveInterval(int)
-
updateInactivityTimer
public void updateInactivityTimer()
Set the inactivity timer to the smaller of the session maxInactivity (ie session-timeout from web.xml), or the inactive eviction time.
-
getMaxInactiveInterval
public int getMaxInactiveInterval()
- Specified by:
getMaxInactiveIntervalin interfaceHttpSession- See Also:
HttpSession.getMaxInactiveInterval()
-
getSessionContext
@Deprecated public HttpSessionContext getSessionContext()
Deprecated.- Specified by:
getSessionContextin interfaceHttpSession- See Also:
HttpSession.getSessionContext()
-
getSessionHandler
public SessionHandler getSessionHandler()
-
checkValidForWrite
protected void checkValidForWrite() throws IllegalStateExceptionCheck that the session can be modified.- Throws:
IllegalStateException- if the session is invalid
-
checkValidForRead
protected void checkValidForRead() throws IllegalStateExceptionChech that the session data can be read.- Throws:
IllegalStateException- if the session is invalid
-
checkLocked
protected void checkLocked() throws IllegalStateException- Throws:
IllegalStateException
-
getAttribute
public Object getAttribute(String name)
- Specified by:
getAttributein interfaceHttpSession- See Also:
HttpSession.getAttribute(java.lang.String)
-
getValue
@Deprecated public Object getValue(String name)
Deprecated.- Specified by:
getValuein interfaceHttpSession- See Also:
HttpSession.getValue(java.lang.String)
-
getAttributeNames
public Enumeration<String> getAttributeNames()
- Specified by:
getAttributeNamesin interfaceHttpSession- See Also:
HttpSession.getAttributeNames()
-
getAttributes
public int getAttributes()
-
getValueNames
@Deprecated public String[] getValueNames() throws IllegalStateException
Deprecated.As of Version 2.2, this method is replaced bygetAttributeNames()- Specified by:
getValueNamesin interfaceHttpSession- Throws:
IllegalStateException
-
setAttribute
public void setAttribute(String name, Object value)
- Specified by:
setAttributein interfaceHttpSession- See Also:
HttpSession.setAttribute(java.lang.String, java.lang.Object)
-
putValue
@Deprecated public void putValue(String name, Object value)
Deprecated.- Specified by:
putValuein interfaceHttpSession- See Also:
HttpSession.putValue(java.lang.String, java.lang.Object)
-
removeAttribute
public void removeAttribute(String name)
- Specified by:
removeAttributein interfaceHttpSession- See Also:
HttpSession.removeAttribute(java.lang.String)
-
removeValue
@Deprecated public void removeValue(String name)
Deprecated.- Specified by:
removeValuein interfaceHttpSession- See Also:
HttpSession.removeValue(java.lang.String)
-
renewId
public void renewId(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:
invalidatein interfaceHttpSession- See Also:
HttpSession.invalidate()
-
lock
public org.eclipse.jetty.util.thread.Locker.Lock lock()
Grab the lock on the session- Returns:
- the lock
-
lockIfNotHeld
public org.eclipse.jetty.util.thread.Locker.Lock lockIfNotHeld()
Grab the lock on the session if it isn't locked already- 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 IllegalStateException
Deprecated.Call HttpSessionAttributeListeners as part of invalidating a Session.- Throws:
IllegalStateException- if no session manager can be find
-
finishInvalidate
protected void finishInvalidate() throws IllegalStateExceptionCall HttpSessionAttributeListeners as part of invalidating a Session.- Throws:
IllegalStateException- if no session manager can be find
-
isNew
public boolean isNew() throws IllegalStateException- Specified by:
isNewin interfaceHttpSession- Throws:
IllegalStateException
-
setIdChanged
public void setIdChanged(boolean changed)
-
isIdChanged
public boolean isIdChanged()
-
getSession
public Session getSession()
- Specified by:
getSessionin interfaceSessionHandler.SessionIf
-
getSessionData
protected SessionData getSessionData()
-
setResident
public void setResident(boolean resident)
-
isResident
public boolean isResident()
-
-