Apache Tomcat 7.0.37

org.apache.catalina.ha.session
Class DeltaSession

java.lang.Object
  extended by org.apache.catalina.session.StandardSession
      extended by org.apache.catalina.ha.session.DeltaSession
All Implemented Interfaces:
Externalizable, Serializable, HttpSession, ClusterSession, Session, ReplicatedMapEntry

public class DeltaSession
extends StandardSession
implements Externalizable, ClusterSession, ReplicatedMapEntry

Similar to the StandardSession except that this session will keep track of deltas during a request.

Version:
$Id: DeltaSession.java 1327623 2012-04-18 18:46:41Z kkolinko $
Author:
Filip Hanik
See Also:
Serialized Form

Field Summary
protected  Lock diffLock
           
static Log log
           
protected static StringManager sm
          The string manager for this package.
 
Fields inherited from class org.apache.catalina.session.StandardSession
accessCount, ACTIVITY_CHECK, attributes, authType, creationTime, EMPTY_ARRAY, excludedAttributes, expiring, facade, id, info, isNew, isValid, LAST_ACCESS_AT_START, lastAccessedTime, listeners, manager, maxInactiveInterval, NOT_SERIALIZED, notes, principal, sessionContext, STRICT_SERVLET_COMPLIANCE, support, thisAccessedTime
 
Fields inherited from interface org.apache.catalina.Session
SESSION_ACTIVATED_EVENT, SESSION_CREATED_EVENT, SESSION_DESTROYED_EVENT, SESSION_PASSIVATED_EVENT
 
Constructor Summary
DeltaSession()
           
DeltaSession(Manager manager)
          Construct a new Session associated with the specified Manager.
 
Method Summary
 void accessEntry()
          Access to an existing object.
 void applyDiff(byte[] diff, int offset, int length)
          Applies a diff to an existing object.
 void endAccess()
          End the access and register to ReplicationValve (crossContext support)
protected  boolean exclude(String name)
          Exclude attributes from replication.
 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)
           
protected  Object getAttributeInternal(String name)
          Return the value of an attribute without a check for validity.
 ClassLoader[] getClassLoaders()
           
 DeltaRequest getDeltaRequest()
           
 byte[] getDiff()
          Returns a diff and sets the dirty map to false
 long getLastTimeReplicated()
          Return the last replicate time.
 long getVersion()
          For accuracy checking, a serialized attribute can contain a version number This number increases as modifications are made to the data.
 boolean isAccessReplicate()
          If this returns true, to replicate that an object has been accessed
protected  boolean isAttributeDistributable(String name, Object value)
          Check whether the Object can be distributed.
 boolean isDiffable()
          If this returns true, the map will extract the diff using getDiff() Otherwise it will serialize the entire object.
 boolean isDirty()
          Has the object changed since last replication and is not in a locked state
 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.
 void lock()
          Lock during serialization
 void readExternal(ObjectInput in)
           
