org.apache.catalina.ha.session

Class DeltaManager

public class DeltaManager extends ClusterManagerBase

The DeltaManager manages replicated sessions by only replicating the deltas in data. For applications written to handle this, the DeltaManager is the optimal way of replicating data. This code is almost identical to StandardManager with a difference in how it persists sessions and some modifications to it. IMPLEMENTATION NOTE : Correct behavior of session storing and reloading depends upon external calls to the start() and stop() methods of this class at the correct times.

Version: $Revision: 832112 $ $Date: 2009-11-02 22:34:46 +0100 (Mon, 02 Nov 2009) $

Author: Filip Hanik Craig R. McClanahan Jean-Francois Arcand Peter Rossbach

Field Summary
protected booleandefaultMode
protected LifecycleSupportlifecycle
The lifecycle event support for this component.
static Loglog
protected static StringmanagerName
The descriptive name of this Manager implementation (for logging).
protected Stringname
protected static StringManagersm
The string manager for this package.
Constructor Summary
DeltaManager()
Method Summary
voidaddLifecycleListener(LifecycleListener listener)
Add a lifecycle event listener to this component.
protected booleancheckSenderDomain(SessionMessage msg, Member sender)
Test that sender and local domain is the same
ClusterManagercloneFromTemplate()
SessioncreateEmptySession()
Create DeltaSession
SessioncreateSession(String sessionId)
Construct and return a new session object, based on the default settings specified by this Manager's properties.
SessioncreateSession(String sessionId, boolean distribute)
create new session with check maxActiveSessions and send session creation to other cluster nodes.
protected DeltaRequestdeserializeDeltaRequest(DeltaSession session, byte[] data)
Load Deltarequest from external node Load the Class at container classloader
protected voiddeserializeSessions(byte[] data)
Load sessions from other cluster node.
booleandoDomainReplication()
voidexpireAllLocalSessions()
Exipre all find sessions.
LifecycleListener[]findLifecycleListeners()
Get the lifecycle listeners associated with this lifecycle.
protected MemberfindSessionMasterMember()
Find the master of the session state
voidgetAllClusterSessions()
get from first session master the backup from all clustered sessions
CatalinaClustergetCluster()
intgetCounterNoStateTransfered()
longgetCounterReceive_EVT_ALL_SESSION_DATA()
intgetCounterReceive_EVT_ALL_SESSION_TRANSFERCOMPLETE()
longgetCounterReceive_EVT_GET_ALL_SESSIONS()
longgetCounterReceive_EVT_SESSION_ACCESSED()
longgetCounterReceive_EVT_SESSION_CREATED()
longgetCounterReceive_EVT_SESSION_DELTA()
longgetCounterReceive_EVT_SESSION_EXPIRED()
longgetCounterSend_EVT_ALL_SESSION_DATA()
intgetCounterSend_EVT_ALL_SESSION_TRANSFERCOMPLETE()
longgetCounterSend_EVT_GET_ALL_SESSIONS()
longgetCounterSend_EVT_SESSION_ACCESSED()
longgetCounterSend_EVT_SESSION_CREATED()
longgetCounterSend_EVT_SESSION_DELTA()
longgetCounterSend_EVT_SESSION_EXPIRED()
StringgetInfo()
Return descriptive information about this Manager implementation and the corresponding version number, in the format <description>/<version>.
String[]getInvalidatedSessions()
When the manager expires session not tied to a request.
intgetMaxActiveSessions()
Return the maximum number of active Sessions allowed, or -1 for no limit.
StringgetName()
Return the descriptive short name of this Manager implementation.
protected DeltaSessiongetNewDeltaSession()
Get new session class to be used in the doLoad() method.
longgetProcessingTime()
intgetReceivedQueueSize()
intgetRejectedSessions()
Number of session creations that failed due to maxActiveSessions
intgetSendAllSessionsSize()
intgetSendAllSessionsWaitTime()
longgetSessionReplaceCounter()
booleangetStateTransfered()
is session state transfered complete?
intgetStateTransferTimeout()
protected voidhandleALL_SESSION_DATA(SessionMessage msg, Member sender)
handle receive sessions from other not ( restart )
protected voidhandleALL_SESSION_TRANSFERCOMPLETE(SessionMessage msg, Member sender)
handle receive session state is complete transfered
protected voidhandleGET_ALL_SESSIONS(SessionMessage msg, Member sender)
handle receive that other node want all sessions ( restart ) a) send all sessions with one message b) send session at blocks After sending send state is complete transfered
protected voidhandleSESSION_ACCESSED(SessionMessage msg, Member sender)
handle receive session is access at other node ( primary session is now false)
protected voidhandleSESSION_CREATED(SessionMessage msg, Member sender)
handle receive new session is created at other node (create backup - primary false)
protected voidhandleSESSION_DELTA(SessionMessage msg, Member sender)
handle receive session delta
protected voidhandleSESSION_EXPIRED(SessionMessage msg, Member sender)
handle receive session is expire at other node ( expire session also here)
booleanisDefaultMode()
booleanisExpireSessionsOnShutdown()
booleanisNotifyListenersOnReplication()
booleanisNotifySessionListenersOnReplication()
booleanisSendAllSessions()
booleanisStateTimestampDrop()
voidload()
voidmessageDataReceived(ClusterMessage cmsg)
A message was received from another node, this is the callback method to implement if you are interested in receiving replication messages.
protected voidmessageReceived(SessionMessage msg, Member sender)
This method is called by the received thread when a SessionMessage has been received from one of the other nodes in the cluster.
voidpropertyChange(PropertyChangeEvent event)
Process property change events from our associated Context.
protected voidregisterSessionAtReplicationValve(DeltaSession session)
Register cross context session at replication valve thread local
voidremoveLifecycleListener(LifecycleListener listener)
Remove a lifecycle event listener from this component.
ClusterMessagerequestCompleted(String sessionId)
When the request has been completed, the replication valve will notify the manager, and the manager will decide whether any replication is needed or not.
ClusterMessagerequestCompleted(String sessionId, boolean expires)
When the request has been completed, the replication valve will notify the manager, and the manager will decide whether any replication is needed or not.
voidresetStatistics()
Reset manager statistics
protected voidsend(SessionMessage msg)
Send messages to other backup member (domain or all)
protected voidsendCreateSession(String sessionId, DeltaSession session)
Send create session evt to all backup node
protected voidsendSessions(Member sender, Session[] currentSessions, long sendTimestamp)
send a block of session to sender
protected byte[]serializeDeltaRequest(DeltaSession session, DeltaRequest deltaRequest)
serialize DeltaRequest
protected byte[]serializeSessions(Session[] currentSessions)
Save any currently active sessions in the appropriate persistence mechanism, if any.
protected voidsessionExpired(String id)
send session expired to other cluster nodes
voidsetCluster(CatalinaCluster cluster)
voidsetContainer(Container container)
Set the Container with which this Manager has been associated.
voidsetDefaultMode(boolean defaultMode)
voidsetDomainReplication(boolean sendClusterDomainOnly)
voidsetExpireSessionsOnShutdown(boolean expireSessionsOnShutdown)
voidsetMaxActiveSessions(int max)
Set the maximum number of actives Sessions allowed, or -1 for no limit.
voidsetName(String name)
voidsetNotifyListenersOnReplication(boolean notifyListenersOnReplication)
voidsetNotifySessionListenersOnReplication(boolean notifyListenersCreateSessionOnReplication)
voidsetRejectedSessions(int rejectedSessions)
voidsetSendAllSessions(boolean sendAllSessions)
voidsetSendAllSessionsSize(int sendAllSessionsSize)
voidsetSendAllSessionsWaitTime(int sendAllSessionsWaitTime)
voidsetStateTimestampDrop(boolean isTimestampDrop)
voidsetStateTransfered(boolean stateTransfered)
set that state ist complete transfered
voidsetStateTransferTimeout(int timeoutAllSession)
voidstart()
Prepare for the beginning of active use of the public methods of this component.
voidstop()
Gracefully terminate the active use of the public methods of this component.
voidunload()
protected voidwaitForSendAllSessions(long beforeSendTime)
Wait that cluster session state is transfer or timeout after 60 Sec With stateTransferTimeout == -1 wait that backup is transfered (forever mode)

