Class DeltaSession
- java.lang.Object
-
- org.apache.catalina.session.StandardSession
-
- 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.- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description protected LockdiffLockstatic Loglogprotected static StringManagersmThe string manager for this package.-
Fields inherited from class org.apache.catalina.session.StandardSession
accessCount, ACTIVITY_CHECK, attributes, authType, creationTime, EMPTY_ARRAY, expiring, facade, id, isNew, isValid, LAST_ACCESS_AT_START, lastAccessedTime, listeners, manager, maxInactiveInterval, 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
Constructors Constructor Description DeltaSession()DeltaSession(Manager manager)Construct a new Session associated with the specified Manager.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaccessEntry()Access to an existing object.voidaddSessionListener(SessionListener listener)Add a session event listener to this component.voidaddSessionListener(SessionListener listener, boolean addDeltaRequest)voidapplyDiff(byte[] diff, int offset, int length)Applies a diff to an existing object.protected DeltaRequestcreateRequest(String sessionId, boolean recordAllActions)protected voiddeserializeAndExecuteDeltaRequest(byte[] delta)protected voiddoReadObject(ObjectInputStream stream)Read a serialized version of this session object from the specified object input stream.protected voiddoWriteObject(ObjectOutputStream stream)Write a serialized version of this session object to the specified object output stream.voidendAccess()End the access and register to ReplicationValve (crossContext support)voidexpire(boolean notify)Perform the internal processing required to invalidate this session, without triggering an exception if the session has already expired.voidexpire(boolean notify, boolean notifyCluster)ClassLoader[]getClassLoaders()DeltaRequestgetDeltaRequest()byte[]getDiff()Returns a diff and sets the dirty map to falselonggetLastTimeReplicated()longgetVersion()For accuracy checking, a serialized attribute can contain a version number This number increases as modifications are made to the data.booleanisAccessReplicate()If this returns true, to replicate that an object has been accessedbooleanisDiffable()If this returns true, the map will extract the diff using getDiff() Otherwise it will serialize the entire object.booleanisDirty()Has the object changed since last replication and is not in a locked statebooleanisPrimarySession()returns true if this session is the primary session, if that is the case, the manager can expire it upon timeout.booleanisValid()Return theisValidflag for this session.voidlock()Lock during serializationvoidreadExternal(ObjectInput in)voidreadObjectData(ObjectInput stream)voidreadObjectData(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.voidrecycle()Release all object references, and initialize instance variables, in preparation for reuse of this object.voidremoveAttribute(String name, boolean notify)Remove the object bound with the specified name from this session.voidremoveAttribute(String name, boolean notify, boolean addDeltaRequest)protected voidremoveAttributeInternal(String name, boolean notify, boolean addDeltaRequest)voidremoveSessionListener(SessionListener listener)Remove a session event listener from this component.voidremoveSessionListener(SessionListener listener, boolean addDeltaRequest)voidresetDeltaRequest()voidresetDiff()Resets the current diff state and resets the dirty flagprotected voidsetAccessCount(int count)voidsetAttribute(String name, Object value)Bind an object to this session, using the specified name.voidsetAttribute(String name, Object value, boolean notify, boolean addDeltaRequest)voidsetAuthType(String authType)Set the authentication type used to authenticate our cached Principal, if any.voidsetAuthType(String authType, boolean addDeltaRequest)voidsetId(String id)Set the session identifier for this session.voidsetId(String id, boolean notify)Set the session identifier for this session and optionally notifies any associated listeners that a new session has been created.voidsetLastTimeReplicated(long lastTimeReplicated)Set the last replicate time.voidsetMaxInactiveInterval(int interval)Set the maximum time interval, in seconds, between client requests before the servlet container will invalidate the session.voidsetMaxInactiveInterval(int interval, boolean addDeltaRequest)voidsetNew(boolean isNew)Set theisNewflag for this session.voidsetNew(boolean isNew, boolean addDeltaRequest)voidsetOwner(Object owner)This method is called after the object has been created on a remote map.voidsetPrimarySession(boolean primarySession)Sets whether this is the primary session or not.voidsetPrincipal(Principal principal)Set the authenticated Principal that is associated with this Session.voidsetPrincipal(Principal principal, boolean addDeltaRequest)voidsetVersion(long version)Forces a certain version to a replicated map entryStringtoString()Return a string representation of this object.voidunlock()Unlock after serializationvoidwriteExternal(ObjectOutput out)voidwriteObjectData(ObjectOutput stream)voidwriteObjectData(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, exclude, expire, fireSessionEvent, getAttribute, getAttributeNames, getAuthType, getCreationTime, getCreationTimeInternal, getId, getIdInternal, getIdleTime, getIdleTimeInternal, getLastAccessedTime, getLastAccessedTimeInternal, getManager, getMaxInactiveInterval, getNote, getNoteNames, getPrincipal, getServletContext, getSession, getSessionContext, getThisAccessedTime, getThisAccessedTimeInternal, getValue, getValueNames, invalidate, isAttributeDistributable, isNew, isValidInternal, keys, passivate, putValue, removeAttribute, removeAttributeInternal, removeNote, removeValue, setAttribute, setCreationTime, setManager, setNote, setValid, tellChangedSessionId, tellNew
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface javax.servlet.http.HttpSession
getAttribute, getAttributeNames, getCreationTime, getId, getLastAccessedTime, getMaxInactiveInterval, getServletContext, getSessionContext, getValue, getValueNames, invalidate, isNew, putValue, removeAttribute, removeValue
-
Methods inherited from interface org.apache.catalina.Session
access, expire, getAuthType, getCreationTime, getCreationTimeInternal, getId, getIdInternal, getIdleTime, getIdleTimeInternal, getLastAccessedTime, getLastAccessedTimeInternal, getManager, getMaxInactiveInterval, getNote, getNoteNames, getPrincipal, getSession, getThisAccessedTime, getThisAccessedTimeInternal, isAttributeDistributable, removeNote, setCreationTime, setManager, setNote, setValid, tellChangedSessionId
-
-
-
-
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
-
createRequest
protected DeltaRequest createRequest(String sessionId, boolean recordAllActions)
-
isDirty
public boolean isDirty()
Has the object changed since last replication and is not in a locked state- Specified by:
isDirtyin interfaceReplicatedMapEntry- 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:
isDiffablein interfaceReplicatedMapEntry- Returns:
- boolean
-
getDiff
public byte[] getDiff() throws IOExceptionReturns a diff and sets the dirty map to false- Specified by:
getDiffin interfaceReplicatedMapEntry- Returns:
- a serialized view of the difference
- Throws:
IOException- IO error serializing
-
getClassLoaders
public ClassLoader[] getClassLoaders()
-
applyDiff
public void applyDiff(byte[] diff, int offset, int length) throws IOException, ClassNotFoundExceptionApplies a diff to an existing object.- Specified by:
applyDiffin interfaceReplicatedMapEntry- Parameters:
diff- Serialized diff dataoffset- Array offsetlength- Array length- Throws:
IOException- IO error deserializingClassNotFoundException- Serialization error
-
resetDiff
public void resetDiff()
Resets the current diff state and resets the dirty flagThis implementation is a NO-OP. The diff is reset in
getDiff().- Specified by:
resetDiffin interfaceReplicatedMapEntry
-
lock
public void lock()
Lock during serializationThis implementation is a NO-OP. Any required locking takes place in the methods that make modifications.
- Specified by:
lockin interfaceReplicatedMapEntry
-
unlock
public void unlock()
Unlock after serializationThis implementation is a NO-OP. Any required unlocking takes place in the methods that make modifications.
- Specified by:
unlockin interfaceReplicatedMapEntry
-
setOwner
public void setOwner(Object owner)
Description copied from interface:ReplicatedMapEntryThis 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:
setOwnerin interfaceReplicatedMapEntry- Parameters:
owner- Object
-
isAccessReplicate
public boolean isAccessReplicate()
If this returns true, to replicate that an object has been accessed- Specified by:
isAccessReplicatein interfaceReplicatedMapEntry- Returns:
- boolean
-
accessEntry
public void accessEntry()
Access to an existing object.- Specified by:
accessEntryin interfaceReplicatedMapEntry
-
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:
isPrimarySessionin interfaceClusterSession- Returns:
- True if this session is primary
-
setPrimarySession
public void setPrimarySession(boolean primarySession)
Sets whether this is the primary session or not.- Specified by:
setPrimarySessionin interfaceClusterSession- 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:
setIdin interfaceSession- Overrides:
setIdin classStandardSession- Parameters:
id- The new session identifiernotify- 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:
setIdin interfaceSession- Overrides:
setIdin classStandardSession- Parameters:
id- The new session identifier
-
setMaxInactiveInterval
public void setMaxInactiveInterval(int interval)
Description copied from class:StandardSessionSet 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:
setMaxInactiveIntervalin interfaceHttpSession- Specified by:
setMaxInactiveIntervalin interfaceSession- Overrides:
setMaxInactiveIntervalin classStandardSession- Parameters:
interval- The new maximum interval
-
setMaxInactiveInterval
public void setMaxInactiveInterval(int interval, boolean addDeltaRequest)
-
setNew
public void setNew(boolean isNew)
Set theisNewflag for this session.- Specified by:
setNewin interfaceSession- Overrides:
setNewin classStandardSession- Parameters:
isNew- The new value for theisNewflag
-
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 anAuthenticatorwith a means to cache a previously authenticated Principal, and avoid potentially expensiveRealm.authenticate()calls on every request.- Specified by:
setPrincipalin interfaceSession- Overrides:
setPrincipalin classStandardSession- Parameters:
principal- The new Principal, ornullif 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:
setAuthTypein interfaceSession- Overrides:
setAuthTypein classStandardSession- Parameters:
authType- The new cached authentication type
-
setAuthType
public void setAuthType(String authType, boolean addDeltaRequest)
-
isValid
public boolean isValid()
Return theisValidflag for this session.- Specified by:
isValidin interfaceSession- Overrides:
isValidin classStandardSession- Returns:
trueif the session is still valid
-
endAccess
public void endAccess()
End the access and register to ReplicationValve (crossContext support)- Specified by:
endAccessin interfaceSession- Overrides:
endAccessin classStandardSession
-
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:
expirein classStandardSession- 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:
recyclein interfaceSession- Overrides:
recyclein classStandardSession
-
toString
public String toString()
Return a string representation of this object.- Overrides:
toStringin classStandardSession
-
addSessionListener
public void addSessionListener(SessionListener listener)
Description copied from class:StandardSessionAdd a session event listener to this component.- Specified by:
addSessionListenerin interfaceSession- Overrides:
addSessionListenerin classStandardSession- Parameters:
listener- the SessionListener instance that should be notified for session events
-
addSessionListener
public void addSessionListener(SessionListener listener, boolean addDeltaRequest)
-
removeSessionListener
public void removeSessionListener(SessionListener listener)
Description copied from class:StandardSessionRemove a session event listener from this component.- Specified by:
removeSessionListenerin interfaceSession- Overrides:
removeSessionListenerin classStandardSession- Parameters:
listener- remove the session listener, which will no longer be notified
-
removeSessionListener
public void removeSessionListener(SessionListener listener, boolean addDeltaRequest)
-
readExternal
public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException
- Specified by:
readExternalin interfaceExternalizable- Throws:
IOExceptionClassNotFoundException
-
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:
readObjectDatain classStandardSession- Parameters:
stream- The object input stream to read from- Throws:
ClassNotFoundException- if an unknown class is specifiedIOException- if an input/output error occurs
-
readObjectData
public void readObjectData(ObjectInput stream) throws ClassNotFoundException, IOException
- Throws:
ClassNotFoundExceptionIOException
-
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:
writeObjectDatain classStandardSession- 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()
-
deserializeAndExecuteDeltaRequest
protected void deserializeAndExecuteDeltaRequest(byte[] delta) throws IOException, ClassNotFoundException- Throws:
IOExceptionClassNotFoundException
-
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 callsvalueUnbound()on the object.- Overrides:
removeAttributein classStandardSession- 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 callsvalueBound()on the object.- Specified by:
setAttributein interfaceHttpSession- Overrides:
setAttributein classStandardSession- Parameters:
name- Name to which the object is bound, cannot be nullvalue- 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)
-
doReadObject
protected void doReadObject(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:
doReadObjectin classStandardSession- Parameters:
stream- The input stream to read from- Throws:
ClassNotFoundException- if an unknown class is specifiedIOException- if an input/output error occurs
-
writeExternal
public void writeExternal(ObjectOutput out) throws IOException
- Specified by:
writeExternalin interfaceExternalizable- Throws:
IOException
-
doWriteObject
protected void doWriteObject(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
distributableproperty of the associated Manager is set totrue.- Overrides:
doWriteObjectin classStandardSession- Parameters:
stream- The output stream to write to- Throws:
IOException- if an input/output error occurs
-
removeAttributeInternal
protected void removeAttributeInternal(String name, boolean notify, boolean addDeltaRequest)
-
getLastTimeReplicated
public long getLastTimeReplicated()
- Specified by:
getLastTimeReplicatedin interfaceReplicatedMapEntry- Returns:
- the last replicate time.
-
getVersion
public long getVersion()
Description copied from interface:ReplicatedMapEntryFor 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:
getVersionin interfaceReplicatedMapEntry- Returns:
- long - the version number or -1 if the data is not versioned
-
setLastTimeReplicated
public void setLastTimeReplicated(long lastTimeReplicated)
Description copied from interface:ReplicatedMapEntrySet the last replicate time.- Specified by:
setLastTimeReplicatedin interfaceReplicatedMapEntry- Parameters:
lastTimeReplicated- New timestamp
-
setVersion
public void setVersion(long version)
Description copied from interface:ReplicatedMapEntryForces a certain version to a replicated map entry- Specified by:
setVersionin interfaceReplicatedMapEntry- Parameters:
version- long
-
setAccessCount
protected void setAccessCount(int count)
-
-