public class Session extends java.lang.Object implements SessionHandler.SessionIf
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.SessionHandler
,
SessionIdManager
Modifier and Type | Class and 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
|
Modifier and Type | Field and 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 and Description |
---|
Session(SessionHandler handler,
javax.servlet.http.HttpServletRequest request,
SessionData data)
Create a new session
|
Session(SessionHandler handler,
SessionData data)
Re-inflate an existing session from some eg persistent store.
|
Modifier and Type | Method and Description |
---|---|
protected boolean |
access(long time) |
protected boolean |
beginInvalidate() |
void |
bindValue(java.lang.String name,
java.lang.Object value)
Bind value if value implements
HttpSessionBindingListener (calls
HttpSessionBindingListener.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 by
getAttributeNames() |
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 session
|
boolean |
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 |
isNew() |
boolean |
isResident() |
boolean |
isValid() |
Locker.Lock |
lock()
Grab the lock on the session
|
void |
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 implements
HttpSessionBindingListener
(calls
HttpSessionBindingListener.valueUnbound(HttpSessionBindingEvent) ) |
void |
updateInactivityTimer()
Deprecated.
|
void |
willPassivate()
Call the passivation listeners.
|
public static final java.lang.String SESSION_CREATED_SECURE
protected final SessionData _sessionData
protected final SessionHandler _handler
protected java.lang.String _extendedId
protected long _requests
protected boolean _idChanged
protected boolean _newSession
protected Session.State _state
protected Locker _lock
protected java.util.concurrent.locks.Condition _stateChangeCompleted
protected boolean _resident
protected final Session.SessionInactivityTimer _sessionInactivityTimer
public Session(SessionHandler handler, javax.servlet.http.HttpServletRequest request, SessionData data)
handler
- the SessionHandler that manages this sessionrequest
- the request the session should be based ondata
- the session datapublic Session(SessionHandler handler, SessionData data)
handler
- the SessionHandler managing the sessiondata
- the session datapublic long getRequests()
public void setExtendedId(java.lang.String extendedId)
protected void cookieSet()
protected boolean access(long time)
protected void complete()
protected boolean isExpiredAt(long time)
time
- the time since the epoch in msprotected boolean isIdleLongerThan(int sec)
sec
- the number of secondsprotected void callSessionAttributeListeners(java.lang.String name, java.lang.Object newValue, java.lang.Object oldValue)
name
- name of the attributenewValue
- new value of the attributeoldValue
- previous value of the attributejava.lang.IllegalStateException
- if no session manager can be findpublic void unbindValue(java.lang.String name, java.lang.Object value)
HttpSessionBindingListener
(calls
HttpSessionBindingListener.valueUnbound(HttpSessionBindingEvent)
)name
- the name with which the object is bound or unboundvalue
- the bound valuepublic void bindValue(java.lang.String name, java.lang.Object value)
HttpSessionBindingListener
(calls
HttpSessionBindingListener.valueBound(HttpSessionBindingEvent)
)name
- the name with which the object is bound or unboundvalue
- the bound valuepublic void didActivate()
public void willPassivate()
public boolean isValid()
public boolean isChanging()
public long getCookieSetTime()
public long getCreationTime() throws java.lang.IllegalStateException
getCreationTime
in interface javax.servlet.http.HttpSession
java.lang.IllegalStateException
public java.lang.String getId()
getId
in interface javax.servlet.http.HttpSession
HttpSession.getId()
public java.lang.String getExtendedId()
public java.lang.String getContextPath()
public java.lang.String getVHost()
public long getLastAccessedTime()
getLastAccessedTime
in interface javax.servlet.http.HttpSession
HttpSession.getLastAccessedTime()
public javax.servlet.ServletContext getServletContext()
getServletContext
in interface javax.servlet.http.HttpSession
HttpSession.getServletContext()
public void setMaxInactiveInterval(int secs)
setMaxInactiveInterval
in interface javax.servlet.http.HttpSession
HttpSession.setMaxInactiveInterval(int)
@Deprecated public void updateInactivityTimer()
public long calculateInactivityTimeout(long now)
now
- the time at which to calculate remaining expirypublic int getMaxInactiveInterval()
getMaxInactiveInterval
in interface javax.servlet.http.HttpSession
HttpSession.getMaxInactiveInterval()
@Deprecated public javax.servlet.http.HttpSessionContext getSessionContext()
getSessionContext
in interface javax.servlet.http.HttpSession
HttpSession.getSessionContext()
public SessionHandler getSessionHandler()
protected void checkValidForWrite() throws java.lang.IllegalStateException
java.lang.IllegalStateException
- if the session is invalidprotected void checkValidForRead() throws java.lang.IllegalStateException
java.lang.IllegalStateException
- if the session is invalidprotected void checkLocked() throws java.lang.IllegalStateException
java.lang.IllegalStateException
public java.lang.Object getAttribute(java.lang.String name)
getAttribute
in interface javax.servlet.http.HttpSession
HttpSession.getAttribute(java.lang.String)
@Deprecated public java.lang.Object getValue(java.lang.String name)
getValue
in interface javax.servlet.http.HttpSession
HttpSession.getValue(java.lang.String)
public java.util.Enumeration<java.lang.String> getAttributeNames()
getAttributeNames
in interface javax.servlet.http.HttpSession
HttpSession.getAttributeNames()
public int getAttributes()
public java.util.Set<java.lang.String> getNames()
@Deprecated public java.lang.String[] getValueNames() throws java.lang.IllegalStateException
getAttributeNames()
getValueNames
in interface javax.servlet.http.HttpSession
java.lang.IllegalStateException
public void setAttribute(java.lang.String name, java.lang.Object value)
setAttribute
in interface javax.servlet.http.HttpSession
HttpSession.setAttribute(java.lang.String,
java.lang.Object)
@Deprecated public void putValue(java.lang.String name, java.lang.Object value)
putValue
in interface javax.servlet.http.HttpSession
HttpSession.putValue(java.lang.String,
java.lang.Object)
public void removeAttribute(java.lang.String name)
removeAttribute
in interface javax.servlet.http.HttpSession
HttpSession.removeAttribute(java.lang.String)
@Deprecated public void removeValue(java.lang.String name)
removeValue
in interface javax.servlet.http.HttpSession
HttpSession.removeValue(java.lang.String)
public void renewId(javax.servlet.http.HttpServletRequest request)
request
- the Request associated with the call to change id.public void invalidate()
invalidate
in interface javax.servlet.http.HttpSession
HttpSession.invalidate()
public Locker.Lock lock()
protected boolean beginInvalidate()
@Deprecated protected void doInvalidate() throws java.lang.IllegalStateException
java.lang.IllegalStateException
- if no session manager can be findprotected void finishInvalidate() throws java.lang.IllegalStateException
java.lang.IllegalStateException
- if no session manager can be findpublic boolean isNew() throws java.lang.IllegalStateException
isNew
in interface javax.servlet.http.HttpSession
java.lang.IllegalStateException
public void setIdChanged(boolean changed)
public boolean isIdChanged()
public Session getSession()
getSession
in interface SessionHandler.SessionIf
protected SessionData getSessionData()
public void setResident(boolean resident)
resident
- public boolean isResident()
public java.lang.String toString()
toString
in class java.lang.Object
Copyright © 1995–2023 Webtide. All rights reserved.