Field Detail

defaultMode

protected boolean defaultMode

lifecycle

protected LifecycleSupport lifecycle
The lifecycle event support for this component.

log

public static Log log

managerName

protected static String managerName
The descriptive name of this Manager implementation (for logging).

name

protected String name

sm

protected static StringManager sm
The string manager for this package.

Constructor Detail

DeltaManager

public DeltaManager()

Method Detail

addLifecycleListener

public void addLifecycleListener(LifecycleListener listener)
Add a lifecycle event listener to this component.

Parameters: listener The listener to add

checkSenderDomain

protected boolean checkSenderDomain(SessionMessage msg, Member sender)
Test that sender and local domain is the same

cloneFromTemplate

public ClusterManager cloneFromTemplate()

createEmptySession

public Session createEmptySession()
Create DeltaSession

See Also: createEmptySession

createSession

public Session createSession(String sessionId)
Construct and return a new session object, based on the default settings specified by this Manager's properties. The session id will be assigned by this method, and available via the getId() method of the returned session. If a new session cannot be created for any reason, return null.

Throws: IllegalStateException if a new session cannot be instantiated for any reason Construct and return a new session object, based on the default settings specified by this Manager's properties. The session id will be assigned by this method, and available via the getId() method of the returned session. If a new session cannot be created for any reason, return null. IllegalStateException if a new session cannot be instantiated for any reason

