public class StandardSession extends Object implements javax.servlet.http.HttpSession, Session, Serializable
IMPLEMENTATION NOTE: An instance of this class represents both the
internal (Session) and application level (HttpSession) view of the session.
However, because the class itself is not declared public, Java logic outside
of the org.apache.catalina.session package cannot cast an
HttpSession view of this instance back to a Session view.
IMPLEMENTATION NOTE: If you add fields to this class, you must make sure that you carry them over in the read/writeObject methods so that this class is properly serialized.
| Modifier and Type | Field and Description |
|---|---|
protected SessionLock |
_sessionLock |
protected Map<String,Object> |
attributes
The collection of user data attributes associated with this Session.
|
protected String |
authType
The authentication type used to authenticate our cached Principal,
if any.
|
protected Method |
containerEventMethod
The
java.lang.Method for the
fireContainerEvent() method of the
org.apache.catalina.core.StandardContext method,
if our Context implementation is of this class. |
protected StandardContext |
context
The context with which this Session is associated.
|
protected long |
creationTime
The time this session was created, in milliseconds since midnight,
January 1, 1970 GMT.
|
protected int |
debug
The debugging detail level for this component.
|
protected static String[] |
EMPTY_ARRAY
Type array.
|
protected boolean |
expiring
We are currently processing a session expiration, so bypass
certain IllegalStateException tests.
|
protected StandardSessionFacade |
facade
The facade associated with this session.
|
protected String |
id
The session identifier of this Session.
|
protected static String |
info
Descriptive information describing this Session implementation.
|
protected boolean |
isNew
Flag indicating whether this session is new or not.
|
protected boolean |
isValid
Flag indicating whether this session is valid or not.
|
protected long |
lastAccessedTime
The last accessed time for this Session.
|
protected ArrayList<SessionListener> |
listeners
The session event listeners for this Session.
|
protected Manager |
manager
The Manager with which this Session is associated.
|
protected int |
maxInactiveInterval
The maximum time interval, in seconds, between client requests before
the servlet container may invalidate this session.
|
protected static String |
NOT_SERIALIZED
The dummy attribute value serialized when a NotSerializableException is
encountered in
writeObject(). |
protected Map<String,Object> |
notes
Internal notes associated with this session by Catalina components
and event listeners.
|
protected Principal |
principal
The authenticated Principal associated with this session, if any.
|
protected static String |
SEPARATE_BUFFER_SERIALIZATION |
protected static javax.servlet.http.HttpSessionContext |
sessionContext
The HTTP session context associated with this session.
|
protected Object |
sessionLockMonitor |
protected String |
ssoId
single sign on id.
|
protected long |
ssoVersion
single sign on version.
|
protected static String |
SYNC_STRING
The string used in the name for setAttribute and removeAttribute
to signify on-demand sync
|
protected long |
thisAccessedTime
The current accessed time for this session.
|
protected static ThreadLocal<Manager> |
threadContextManager |
protected AtomicLong |
version
The session version, incremented and used by in-memory-replicating
session managers
|
SESSION_CREATED_EVENT, SESSION_DESTROYED_EVENT| Constructor and Description |
|---|
StandardSession(Manager manager)
Construct a new Session associated with the specified Manager.
|
| Modifier and Type | Method and Description |
|---|---|
void |
access()
Update the accessed time information for this session.
|
void |
activate()
Perform internal processing required to activate this
session.
|
void |
addSessionListener(SessionListener listener)
Add a session event listener to this component.
|
void |
endAccess()
End the access.
|
protected void |
evaluateIfValid() |
protected boolean |
exclude(String name)
Exclude attribute that cannot be serialized.
|
void |
expire()
Perform the internal processing required to invalidate this session,
without triggering an exception if the session has already expired.
|
void |
expire(boolean notify)
Perform the internal processing required to invalidate this session,
without triggering an exception if the session has already expired.
|
void |
expire(boolean notify,
boolean persistentRemove)
Perform the internal processing required to invalidate this session,
without triggering an exception if the session has already expired.
|
protected void |
fireContainerEvent(Context context,
String type,
Object data)
Fire container events if the Context implementation is the
org.apache.catalina.core.StandardContext. |
void |
fireSessionEvent(String type,
Object data)
Notify all session event listeners that a particular event has
occurred for this Session.
|
Object |
getAttribute(String name)
Return the object bound with the specified name in this session, or
null if no object is bound with that name. |
protected Object |
getAttributeInternal(String name)
Return the value of an attribute without a check for validity.
|
Enumeration<String> |
getAttributeNames()
Return an
Enumeration of String objects
containing the names of the objects bound to this session. |
Map<String,Object> |
getAttributes()
Gets the attributes of this session.
|
String |
getAuthType()
Return the authentication type used to authenticate our cached
Principal, if any.
|
String |
getBeKey()
Gets the BEKEY of this session
|
long |
getCreationTime()
Return the time when this session was created, in milliseconds since
midnight, January 1, 1970 GMT.
|
String |
getId()
Return the session identifier for this session.
|
String |
getIdInternal()
Return the session identifier for this session.
|
String |
getInfo()
Return descriptive information about this Session implementation and
the corresponding version number, in the format
<description>/<version>. |
boolean |
getIsValid()
Return the
isValid flag for this session. |
long |
getLastAccessedTime()
Return the last time the client sent a request associated with this
session, as the number of milliseconds since midnight, January 1, 1970
GMT.
|
long |
getLastAccessedTimeInternal()
Same as getLastAccessedTime(), except that there is no call to
isValid(), which may expire the session and cause any subsequent
session access to throw an IllegalStateException.
|
Manager |
getManager()
Return the Manager within which this Session is valid.
|
int |
getMaxInactiveInterval()
Return the maximum time interval, in seconds, between client requests
before the servlet container will invalidate the session.
|
Object |
getNote(String name)
Return the object bound with the specified name to the internal notes
for this session, or
null if no such binding exists. |
Iterator<String> |
getNoteNames()
Return an Iterator containing the String names of all notes bindings
that exist for this session.
|
Principal |
getPrincipal()
Return the authenticated Principal that is associated with this Session.
|
javax.servlet.ServletContext |
getServletContext()
Return the ServletContext to which this session belongs.
|
javax.servlet.http.HttpSession |
getSession()
Return the
HttpSession for which this object
is the facade. |
javax.servlet.http.HttpSessionContext |
getSessionContext()
Deprecated.
As of Version 2.1, this method is deprecated and has no
replacement. It will be removed in a future version of the
Java Servlet API.
|
SessionLock |
getSessionLock()
return the Session lock
|
protected boolean |
getSessionLockForForeground()
get this session locked for foreground
if the session is found to be presently background
locked; retry logic in a time-decay polling loop
waits for background lock to clear
after 6 attempts (12.6 seconds) it unlocks the
session and acquires the foreground lock
|
String |
getSipApplicationSessionId()
Gets the id of the SipApplicationSession that is the parent of this
StandardSession.
|
String |
getSsoId()
Return the single sign on id.
|
long |
getSsoVersion()
Return the single sign on version.
|
Object |
getValue(String name)
Deprecated.
As of Version 2.2, this method is replaced by
getAttribute() |
String[] |
getValueNames()
Deprecated.
As of Version 2.2, this method is replaced by
getAttributeNames() |
long |
getVersion()
Gets the version number
|
boolean |
hasExpired()
Checks whether this Session has expired.
|
boolean |
hasNonHttpLockOccurred() |
long |
incrementVersion()
Increments the version number
|
void |
invalidate()
Invalidates this session and unbinds any objects bound to it.
|
boolean |
isForegroundLocked()
return whether this session is currently foreground locked
|
boolean |
isNew()
Return
true if the client does not yet know about the
session, or if the client chooses not to join the session. |
boolean |
isValid()
Return the
isValid flag for this session. |
protected String[] |
keys()
Return the names of all currently defined session attributes
as an array of Strings.
|
boolean |
lockBackground()
lock the session for foreground
returns true if successful; false if unsuccessful
|
boolean |
lockForeground()
lock the session for background
returns true if successful; false if unsuccessful
|
protected void |
log(String message)
Log a message on the Logger associated with our Manager (if any).
|
protected void |
log(String message,
Level level)
Log a message on the Logger associated with our Manager (if any).
|
protected void |
log(String message,
Throwable t)
Log a message on the Logger associated with our Manager (if any).
|
void |
passivate()
Perform the internal processing required to passivate
this session.
|
void |
putValue(String name,
Object value)
Deprecated.
As of Version 2.2, this method is replaced by
setAttribute() |
void |
recycle()
Release all object references, and initialize instance variables, in
preparation for reuse of this object.
|
void |
removeAttribute(String name)
Remove the object bound with the specified name from this session.
|
void |
removeAttribute(String name,
boolean notify,
boolean checkValid)
Remove the object bound with the specified name from this session.
|
void |
removeNote(String name)
Remove any object bound to the specified name in the internal notes
for this session.
|
void |
removeSessionListener(SessionListener listener)
Remove a session event listener from this component.
|
void |
removeValue(String name)
Deprecated.
As of Version 2.2, this method is replaced by
removeAttribute() |
void |
setAttribute(String name,
Object value)
Bind an object to this session, using the specified name.
|
void |
setAuthType(String authType)
Set the authentication type used to authenticate our cached
Principal, if any.
|
void |
setBeKey(String beKey)
Sets the BEKEY for this session
|
void |
setCreationTime(long time)
Set the creation time for this session.
|
void |
setId(String id)
Set the session identifier for this session.
|
void |
setLastAccessedTime(long lastAcessedTime)
Set the last time the client sent a request associated with this
session, as the number of milliseconds since midnight, January 1, 1970
GMT.
|
void |
setManager(Manager manager)
Set the Manager within which this Session is valid.
|
void |
setMaxInactiveInterval(int interval)
Set the maximum time interval, in seconds, between client requests
before the servlet container will invalidate the session.
|
void |
setNew(boolean isNew)
Set the
isNew flag for this session. |
void |
setNote(String name,
Object value)
Bind an object to a specified name in the internal notes associated
with this session, replacing any existing binding for this name.
|
void |
setPrincipal(Principal principal)
Set the authenticated Principal that is associated with this Session.
|
void |
setSessionLock(SessionLock sessionLock)
set the Session lock
|
void |
setSipApplicationSessionId(String id)
Sets the id of the SipApplicationSession that is the parent of this
StandardSession.
|
void |
setSsoId(String ssoId)
Set the single sign on id.
|
void |
setSsoVersion(long value)
Set the single sign on version.
|
void |
setValid(boolean isValid)
Set the
isValid flag for this session. |
void |
setVersion(long value)
Sets the version number
|
void |
tellNew()
Inform the listeners about the new session.
|
String |
toString()
Return a string representation of this object.
|
void |
unlockBackground()
unlock the session from background
|
void |
unlockForeground()
unlock the session from foreground
|
void |
unlockForegroundCompletely()
unlock the session completely
irregardless of whether it was foreground or background locked
|
protected static final String[] EMPTY_ARRAY
protected static final String NOT_SERIALIZED
writeObject().protected static final String SEPARATE_BUFFER_SERIALIZATION
protected static final String SYNC_STRING
protected static final String info
protected static volatile javax.servlet.http.HttpSessionContext sessionContext
protected Map<String,Object> attributes
protected transient String authType
protected transient Method containerEventMethod
java.lang.Method for the
fireContainerEvent() method of the
org.apache.catalina.core.StandardContext method,
if our Context implementation is of this class. This value is
computed dynamically the first time it is needed, or after
a session reload (since it is declared transient).protected long creationTime
protected transient int debug
protected transient boolean expiring
protected transient StandardSessionFacade facade
protected String id
protected long lastAccessedTime
protected transient ArrayList<SessionListener> listeners
protected transient Manager manager
protected static final transient ThreadLocal<Manager> threadContextManager
protected transient StandardContext context
protected int maxInactiveInterval
protected boolean isNew
protected boolean isValid
protected transient Map<String,Object> notes
protected transient Principal principal
protected long thisAccessedTime
protected AtomicLong version
protected String ssoId
protected volatile long ssoVersion
protected transient SessionLock _sessionLock
protected final Object sessionLockMonitor
public StandardSession(Manager manager)
manager - The manager with which this Session is associatedpublic String getAuthType()
getAuthType in interface Sessionpublic void setAuthType(String authType)
setAuthType in interface SessionauthType - The new cached authentication typepublic void setCreationTime(long time)
setCreationTime in interface Sessiontime - The new creation timepublic String getId()
public String getIdInternal()
getIdInternal in interface Sessionpublic void setId(String id)
public void setBeKey(String beKey)
The BEKEY is used by the Converged Loadbalancer (CLB) in DCR mode for loadbalancing purposes, and supplied to the web container in the form of a request header.
beKey - the BEKEY for this session, or null if not
presentpublic String getBeKey()
public void setSipApplicationSessionId(String id)
id - SipApplicationSession idpublic String getSipApplicationSessionId()
public void tellNew()
public String getInfo()
<description>/<version>.public long getLastAccessedTime()
getLastAccessedTime in interface javax.servlet.http.HttpSessiongetLastAccessedTime in interface Sessionpublic long getLastAccessedTimeInternal()
public void setLastAccessedTime(long lastAcessedTime)
public Manager getManager()
getManager in interface Sessionpublic void setManager(Manager manager)
setManager in interface Sessionmanager - The new Managerpublic int getMaxInactiveInterval()
getMaxInactiveInterval in interface javax.servlet.http.HttpSessiongetMaxInactiveInterval in interface Sessionpublic void setMaxInactiveInterval(int interval)
setMaxInactiveInterval in interface javax.servlet.http.HttpSessionsetMaxInactiveInterval in interface Sessioninterval - The new maximum intervalpublic void setNew(boolean isNew)
isNew flag for this session.public Principal getPrincipal()
Authenticator with a means to cache a
previously authenticated Principal, and avoid potentially expensive
Realm.authenticate() calls on every request. If there
is no current associated Principal, return null.getPrincipal in interface Sessionpublic void setPrincipal(Principal principal)
Authenticator with a means to cache a
previously authenticated Principal, and avoid potentially expensive
Realm.authenticate() calls on every request.setPrincipal in interface Sessionprincipal - The new Principal, or null if nonepublic javax.servlet.http.HttpSession getSession()
HttpSession for which this object
is the facade.getSession in interface Sessionpublic boolean isValid()
isValid flag for this session.public boolean getIsValid()
SessionisValid flag for this session.getIsValid in interface Sessionpublic void setValid(boolean isValid)
isValid flag for this session.public void access()
public void addSessionListener(SessionListener listener)
addSessionListener in interface Sessionpublic void expire()
public void expire(boolean notify)
notify - Should we notify listeners about the demise of
this session?public void expire(boolean notify,
boolean persistentRemove)
notify - Should we notify listeners about the demise of
this session?persistentRemove - should we call store to remove the session
if availablepublic void passivate()
public void activate()
public Object getNote(String name)
null if no such binding exists.public Iterator<String> getNoteNames()
getNoteNames in interface Sessionpublic void recycle()
public void removeNote(String name)
removeNote in interface Sessionname - Name of the note to be removedpublic void removeSessionListener(SessionListener listener)
removeSessionListener in interface Sessionpublic void setNote(String name, Object value)
public boolean hasExpired()
hasExpired in interface Sessionpublic long incrementVersion()
public long getVersion()
getVersion in interface Sessionpublic void setVersion(long value)
public String getSsoId()
public void setSsoId(String ssoId)
public long getSsoVersion()
getSsoVersion in interface Sessionpublic void setSsoVersion(long value)
setSsoVersion in interface Sessionpublic String toString()
public long getCreationTime()
getCreationTime in interface javax.servlet.http.HttpSessiongetCreationTime in interface SessionIllegalStateException - if this method is called on an
invalidated sessionpublic javax.servlet.ServletContext getServletContext()
public javax.servlet.http.HttpSessionContext getSessionContext()
getSessionContext in interface javax.servlet.http.HttpSessionpublic Object getAttribute(String name)
null if no object is bound with that name.name - Name of the attribute to be returned
* @exception IllegalStateException if this method is called on an
invalidated sessionpublic Map<String,Object> getAttributes()
SessiongetAttributes in interface Sessionpublic Enumeration<String> getAttributeNames()
Enumeration of String objects
containing the names of the objects bound to this session.IllegalStateException - if this method is called on an
invalidated sessionpublic Object getValue(String name)
getAttribute()null if no object is bound with that name.getValue in interface javax.servlet.http.HttpSessionname - Name of the value to be returnedIllegalStateException - if this method is called on an
invalidated sessionpublic String[] getValueNames()
getAttributeNames()getValueNames in interface javax.servlet.http.HttpSessionIllegalStateException - if this method is called on an
invalidated sessionprotected boolean getSessionLockForForeground()
public boolean isForegroundLocked()
public boolean lockBackground()
public boolean lockForeground()
lockForeground in interface Sessionpublic void unlockForegroundCompletely()
public void unlockForeground()
unlockForeground in interface Sessionpublic void unlockBackground()
public SessionLock getSessionLock()
public void setSessionLock(SessionLock sessionLock)
sessionLock - public boolean hasNonHttpLockOccurred()
public void invalidate()
invalidate in interface javax.servlet.http.HttpSessionIllegalStateException - if this method is called on
an invalidated session
HERCULES:modified methodpublic boolean isNew()
true if the client does not yet know about the
session, or if the client chooses not to join the session. For
example, if the server used only cookie-based sessions, and the client
has disabled the use of cookies, then a session would be new on each
request.isNew in interface javax.servlet.http.HttpSessionIllegalStateException - if this method is called on an
invalidated sessionpublic void putValue(String name, Object value)
setAttribute()
After this method executes, and if the object implements
HttpSessionBindingListener, the container calls
valueBound() on the object.
putValue in interface javax.servlet.http.HttpSessionname - Name to which the object is bound, cannot be nullvalue - Object to be bound, cannot be nullIllegalStateException - if this method is called on an
invalidated sessionpublic void removeAttribute(String name)
After this method executes, and if the object implements
HttpSessionBindingListener, the container calls
valueUnbound() on the object.
name - Name of the object to remove from this session.IllegalStateException - if this method is called on an
invalidated sessionpublic void removeAttribute(String name, boolean notify, boolean checkValid)
After this method executes, and if the object implements
HttpSessionBindingListener, the container calls
valueUnbound() on the object.
name - Name of the object to remove from this session.notify - Should we notify interested listeners that this
attribute is being removed?checkValid - Indicates whether IllegalStateException must be
thrown if session has already been invalidatedIllegalStateException - if this method is called on an
invalidated sessionpublic void removeValue(String name)
removeAttribute()
After this method executes, and if the object implements
HttpSessionBindingListener, the container calls
valueUnbound() on the object.
removeValue in interface javax.servlet.http.HttpSessionname - Name of the object to remove from this session.IllegalStateException - if this method is called on an
invalidated sessionpublic void setAttribute(String name, Object value)
After this method executes, and if the object implements
HttpSessionBindingListener, the container calls
valueBound() on the object.
name - Name to which the object is bound, cannot be nullvalue - Object to be bound, cannot be nullIllegalArgumentException - if an attempt is made to add a
non-serializable object in an environment marked distributable.IllegalStateException - if this method is called on an
invalidated sessionprotected boolean exclude(String name)
name - the attribute's nameprotected void evaluateIfValid()
protected void fireContainerEvent(Context context, String type, Object data) throws Exception
org.apache.catalina.core.StandardContext.context - Context for which to fire eventstype - Event typedata - Event dataException - occurred during event firingpublic void fireSessionEvent(String type, Object data)
type - Event typedata - Event dataprotected String[] keys()
protected Object getAttributeInternal(String name)
protected void log(String message)
message - Message to be loggedprotected void log(String message, Throwable t)
message - Message to be loggedt - Associated exceptionCopyright © 2017. All rights reserved.