org.apache.catalina.cluster.session
Class DeltaSession

java.lang.Object
  extended byorg.apache.catalina.cluster.session.DeltaSession
All Implemented Interfaces:
ClusterSession, javax.servlet.http.HttpSession, java.io.Serializable, Session

public class DeltaSession
extends java.lang.Object
implements javax.servlet.http.HttpSession, Session, java.io.Serializable, ClusterSession

Similar to the StandardSession, this code is identical, but for update and some small issues, simply copied in the first release. This session will keep track of deltas during a request.

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.

Version:
$Id: DeltaSession.java 1160227 2011-08-22 12:06:00Z kkolinko $
Author:
Filip Hanik, Craig R. McClanahan, Sean Legassick, Jon S. Stevens
See Also:
Serialized Form

Field Summary
protected  int accessCount
          The access count for this session
protected static java.lang.String[] EMPTY_ARRAY
          Type array.
protected  boolean isValid
          Flag indicating whether this session is valid or not.
static org.apache.commons.logging.Log log
           
protected static StringManager smp
          The string manager for this package.
 
Fields inherited from interface org.apache.catalina.Session
SESSION_ACTIVATED_EVENT, SESSION_CREATED_EVENT, SESSION_DESTROYED_EVENT, SESSION_PASSIVATED_EVENT
 
Constructor Summary
DeltaSession(Manager manager)
          Construct a new Session associated with the specified Manager.
 
Method Summary
 void access()
          Update the accessed time information for this session.
 void addSessionListener(SessionListener listener)
          Add a session event listener to this component.
 void endAccess()
          End access to the session.
 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 notifyCluster)
           
 void fireSessionEvent(java.lang.String type, java.lang.Object data)
          Notify all session event listeners that a particular event has occurred for this Session.
protected  int getAccessCount()
           
 java.lang.Object getAttribute(java.lang.String name)
          Return the object bound with the specified name in this session, or null if no object is bound with that name.
protected  java.lang.Object getAttributeInternal(java.lang.String name)
          Return the value of an attribute without a check for validity.
 java.util.Enumeration getAttributeNames()
          Return an Enumeration of String objects containing the names of the objects bound to this session.
 java.lang.String getAuthType()
          Return the authentication type used to authenticate our cached Principal, if any.
 long getCreationTime()
          Return the time when this session was created, in milliseconds since midnight, January 1, 1970 GMT.
 DeltaRequest getDeltaRequest()
           
protected  int getExpireTolerance()
           
 java.lang.String getId()
          Return the session identifier for this session.
 java.lang.String getIdInternal()
          Return the session identifier for this session.
 java.lang.String getInfo()
          Return descriptive information about this Session implementation and the corresponding version number, in the format <description>/<version>.
 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()
          Return the last client access time without invalidation check
protected  long getLastTimeReplicated()
           
 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.
 java.lang.Object getNote(java.lang.String name)
          Return the object bound with the specified name to the internal notes for this session, or null if no such binding exists.
 java.util.Iterator getNoteNames()
          Return an Iterator containing the String names of all notes bindings that exist for this session.
 java.security.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.
 java.lang.Object getValue(java.lang.String name)
          Deprecated. As of Version 2.2, this method is replaced by getAttribute()
 java.lang.String[] getValueNames()
          Deprecated. As of Version 2.2, this method is replaced by getAttributeNames()
 void invalidate()
          Invalidates this session and unbinds any objects bound to it.
 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 isPrimarySession()
          returns true if this session is the primary session, if that is the case, the manager can expire it upon timeout.
 boolean isValid()
          Return the isValid flag for this session.
protected  java.lang.String[] keys()
          Return the names of all currently defined session attributes as an array of Strings.
 void putValue(java.lang.String name, java.lang.Object value)
          Deprecated. As of Version 2.2, this method is replaced by setAttribute()
 void readObjectData(java.io.ObjectInputStream stream)
          Read a serialized version of the contents of this session object from the specified object input stream, without requiring that the StandardSession itself have been serialized.
 void recycle()
          Release all object references, and initialize instance variables, in preparation for reuse of this object.
 void removeAttribute(java.lang.String name)
          Remove the object bound with the specified name from this session.
 void removeAttribute(java.lang.String name, boolean notify)
          Remove the object bound with the specified name from this session.
 void removeAttribute(java.lang.String name, boolean notify, boolean addDeltaRequest)
           