createSession

public Session createSession(String sessionId, boolean distribute)
create new session with check maxActiveSessions and send session creation to other cluster nodes.

Parameters: distribute

Returns: The session

deserializeDeltaRequest

protected DeltaRequest deserializeDeltaRequest(DeltaSession session, byte[] data)
Load Deltarequest from external node Load the Class at container classloader

Parameters: session data message data

Returns: The request

Throws: ClassNotFoundException IOException

See Also: readExternal

deserializeSessions

protected void deserializeSessions(byte[] data)
Load sessions from other cluster node. FIXME replace currently sessions with same id without notifcation. FIXME SSO handling is not really correct with the session replacement!

Throws: ClassNotFoundException if a serialized class cannot be found during the reload IOException if an input/output error occurs

doDomainReplication

public boolean doDomainReplication()

Returns: Returns the sendClusterDomainOnly.

expireAllLocalSessions

public void expireAllLocalSessions()
Exipre all find sessions.

findLifecycleListeners

public LifecycleListener[] findLifecycleListeners()
Get the lifecycle listeners associated with this lifecycle. If this Lifecycle has no listeners registered, a zero-length array is returned.

findSessionMasterMember

protected Member findSessionMasterMember()
Find the master of the session state

Returns: master member of sessions

getAllClusterSessions

public void getAllClusterSessions()
get from first session master the backup from all clustered sessions

See Also: findSessionMasterMember

getCluster

public CatalinaCluster getCluster()

getCounterNoStateTransfered

public int getCounterNoStateTransfered()

Returns: Returns the counterNoStateTransfered.

getCounterReceive_EVT_ALL_SESSION_DATA

public long getCounterReceive_EVT_ALL_SESSION_DATA()

Returns: Returns the counterReceive_EVT_ALL_SESSION_DATA.

getCounterReceive_EVT_ALL_SESSION_TRANSFERCOMPLETE

public int getCounterReceive_EVT_ALL_SESSION_TRANSFERCOMPLETE()

Returns: Returns the counterReceive_EVT_ALL_SESSION_TRANSFERCOMPLETE.

getCounterReceive_EVT_GET_ALL_SESSIONS