protected  void readObject(ObjectInputStream stream)
          Read a serialized version of this session object from the specified object input stream.
 void readObjectData(ObjectInput stream)
           
 void readObjectData(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(String name, boolean notify)
          Remove the object bound with the specified name from this session.
 void removeAttribute(String name, boolean notify, boolean addDeltaRequest)
           
protected  void removeAttributeInternal(String name, boolean notify, boolean addDeltaRequest)
           
 void resetDeltaRequest()
           
 void resetDiff()
          Resets the current diff state and resets the dirty flag
protected  void setAccessCount(int count)
           
 void setAttribute(String name, Object value)
          Bind an object to this session, using the specified name.
 void setAttribute(String name, Object value, boolean notify, boolean addDeltaRequest)
           
 void setAuthType(String authType)
          Set the authentication type used to authenticate our cached Principal, if any.
 void setAuthType(String authType, boolean addDeltaRequest)
           
 void setId(String id)
          Set the session identifier for this session.
 void setId(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 setLastTimeReplicated(long lastTimeReplicated)
          Set the last replicate time.
 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 setOwner(Object owner)
          This method is called after the object has been created on a remote map.
 void setPrimarySession(boolean primarySession)
          Sets whether this is the primary session or not.
 void setPrincipal(Principal principal)
          Set the authenticated Principal that is associated with this Session.
 void setPrincipal(Principal principal, boolean addDeltaRequest)
           
 void setVersion(long version)
          Forces a certain version to a replicated map entry
 String toString()
          Return a string representation of this object.
 void unlock()
          Unlock after serialization
 void writeExternal(ObjectOutput out)
           
protected  void writeObject(ObjectOutputStream stream)
          Write a serialized version of this session object to the specified object output stream.
 void writeObjectData(ObjectOutput stream)
           
 void writeObjectData(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 org.apache.catalina.session.StandardSession
access, activate, addSessionListener, expire, fireContainerEvent, fireSessionEvent, getAttribute, getAttributeNames, getAuthType, getCreationTime, getCreationTimeInternal, getId, getIdInternal, getInfo, getLastAccessedTime, getLastAccessedTimeInternal, getManager, getMaxInactiveInterval, getNote, getNoteNames, getPrincipal, getServletContext, getSession, getSessionContext, getThisAccessedTime, getThisAccessedTimeInternal, getValue, getValueNames, invalidate, isNew, isValidInternal, keys, passivate, putValue, removeAttribute, removeAttributeInternal, removeNote, removeSessionListener, removeValue, setAttribute, setCreationTime, setManager, setNote, setValid, tellNew
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.apache.catalina.Session
access, addSessionListener, expire, getAuthType, getCreationTime, getCreationTimeInternal, getId, getIdInternal, getInfo, getLastAccessedTime, getLastAccessedTimeInternal, getManager, getMaxInactiveInterval, getNote, getNoteNames, getPrincipal, getSession, getThisAccessedTime, getThisAccessedTimeInternal, removeNote, removeSessionListener, setCreationTime, setManager, setNote, setValid
 
Methods inherited from interface javax.servlet.http.HttpSession
getAttribute, getAttributeNames, getCreationTime, getId, getLastAccessedTime, getMaxInactiveInterval, getServletContext, getSessionContext, getValue, getValueNames, invalidate, isNew, putValue, removeAttribute, removeValue
 

Field Detail

log

public static final Log log

sm

protected static final StringManager sm
The string manager for this package.


diffLock

protected final Lock diffLock
Constructor Detail

DeltaSession

public DeltaSession()

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

isDirty

public boolean isDirty()
Has the object changed since last replication and is not in a locked state

Specified by:
isDirty in interface ReplicatedMapEntry
Returns:
boolean

isDiffable

public boolean isDiffable()
If this returns true, the map will extract the diff using getDiff() Otherwise it will serialize the entire object.

Specified by:
isDiffable in interface ReplicatedMapEntry
Returns:
boolean

getDiff

public byte[] getDiff()
               throws IOException
Returns a diff and sets the dirty map to false

Specified by:
getDiff in interface ReplicatedMapEntry
Returns:
byte[]
Throws:
IOException

getClassLoaders

public ClassLoader[] getClassLoaders()

applyDiff

public void applyDiff(byte[] diff,
                      int offset,
                      int length)
               throws IOException,
                      ClassNotFoundException
Applies a diff to an existing object.

Specified by:
applyDiff in interface ReplicatedMapEntry
Parameters:
diff - byte[]
offset - int
length - int
Throws:
IOException
ClassNotFoundException

resetDiff

public void resetDiff()
Resets the current diff state and resets the dirty flag

Specified by:
resetDiff in interface ReplicatedMapEntry

lock

public void lock()
Lock during serialization

Specified by:
lock in interface ReplicatedMapEntry

unlock

public void unlock()
Unlock after serialization

Specified by:
unlock in interface ReplicatedMapEntry

setOwner

public void setOwner(Object owner)
Description copied from interface: ReplicatedMapEntry
This method is called after the object has been created on a remote map. On this method, the object can initialize itself for any data that wasn't

Specified by:
setOwner in interface ReplicatedMapEntry
Parameters:
owner - Object

isAccessReplicate

public boolean isAccessReplicate()
If this returns true, to replicate that an object has been accessed

Specified by:
isAccessReplicate in interface ReplicatedMapEntry
Returns:
boolean

accessEntry

public void accessEntry()
Access to an existing object.

Specified by:
accessEntry in interface ReplicatedMapEntry

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

setId

public void setId(String id,
                  boolean notify)
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
Overrides:
setId in class StandardSession
Parameters:
id - The new session identifier
notify - Should any associated listeners be notified that a new session has been created?

setId

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

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

setMaxInactiveInterval

public void setMaxInactiveInterval(int interval)
Description copied from class: StandardSession
Set the maximum time interval, in seconds, between client requests before the servlet container will invalidate the session. A zero or negative time indicates that the session should never time out.

Specified by:
setMaxInactiveInterval in interface HttpSession
Specified by:
setMaxInactiveInterval in interface Session
Overrides:
setMaxInactiveInterval in class StandardSession
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
Overrides:
setNew in class StandardSession
Parameters:
isNew - The new value for the isNew flag

setNew

public void setNew(boolean isNew,
                   boolean addDeltaRequest)

setPrincipal

public void setPrincipal(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
Overrides:
setPrincipal in class StandardSession
Parameters:
principal - The new Principal, or null if none

setPrincipal

public void setPrincipal(Principal principal,
                         boolean addDeltaRequest)

setAuthType

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

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

setAuthType

public void setAuthType(String authType,
                        boolean addDeltaRequest)

isValid

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

Specified by:
isValid in interface Session
Overrides:
isValid in class StandardSession

endAccess

public void endAccess()
End the access and register to ReplicationValve (crossContext support)

Specified by:
endAccess in interface Session
Overrides:
endAccess in class StandardSession

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.

Overrides:
expire in class StandardSession
Parameters:
notify - Should we notify listeners about the demise of this session?

expire

public void expire(boolean notify,
                   boolean notifyCluster)

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
Overrides:
recycle in class StandardSession

toString

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

Overrides:
toString in class StandardSession

readExternal

public void readExternal(ObjectInput in)
                  throws IOException,
                         ClassNotFoundException
Specified by:
readExternal in interface Externalizable
Throws:
IOException
ClassNotFoundException

readObjectData

public void readObjectData(ObjectInputStream stream)
                    throws ClassNotFoundException,
                           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.

Overrides:
readObjectData in class StandardSession
Parameters:
stream - The object input stream to read from
Throws:
ClassNotFoundException - if an unknown class is specified
IOException - if an input/output error occurs

readObjectData

public void readObjectData(ObjectInput stream)
                    throws ClassNotFoundException,
                           IOException
Throws:
ClassNotFoundException
IOException

writeObjectData

public void writeObjectData(ObjectOutputStream stream)
                     throws 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.

Overrides:
writeObjectData in class StandardSession
Parameters:
stream - The object output stream to write to
Throws:
IOException - if an input/output error occurs

writeObjectData

public void writeObjectData(ObjectOutput stream)
                     throws IOException
Throws:
IOException

resetDeltaRequest

public void resetDeltaRequest()

getDeltaRequest

public DeltaRequest getDeltaRequest()

isAttributeDistributable

protected boolean isAttributeDistributable(String name,
                                           Object value)
Check whether the Object can be distributed. The object is always distributable, if the cluster manager decides to never distribute it.

Overrides:
isAttributeDistributable in class StandardSession
Parameters:
name - The name of the attribute to check
value - The value of the attribute to check
Returns:
true if the attribute is distributable, false otherwise

exclude

protected boolean exclude(String name)
Exclude attributes from replication.

Overrides:
exclude in class StandardSession
Parameters:
name - the attribute's name
Returns:
true if attribute should not be replicated

removeAttribute

public void removeAttribute(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.

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

removeAttribute

public void removeAttribute(String name,
                            boolean notify,
                            boolean addDeltaRequest)

setAttribute

public void setAttribute(String name,
                         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 HttpSession
Overrides:
setAttribute in class StandardSession
Parameters:
name - Name to which the object is bound, cannot be null
value - Object to be bound, cannot be null
Throws:
IllegalArgumentException - 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 session

setAttribute

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

readObject

protected void readObject(ObjectInputStream stream)
                   throws ClassNotFoundException,
                          IOException
Read a serialized version of this session object from the specified object input stream.

IMPLEMENTATION NOTE : The reference to the owning Manager is not restored by this method, and must be set explicitly.

Overrides:
readObject in class StandardSession
Parameters:
stream - The input stream to read from
Throws:
ClassNotFoundException - if an unknown class is specified
IOException - if an input/output error occurs

writeExternal

public void writeExternal(ObjectOutput out)
                   throws IOException
Specified by:
writeExternal in interface Externalizable
Throws:
IOException

writeObject

protected void writeObject(ObjectOutputStream stream)
                    throws IOException
Write a serialized version of this session object to the specified object output stream.

IMPLEMENTATION NOTE : The owning Manager will not be stored in the serialized representation of this Session. After calling readObject(), you must set the associated Manager explicitly.

IMPLEMENTATION NOTE : Any attribute that is not Serializable will be unbound from the session, with appropriate actions if it implements HttpSessionBindingListener. If you do not want any such attributes, be sure the distributable property of the associated Manager is set to true.

Overrides:
writeObject in class StandardSession
Parameters:
stream - The output stream to write to
Throws:
IOException - if an input/output error occurs

getAttributeInternal

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


removeAttributeInternal

protected void removeAttributeInternal(String name,
                                       boolean notify,
                                       boolean addDeltaRequest)

getLastTimeReplicated

public long getLastTimeReplicated()
Description copied from interface: ReplicatedMapEntry
Return the last replicate time.

Specified by:
getLastTimeReplicated in interface ReplicatedMapEntry

getVersion

public long getVersion()
Description copied from interface: ReplicatedMapEntry
For accuracy checking, a serialized attribute can contain a version number This number increases as modifications are made to the data. The replicated map can use this to ensure accuracy on a periodic basis

Specified by:
getVersion in interface ReplicatedMapEntry
Returns:
long - the version number or -1 if the data is not versioned

setLastTimeReplicated

public void setLastTimeReplicated(long lastTimeReplicated)
Description copied from interface: ReplicatedMapEntry
Set the last replicate time.

Specified by:
setLastTimeReplicated in interface ReplicatedMapEntry

setVersion

public void setVersion(long version)
Description copied from interface: ReplicatedMapEntry
Forces a certain version to a replicated map entry

Specified by:
setVersion in interface ReplicatedMapEntry
Parameters:
version - long

setAccessCount

protected void setAccessCount(int count)

Apache Tomcat 7.0.37

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