protected  void removeAttributeInternal(java.lang.String name, boolean notify, boolean addDeltaRequest)
           
 void removeNote(java.lang.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(java.lang.String name)
          Deprecated. As of Version 2.2, this method is replaced by removeAttribute()
 void resetDeltaRequest()
           
protected  void setAccessCount(int accessCount)
           
 void setAttribute(java.lang.String name, java.lang.Object value)
          Bind an object to this session, using the specified name.
 void setAttribute(java.lang.String name, java.lang.Object value, boolean notify, boolean addDeltaRequest)
           
 void setAuthType(java.lang.String authType)
          Set the authentication type used to authenticate our cached Principal, if any.
 void setAuthType(java.lang.String authType, boolean addDeltaRequest)
           
 void setCreationTime(long time)
          Set the creation time for this session.
protected  void setExpireTolerance(int expireTolerance)
           
 void setId(java.lang.String id)
          Set the session identifier for this session.
 void setId(java.lang.String id, boolean notify)
          Set the session identifier for this session and optionally notifies any associated listeners that a new session has been created.
 void setIdInternal(java.lang.String id)
          Set the session identifier for this session without notify listeners.
protected  void setLastTimeReplicated(long lastTimeReplicated)
           
 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 setMaxInactiveInterval(int interval, boolean addDeltaRequest)
           
 void setNew(boolean isNew)
          Set the isNew flag for this session.
 void setNew(boolean isNew, boolean addDeltaRequest)
           
 void setNote(java.lang.String name, java.lang.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 setPrimarySession(boolean primarySession)
          Sets whether this is the primary session or not.
 void setPrincipal(java.security.Principal principal)
          Set the authenticated Principal that is associated with this Session.
 void setPrincipal(java.security.Principal principal, boolean addDeltaRequest)
           
 void setValid(boolean isValid)
          Set the isValid flag for this session.
 void tellNew()
          Inform the listeners about the new session.
 java.lang.String toString()
          Return a string representation of this object.
 void writeObjectData(java.io.ObjectOutputStream stream)
          Write a serialized version of the contents of this session object to the specified object output stream, without requiring that the StandardSession itself have been serialized.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

log

public static org.apache.commons.logging.Log log

smp

protected static StringManager smp
The string manager for this package.


EMPTY_ARRAY

protected static final java.lang.String[] EMPTY_ARRAY
Type array.


isValid

protected boolean isValid
Flag indicating whether this session is valid or not.


accessCount

protected transient int accessCount
The access count for this session

Constructor Detail

DeltaSession

public DeltaSession(Manager manager)
Construct a new Session associated with the specified Manager.

Parameters:
manager - The manager with which this Session is associated
Method Detail

isPrimarySession

public boolean isPrimarySession()
returns true if this session is the primary session, if that is the case, the manager can expire it upon timeout.

Specified by:
isPrimarySession in interface ClusterSession
Returns:
True if this session is primary

setPrimarySession

public void setPrimarySession(boolean primarySession)
Sets whether this is the primary session or not.

Specified by:
setPrimarySession in interface ClusterSession
Parameters:
primarySession - Flag value

getAuthType

public java.lang.String getAuthType()
Return the authentication type used to authenticate our cached Principal, if any.

Specified by:
getAuthType in interface Session

setAuthType

public void setAuthType(java.lang.String authType)
Set the authentication type used to authenticate our cached Principal, if any.

Specified by:
setAuthType in interface Session
Parameters:
authType - The new cached authentication type

setAuthType

public void setAuthType(java.lang.String authType,
                        boolean addDeltaRequest)

setCreationTime

public void setCreationTime(long time)
Set the creation time for this session. This method is called by the Manager when an existing Session instance is reused.

Specified by:
setCreationTime in interface Session
Parameters:
time - The new creation time

getId

public java.lang.String getId()
Return the session identifier for this session.

Specified by:
getId in interface javax.servlet.http.HttpSession

getIdInternal

public java.lang.String getIdInternal()
Return the session identifier for this session.

Specified by:
getIdInternal in interface Session

setIdInternal

public void setIdInternal(java.lang.String id)
Set the session identifier for this session without notify listeners.

Parameters:
id - The new session identifier

setId

public void setId(java.lang.String id)
Set the session identifier for this session.

Specified by:
setId in interface Session
Parameters:
id - The new session identifier

setId

public void setId(java.lang.String id,
                  boolean notify)
Description copied from interface: Session
Set the session identifier for this session and optionally notifies any associated listeners that a new session has been created.

Specified by:
setId in interface Session
Parameters:
id - The new session identifier
notify - Should any associated listeners be notified that a new session has been created?

tellNew

public void tellNew()
Inform the listeners about the new session.


getInfo

public java.lang.String getInfo()
Return descriptive information about this Session implementation and the corresponding version number, in the format <description>/<version>.

Specified by:
getInfo in interface Session

getLastAccessedTime

public 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. Actions that your application takes, such as getting or setting a value associated with the session, do not affect the access time.

Specified by:
getLastAccessedTime in interface javax.servlet.http.HttpSession

getLastAccessedTimeInternal

public long getLastAccessedTimeInternal()
Return the last client access time without invalidation check

Specified by:
getLastAccessedTimeInternal in interface Session
See Also:
getLastAccessedTime().

getManager

public Manager getManager()
Return the Manager within which this Session is valid.

Specified by:
getManager in interface Session

setManager

public void setManager(Manager manager)
Set the Manager within which this Session is valid.

Specified by:
setManager in interface Session
Parameters:
manager - The new Manager

getMaxInactiveInterval

public int getMaxInactiveInterval()
Return the maximum time interval, in seconds, between client requests before the servlet container will invalidate the session. A negative time indicates that the session should never time out.

Specified by:
getMaxInactiveInterval in interface javax.servlet.http.HttpSession

setMaxInactiveInterval

public void setMaxInactiveInterval(int interval)
Set the maximum time interval, in seconds, between client requests before the servlet container will invalidate the session. A negative time indicates that the session should never time out.

Specified by:
setMaxInactiveInterval in interface javax.servlet.http.HttpSession
Parameters:
interval - The new maximum interval

setMaxInactiveInterval

public void setMaxInactiveInterval(int interval,
                                   boolean addDeltaRequest)

setNew

public void setNew(boolean isNew)
Set the isNew flag for this session.

Specified by:
setNew in interface Session
Parameters:
isNew - The new value for the isNew flag

setNew

public void setNew(boolean isNew,
                   boolean addDeltaRequest)

getPrincipal

public java.security.Principal getPrincipal()
Return the authenticated Principal that is associated with this Session. This provides an 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.

Specified by:
getPrincipal in interface Session

setPrincipal

public void setPrincipal(java.security.Principal principal)
Set the authenticated Principal that is associated with this Session. This provides an Authenticator with a means to cache a previously authenticated Principal, and avoid potentially expensive Realm.authenticate() calls on every request.

Specified by:
setPrincipal in interface Session
Parameters:
principal - The new Principal, or null if none

setPrincipal

public void setPrincipal(java.security.Principal principal,
                         boolean addDeltaRequest)

getSession

public javax.servlet.http.HttpSession getSession()
Return the HttpSession for which this object is the facade.

Specified by:
getSession in interface Session

isValid

public boolean isValid()
Return the isValid flag for this session.

Specified by:
isValid in interface Session

setValid

public void setValid(boolean isValid)
Set the isValid flag for this session.

Specified by:
setValid in interface Session
Parameters:
isValid - The new value for the isValid flag

access

public void access()
Update the accessed time information for this session. This method should be called by the context when a request comes in for a particular session, even if the application does not reference it.

Specified by:
access in interface Session

endAccess

public void endAccess()
Description copied from interface: Session
End access to the session.

Specified by:
endAccess in interface Session

addSessionListener

public void addSessionListener(SessionListener listener)
Add a session event listener to this component.

Specified by:
addSessionListener in interface Session

expire

public void expire()
Perform the internal processing required to invalidate this session, without triggering an exception if the session has already expired.

Specified by:
expire in interface Session

expire

public void expire(boolean notify)
Perform the internal processing required to invalidate this session, without triggering an exception if the session has already expired.

Parameters:
notify - Should we notify listeners about the demise of this session?

expire

public void expire(boolean notify,
                   boolean notifyCluster)

getNote

public java.lang.Object getNote(java.lang.String name)
Return the object bound with the specified name to the internal notes for this session, or null if no such binding exists.

Specified by:
getNote in interface Session
Parameters:
name - Name of the note to be returned

getNoteNames

public java.util.Iterator getNoteNames()
Return an Iterator containing the String names of all notes bindings that exist for this session.

Specified by:
getNoteNames in interface Session

recycle

public void recycle()
Release all object references, and initialize instance variables, in preparation for reuse of this object.

Specified by:
recycle in interface Session

removeNote

public void removeNote(java.lang.String name)
Remove any object bound to the specified name in the internal notes for this session.

Specified by:
removeNote in interface Session
Parameters:
name - Name of the note to be removed

removeSessionListener

public void removeSessionListener(SessionListener listener)
Remove a session event listener from this component.

Specified by:
removeSessionListener in interface Session

setNote

public void setNote(java.lang.String name,
                    java.lang.Object value)
Bind an object to a specified name in the internal notes associated with this session, replacing any existing binding for this name.

Specified by:
setNote in interface Session
Parameters:
name - Name to which the object should be bound
value - Object to be bound to the specified name

toString

public java.lang.String toString()
Return a string representation of this object.


readObjectData

public void readObjectData(java.io.ObjectInputStream stream)
                    throws java.lang.ClassNotFoundException,
                           java.io.IOException
Read a serialized version of the contents of this session object from the specified object input stream, without requiring that the StandardSession itself have been serialized.

Parameters:
stream - The object input stream to read from
Throws:
java.lang.ClassNotFoundException - if an unknown class is specified
java.io.IOException - if an input/output error occurs

writeObjectData

public void writeObjectData(java.io.ObjectOutputStream stream)
                     throws java.io.IOException
Write a serialized version of the contents of this session object to the specified object output stream, without requiring that the StandardSession itself have been serialized.

Parameters:
stream - The object output stream to write to
Throws:
java.io.IOException - if an input/output error occurs

resetDeltaRequest

public void resetDeltaRequest()

getDeltaRequest

public DeltaRequest getDeltaRequest()

getCreationTime

public long getCreationTime()
Return the time when this session was created, in milliseconds since midnight, January 1, 1970 GMT.

Specified by:
getCreationTime in interface javax.servlet.http.HttpSession
Throws:
java.lang.IllegalStateException - if this method is called on an invalidated session

getServletContext

public javax.servlet.ServletContext getServletContext()
Return the ServletContext to which this session belongs.

Specified by:
getServletContext in interface javax.servlet.http.HttpSession

getSessionContext

public 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.

Return the session context with which this session is associated.

Specified by:
getSessionContext in interface javax.servlet.http.HttpSession

getAttribute

public java.lang.Object getAttribute(java.lang.String name)
Return the object bound with the specified name in this session, or null if no object is bound with that name.

Specified by:
getAttribute in interface javax.servlet.http.HttpSession
Parameters:
name - Name of the attribute to be returned
Throws:
java.lang.IllegalStateException - if this method is called on an invalidated session

getAttributeNames

public java.util.Enumeration getAttributeNames()
Return an Enumeration of String objects containing the names of the objects bound to this session.

Specified by:
getAttributeNames in interface javax.servlet.http.HttpSession
Throws:
java.lang.IllegalStateException - if this method is called on an invalidated session

getValue

public java.lang.Object getValue(java.lang.String name)
Deprecated. As of Version 2.2, this method is replaced by getAttribute()

Return the object bound with the specified name in this session, or null if no object is bound with that name.

Specified by:
getValue in interface javax.servlet.http.HttpSession
Parameters:
name - Name of the value to be returned
Throws:
java.lang.IllegalStateException - if this method is called on an invalidated session

getValueNames

public java.lang.String[] getValueNames()
Deprecated. As of Version 2.2, this method is replaced by getAttributeNames()

Return the set of names of objects bound to this session. If there are no such objects, a zero-length array is returned.

Specified by:
getValueNames in interface javax.servlet.http.HttpSession
Throws:
java.lang.IllegalStateException - if this method is called on an invalidated session

invalidate

public void invalidate()
Invalidates this session and unbinds any objects bound to it.

Specified by:
invalidate in interface javax.servlet.http.HttpSession
Throws:
java.lang.IllegalStateException - if this method is called on an invalidated session

isNew

public boolean isNew()
Return 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.

Specified by:
isNew in interface javax.servlet.http.HttpSession
Throws:
java.lang.IllegalStateException - if this method is called on an invalidated session

putValue

public void putValue(java.lang.String name,
                     java.lang.Object value)
Deprecated. As of Version 2.2, this method is replaced by setAttribute()

Bind an object to this session, using the specified name. If an object of the same name is already bound to this session, the object is replaced.

After this method executes, and if the object implements HttpSessionBindingListener, the container calls valueBound() on the object.

Specified by:
putValue in interface javax.servlet.http.HttpSession
Parameters:
name - Name to which the object is bound, cannot be null
value - Object to be bound, cannot be null
Throws:
java.lang.IllegalStateException - if this method is called on an invalidated session

removeAttribute

public void removeAttribute(java.lang.String name)
Remove the object bound with the specified name from this session. If the session does not have an object bound with this name, this method does nothing.

After this method executes, and if the object implements HttpSessionBindingListener, the container calls valueUnbound() on the object.

Specified by:
removeAttribute in interface javax.servlet.http.HttpSession
Parameters:
name - Name of the object to remove from this session.
Throws:
java.lang.IllegalStateException - if this method is called on an invalidated session

removeAttribute

public void removeAttribute(java.lang.String name,
                            boolean notify)
Remove the object bound with the specified name from this session. If the session does not have an object bound with this name, this method does nothing.

After this method executes, and if the object implements HttpSessionBindingListener, the container calls valueUnbound() on the object.

Parameters:
name - Name of the object to remove from this session.
notify - Should we notify interested listeners that this attribute is being removed?
Throws:
java.lang.IllegalStateException - if this method is called on an invalidated session

removeAttribute

public void removeAttribute(java.lang.String name,
                            boolean notify,
                            boolean addDeltaRequest)

removeValue

public void removeValue(java.lang.String name)
Deprecated. As of Version 2.2, this method is replaced by removeAttribute()

Remove the object bound with the specified name from this session. If the session does not have an object bound with this name, this method does nothing.

After this method executes, and if the object implements HttpSessionBindingListener, the container calls valueUnbound() on the object.

Specified by:
removeValue in interface javax.servlet.http.HttpSession
Parameters:
name - Name of the object to remove from this session.
Throws:
java.lang.IllegalStateException - if this method is called on an invalidated session

setAttribute

public void setAttribute(java.lang.String name,
                         java.lang.Object value)
Bind an object to this session, using the specified name. If an object of the same name is already bound to this session, the object is replaced.

After this method executes, and if the object implements HttpSessionBindingListener, the container calls valueBound() on the object.

Specified by:
setAttribute in interface javax.servlet.http.HttpSession
Parameters:
name - Name to which the object is bound, cannot be null
value - Object to be bound, cannot be null
Throws:
java.lang.IllegalArgumentException - if an attempt is made to add a non-serializable object in an environment marked distributable.
java.lang.IllegalStateException - if this method is called on an invalidated session

setAttribute

public void setAttribute(java.lang.String name,
                         java.lang.Object value,
                         boolean notify,
                         boolean addDeltaRequest)

fireSessionEvent

public void fireSessionEvent(java.lang.String type,
                             java.lang.Object data)
Notify all session event listeners that a particular event has occurred for this Session. The default implementation performs this notification synchronously using the calling thread.

Parameters:
type - Event type
data - Event data

keys

protected java.lang.String[] keys()
Return the names of all currently defined session attributes as an array of Strings. If there are no defined attributes, a zero-length array is returned.


getAttributeInternal

protected java.lang.Object getAttributeInternal(java.lang.String name)
Return the value of an attribute without a check for validity.


removeAttributeInternal

protected void removeAttributeInternal(java.lang.String name,
                                       boolean notify,
                                       boolean addDeltaRequest)

getLastTimeReplicated

protected long getLastTimeReplicated()

setLastTimeReplicated

protected void setLastTimeReplicated(long lastTimeReplicated)

setAccessCount

protected void setAccessCount(int accessCount)

getAccessCount

protected int getAccessCount()

setExpireTolerance

protected void setExpireTolerance(int expireTolerance)

getExpireTolerance

protected int getExpireTolerance()


Copyright © 2000-2012 Apache Software Foundation. All Rights Reserved.