public long getCounterReceive_EVT_GET_ALL_SESSIONS()

Returns: Returns the counterReceive_EVT_GET_ALL_SESSIONS.

getCounterReceive_EVT_SESSION_ACCESSED

public long getCounterReceive_EVT_SESSION_ACCESSED()

Returns: Returns the counterReceive_EVT_SESSION_ACCESSED.

getCounterReceive_EVT_SESSION_CREATED

public long getCounterReceive_EVT_SESSION_CREATED()

Returns: Returns the counterReceive_EVT_SESSION_CREATED.

getCounterReceive_EVT_SESSION_DELTA

public long getCounterReceive_EVT_SESSION_DELTA()

Returns: Returns the counterReceive_EVT_SESSION_DELTA.

getCounterReceive_EVT_SESSION_EXPIRED

public long getCounterReceive_EVT_SESSION_EXPIRED()

Returns: Returns the counterReceive_EVT_SESSION_EXPIRED.

getCounterSend_EVT_ALL_SESSION_DATA

public long getCounterSend_EVT_ALL_SESSION_DATA()

Returns: Returns the counterSend_EVT_ALL_SESSION_DATA.

getCounterSend_EVT_ALL_SESSION_TRANSFERCOMPLETE

public int getCounterSend_EVT_ALL_SESSION_TRANSFERCOMPLETE()

Returns: Returns the counterSend_EVT_ALL_SESSION_TRANSFERCOMPLETE.

getCounterSend_EVT_GET_ALL_SESSIONS

public long getCounterSend_EVT_GET_ALL_SESSIONS()

Returns: Returns the counterSend_EVT_GET_ALL_SESSIONS.

getCounterSend_EVT_SESSION_ACCESSED

public long getCounterSend_EVT_SESSION_ACCESSED()

Returns: Returns the counterSend_EVT_SESSION_ACCESSED.

getCounterSend_EVT_SESSION_CREATED

public long getCounterSend_EVT_SESSION_CREATED()

Returns: Returns the counterSend_EVT_SESSION_CREATED.

getCounterSend_EVT_SESSION_DELTA

public long getCounterSend_EVT_SESSION_DELTA()

Returns: Returns the counterSend_EVT_SESSION_DELTA.

getCounterSend_EVT_SESSION_EXPIRED

public long getCounterSend_EVT_SESSION_EXPIRED()

Returns: Returns the counterSend_EVT_SESSION_EXPIRED.

getInfo

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

getInvalidatedSessions

public String[] getInvalidatedSessions()
When the manager expires session not tied to a request. The cluster will periodically ask for a list of sessions that should expire and that should be sent across the wire.

Returns: The invalidated sessions array

getMaxActiveSessions

public int getMaxActiveSessions()
Return the maximum number of active Sessions allowed, or -1 for no limit.

getName

public String getName()
Return the descriptive short name of this Manager implementation.

getNewDeltaSession

protected DeltaSession getNewDeltaSession()
Get new session class to be used in the doLoad() method.

getProcessingTime

public long getProcessingTime()

Returns: Returns the processingTime.

getReceivedQueueSize

public int getReceivedQueueSize()

getRejectedSessions

public int getRejectedSessions()
Number of session creations that failed due to maxActiveSessions

Returns: The count

getSendAllSessionsSize

public int getSendAllSessionsSize()

Returns: Returns the sendAllSessionsSize.

getSendAllSessionsWaitTime

public int getSendAllSessionsWaitTime()

Returns: Returns the sendAllSessionsWaitTime in msec

getSessionReplaceCounter

public long getSessionReplaceCounter()

Returns: Returns the sessionReplaceCounter.

getStateTransfered

public boolean getStateTransfered()
is session state transfered complete?

getStateTransferTimeout

public int getStateTransferTimeout()

Returns: Returns the stateTransferTimeout.

handleALL_SESSION_DATA

protected void handleALL_SESSION_DATA(SessionMessage msg, Member sender)
handle receive sessions from other not ( restart )

Parameters: msg sender

Throws: ClassNotFoundException IOException

handleALL_SESSION_TRANSFERCOMPLETE

protected void handleALL_SESSION_TRANSFERCOMPLETE(SessionMessage msg, Member sender)
handle receive session state is complete transfered

Parameters: msg sender

handleGET_ALL_SESSIONS

protected void handleGET_ALL_SESSIONS(SessionMessage msg, Member sender)
handle receive that other node want all sessions ( restart ) a) send all sessions with one message b) send session at blocks After sending send state is complete transfered

Parameters: msg sender

Throws: IOException

handleSESSION_ACCESSED

protected void handleSESSION_ACCESSED(SessionMessage msg, Member sender)
handle receive session is access at other node ( primary session is now false)

Parameters: msg sender

Throws: IOException

handleSESSION_CREATED

protected void handleSESSION_CREATED(SessionMessage msg, Member sender)
handle receive new session is created at other node (create backup - primary false)

Parameters: msg sender

handleSESSION_DELTA

protected void handleSESSION_DELTA(SessionMessage msg, Member sender)
handle receive session delta

Parameters: msg sender

Throws: IOException ClassNotFoundException

handleSESSION_EXPIRED

protected void handleSESSION_EXPIRED(SessionMessage msg, Member sender)
handle receive session is expire at other node ( expire session also here)

Parameters: msg sender

Throws: IOException

isDefaultMode

public boolean isDefaultMode()

Returns: Returns the defaultMode.

isExpireSessionsOnShutdown

public boolean isExpireSessionsOnShutdown()

isNotifyListenersOnReplication

public boolean isNotifyListenersOnReplication()

isNotifySessionListenersOnReplication

public boolean isNotifySessionListenersOnReplication()

Returns: Returns the notifySessionListenersOnReplication.

isSendAllSessions

public boolean isSendAllSessions()

Returns: Returns the sendAllSessions.

isStateTimestampDrop

public boolean isStateTimestampDrop()

Returns: Returns the stateTimestampDrop.

load

public void load()

messageDataReceived

public void messageDataReceived(ClusterMessage cmsg)
A message was received from another node, this is the callback method to implement if you are interested in receiving replication messages.

Parameters: cmsg - the message received.

messageReceived

protected void messageReceived(SessionMessage msg, Member sender)
This method is called by the received thread when a SessionMessage has been received from one of the other nodes in the cluster.

Parameters: msg - the message received sender - the sender of the message, this is used if we receive a EVT_GET_ALL_SESSION message, so that we only reply to the requesting node

propertyChange

public void propertyChange(PropertyChangeEvent event)
Process property change events from our associated Context.

Parameters: event The property change event that has occurred

registerSessionAtReplicationValve

protected void registerSessionAtReplicationValve(DeltaSession session)
Register cross context session at replication valve thread local

Parameters: session cross context session

removeLifecycleListener

public void removeLifecycleListener(LifecycleListener listener)
Remove a lifecycle event listener from this component.

Parameters: listener The listener to remove

requestCompleted

public ClusterMessage requestCompleted(String sessionId)
When the request has been completed, the replication valve will notify the manager, and the manager will decide whether any replication is needed or not. If there is a need for replication, the manager will create a session message and that will be replicated. The cluster determines where it gets sent.

Parameters: sessionId - the sessionId that just completed.

Returns: a SessionMessage to be sent,

requestCompleted

public ClusterMessage requestCompleted(String sessionId, boolean expires)
When the request has been completed, the replication valve will notify the manager, and the manager will decide whether any replication is needed or not. If there is a need for replication, the manager will create a session message and that will be replicated. The cluster determines where it gets sent. Session expiration also calls this method, but with expires == true.

Parameters: sessionId - the sessionId that just completed. expires - whether this method has been called during session expiration

Returns: a SessionMessage to be sent,

resetStatistics

public void resetStatistics()
Reset manager statistics

send

protected void send(SessionMessage msg)
Send messages to other backup member (domain or all)

Parameters: msg Session message

sendCreateSession

protected void sendCreateSession(String sessionId, DeltaSession session)
Send create session evt to all backup node

Parameters: sessionId session

sendSessions

protected void sendSessions(Member sender, Session[] currentSessions, long sendTimestamp)
send a block of session to sender

Parameters: sender currentSessions sendTimestamp

Throws: IOException

serializeDeltaRequest

protected byte[] serializeDeltaRequest(DeltaSession session, DeltaRequest deltaRequest)
serialize DeltaRequest

Parameters: deltaRequest

Returns: serialized delta request

Throws: IOException

See Also:

serializeSessions

protected byte[] serializeSessions(Session[] currentSessions)
Save any currently active sessions in the appropriate persistence mechanism, if any. If persistence is not supported, this method returns without doing anything.

Throws: IOException if an input/output error occurs

sessionExpired

protected void sessionExpired(String id)
send session expired to other cluster nodes

Parameters: id session id

setCluster

public void setCluster(CatalinaCluster cluster)

setContainer

public void setContainer(Container container)
Set the Container with which this Manager has been associated. If it is a Context (the usual case), listen for changes to the session timeout property.

Parameters: container The associated Container

setDefaultMode

public void setDefaultMode(boolean defaultMode)

Parameters: defaultMode The defaultMode to set.

setDomainReplication

public void setDomainReplication(boolean sendClusterDomainOnly)

Parameters: sendClusterDomainOnly The sendClusterDomainOnly to set.

setExpireSessionsOnShutdown

public void setExpireSessionsOnShutdown(boolean expireSessionsOnShutdown)

setMaxActiveSessions

public void setMaxActiveSessions(int max)
Set the maximum number of actives Sessions allowed, or -1 for no limit.

Parameters: max The new maximum number of sessions

setName

public void setName(String name)

setNotifyListenersOnReplication

public void setNotifyListenersOnReplication(boolean notifyListenersOnReplication)

setNotifySessionListenersOnReplication

public void setNotifySessionListenersOnReplication(boolean notifyListenersCreateSessionOnReplication)

Parameters: notifyListenersCreateSessionOnReplication The notifySessionListenersOnReplication to set.

setRejectedSessions

public void setRejectedSessions(int rejectedSessions)

setSendAllSessions

public void setSendAllSessions(boolean sendAllSessions)

Parameters: sendAllSessions The sendAllSessions to set.

setSendAllSessionsSize

public void setSendAllSessionsSize(int sendAllSessionsSize)

Parameters: sendAllSessionsSize The sendAllSessionsSize to set.

setSendAllSessionsWaitTime

public void setSendAllSessionsWaitTime(int sendAllSessionsWaitTime)

Parameters: sendAllSessionsWaitTime The sendAllSessionsWaitTime to set at msec.

setStateTimestampDrop

public void setStateTimestampDrop(boolean isTimestampDrop)

Parameters: isTimestampDrop The new flag value

setStateTransfered

public void setStateTransfered(boolean stateTransfered)
set that state ist complete transfered

Parameters: stateTransfered

setStateTransferTimeout

public void setStateTransferTimeout(int timeoutAllSession)

Parameters: timeoutAllSession The timeout

start

public void start()
Prepare for the beginning of active use of the public methods of this component. This method should be called after configure(), and before any of the public methods of the component are utilized.

Throws: LifecycleException if this component detects a fatal error that prevents this component from being used

stop

public void stop()
Gracefully terminate the active use of the public methods of this component. This method should be the last one called on a given instance of this component.

Throws: LifecycleException if this component detects a fatal error that needs to be reported

unload

public void unload()

waitForSendAllSessions

protected void waitForSendAllSessions(long beforeSendTime)
Wait that cluster session state is transfer or timeout after 60 Sec With stateTransferTimeout == -1 wait that backup is transfered (forever mode)
Copyright © 2000-2011 Apache Software Foundation. All Rights Reserved.