org.apache.catalina.cluster.session
Class DeltaManager

java.lang.Object
  extended byorg.apache.catalina.session.ManagerBase
      extended byorg.apache.catalina.cluster.session.DeltaManager
All Implemented Interfaces:
ClusterManager, java.util.EventListener, Lifecycle, Manager, javax.management.MBeanRegistration, java.beans.PropertyChangeListener

public class DeltaManager
extends ManagerBase
implements Lifecycle, java.beans.PropertyChangeListener, ClusterManager

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: 1.36 $ $Date: 2004/11/22 14:51:18 $
Author:
Filip Hanik, Craig R. McClanahan, Jean-Francois Arcand

Field Summary
protected  LifecycleSupport lifecycle
          The lifecycle event support for this component.
static org.apache.commons.logging.Log log
           
protected static java.lang.String managerName
          The descriptive name of this Manager implementation (for logging).
protected  java.lang.String name
           
 
Fields inherited from class org.apache.catalina.session.ManagerBase
algorithm, container, DEFAULT_ALGORITHM, devRandomSource, digest, distributable, domain, duplicates, entropy, initialized, maxActive, maxInactiveInterval, mserver, oname, processExpiresFrequency, random, randomClass, randomIS, sessionAverageAliveTime, sessionCounter, sessionIdLength, sessionMaxAliveTime, sessions, sm, support
 
Fields inherited from interface org.apache.catalina.Lifecycle
AFTER_START_EVENT, AFTER_STOP_EVENT, BEFORE_START_EVENT, BEFORE_STOP_EVENT, DESTROY_EVENT, INIT_EVENT, PERIODIC_EVENT, START_EVENT, STOP_EVENT
 
Constructor Summary
DeltaManager()
           
 
Method Summary
 void addLifecycleListener(LifecycleListener listener)
          Add a lifecycle event listener to this component.
 Session createSession()
          Construct and return a new session object, based on the default settings specified by this Manager's properties.
 Session createSession(boolean distribute)
          create new session with check maxActiveSessions and send session creation to other cluster nodes.
 LifecycleListener[] findLifecycleListeners()
          Get the lifecycle listeners associated with this lifecycle.
 CatalinaCluster getCluster()
           
 boolean getExpireSessionsOnShutdown()
           
 java.lang.String getInfo()
          Return descriptive information about this Manager implementation and the corresponding version number, in the format <description>/<version>.
 java.lang.String[] getInvalidatedSessions()
          When the manager expires session not tied to a request.
 int getMaxActiveSessions()
          Return the maximum number of active Sessions allowed, or -1 for no limit.
 java.lang.String getName()
          Return the descriptive short name of this Manager implementation.
protected  DeltaSession getNewDeltaSession()
          Get new session class to be used in the doLoad() method.
 boolean getNotifyListenersOnReplication()
           
 boolean getPrintToScreen()
           
 int getRejectedSessions()
          Number of session creations that failed due to maxActiveSessions
 boolean getStateTransferred()
           
 boolean getUseDirtyFlag()
           
 void load()
          Load any currently active sessions that were previously unloaded to the appropriate persistence mechanism, if any.
 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.
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.
 void propertyChange(java.beans.PropertyChangeEvent event)
          Process property change events from our associated Context.
 void removeLifecycleListener(LifecycleListener listener)
          Remove a lifecycle event listener from this component.
 ClusterMessage requestCompleted(java.lang.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.
protected  void sessionExpired(java.lang.String id)
          send session expired to other cluster nodes
 void setCluster(CatalinaCluster cluster)
           
 void setContainer(Container container)
          Set the Container with which this Manager has been associated.
 void setExpireSessionsOnShutdown(boolean expireSessionsOnShutdown)
           
 void setMaxActiveSessions(int max)
          Set the maximum number of actives Sessions allowed, or -1 for no limit.
 void setName(java.lang.String name)
           
 void setNotifyListenersOnReplication(boolean notifyListenersOnReplication)
           
 void setPrintToScreen(boolean printToScreen)
           
 void setRejectedSessions(int rejectedSessions)
          Sets the number of sessions that were not created because the maximum number of active sessions was reached.
 void setStateTransferred(boolean stateTransferred)
           
 void setUseDirtyFlag(boolean useDirtyFlag)
           
 void start()
          Prepare for the beginning of active use of the public methods of this component.
 void stop()
          Gracefully terminate the active use of the public methods of this component.
 void unload()
          Save any currently active sessions in the appropriate persistence mechanism, if any.
 
Methods inherited from class org.apache.catalina.session.ManagerBase
add, addPropertyChangeListener, backgroundProcess, createEmptySession, destroy, expireSession, findSession, findSessions, generateSessionId, getActiveSessions, getAlgorithm, getClassName, getContainer, getDigest, getDistributable, getDomain, getDuplicates, getEngine, getEntropy, getExpiredSessions, getJvmRoute, getLastAccessedTime, getMaxActive, getMaxInactiveInterval, getNewSession, getObjectName, getProcessExpiresFrequency, getProcessingTime, getRandom, getRandomBytes, getRandomClass, getRandomFile, getSessionAttribute, getSessionAverageAliveTime, getSessionCounter, getSessionIdLength, getSessionMaxAliveTime, init, listSessionIds, postDeregister, postRegister, preDeregister, preRegister, processExpires, remove, removePropertyChangeListener, setAlgorithm, setDistributable, setDuplicates, setEntropy, setExpiredSessions, setMaxActive, setMaxInactiveInterval, setProcessExpiresFrequency, setProcessingTime, setRandomClass, setRandomFile, setSessionAverageAliveTime, setSessionCounter, setSessionIdLength, setSessionMaxAliveTime
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.apache.catalina.Manager
add, addPropertyChangeListener, backgroundProcess, createEmptySession, findSession, findSessions, getActiveSessions, getContainer, getDistributable, getExpiredSessions, getMaxActive, getMaxInactiveInterval, getSessionAverageAliveTime, getSessionCounter, getSessionIdLength, getSessionMaxAliveTime, remove, removePropertyChangeListener, setDistributable, setExpiredSessions, setMaxActive, setMaxInactiveInterval, setSessionAverageAliveTime, setSessionCounter, setSessionIdLength, setSessionMaxAliveTime
 

Field Detail

log

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

lifecycle

protected LifecycleSupport lifecycle
The lifecycle event support for this component.


managerName

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


name

protected java.lang.String name
Constructor Detail

DeltaManager

public DeltaManager()
Method Detail

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.

Specified by:
setContainer in interface Manager
Overrides:
setContainer in class ManagerBase
Parameters:
container - The associated Container

getInfo

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

Specified by:
getInfo in interface Manager
Overrides:
getInfo in class ManagerBase

getMaxActiveSessions

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


getRejectedSessions

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

Specified by:
getRejectedSessions in interface Manager
Returns:
The count

setRejectedSessions

public void setRejectedSessions(int rejectedSessions)
Description copied from interface: Manager
Sets the number of sessions that were not created because the maximum number of active sessions was reached.

Specified by:
setRejectedSessions in interface Manager
Parameters:
rejectedSessions - Number of rejected sessions

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

getName

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

Specified by:
getName in interface ClusterManager
Overrides:
getName in class ManagerBase

createSession

public Session createSession()
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.

Specified by:
createSession in interface Manager
Overrides:
createSession in class ManagerBase
Throws:
java.lang.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.
java.lang.IllegalStateException - if a new session cannot be instantiated for any reason

createSession

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

Parameters:
distribute -
Returns:

getNewDeltaSession

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


addLifecycleListener

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

Specified by:
addLifecycleListener in interface Lifecycle
Parameters:
listener - The listener to add

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.

Specified by:
findLifecycleListeners in interface Lifecycle

removeLifecycleListener

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

Specified by:
removeLifecycleListener in interface Lifecycle
Parameters:
listener - The listener to remove

start

public void start()
           throws LifecycleException
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.

Specified by:
start in interface Lifecycle
Throws:
LifecycleException - if this component detects a fatal error that prevents this component from being used

stop

public void stop()
          throws LifecycleException
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.

Specified by:
stop in interface Lifecycle
Throws:
LifecycleException - if this component detects a fatal error that needs to be reported

propertyChange

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

Specified by:
propertyChange in interface java.beans.PropertyChangeListener
Parameters:
event - The property change event that has occurred

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.

Specified by:
messageDataReceived in interface ClusterManager
Parameters:
cmsg - - the message received.

requestCompleted

public ClusterMessage requestCompleted(java.lang.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.

Specified by:
requestCompleted in interface ClusterManager
Parameters:
sessionId - - the sessionId that just completed.
Returns:
a SessionMessage to be sent,

sessionExpired

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

Parameters:
id - session id

getInvalidatedSessions

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

Specified by:
getInvalidatedSessions in interface ClusterManager
Returns:

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

getStateTransferred

public boolean getStateTransferred()

setStateTransferred

public void setStateTransferred(boolean stateTransferred)

getCluster

public CatalinaCluster getCluster()

setCluster

public void setCluster(CatalinaCluster cluster)
Specified by:
setCluster in interface ClusterManager

load

public void load()
Description copied from interface: Manager
Load any currently active sessions that were previously unloaded to the appropriate persistence mechanism, if any. If persistence is not supported, this method returns without doing anything.

Specified by:
load in interface Manager

unload

public void unload()
Description copied from interface: Manager
Save any currently active sessions in the appropriate persistence mechanism, if any. If persistence is not supported, this method returns without doing anything.

Specified by:
unload in interface Manager

getUseDirtyFlag

public boolean getUseDirtyFlag()

setUseDirtyFlag

public void setUseDirtyFlag(boolean useDirtyFlag)
Specified by:
setUseDirtyFlag in interface ClusterManager

getExpireSessionsOnShutdown

public boolean getExpireSessionsOnShutdown()

setExpireSessionsOnShutdown

public void setExpireSessionsOnShutdown(boolean expireSessionsOnShutdown)
Specified by:
setExpireSessionsOnShutdown in interface ClusterManager

getPrintToScreen

public boolean getPrintToScreen()

setPrintToScreen

public void setPrintToScreen(boolean printToScreen)

setName

public void setName(java.lang.String name)
Specified by:
setName in interface ClusterManager

getNotifyListenersOnReplication

public boolean getNotifyListenersOnReplication()
Specified by:
getNotifyListenersOnReplication in interface ClusterManager

setNotifyListenersOnReplication

public void setNotifyListenersOnReplication(boolean notifyListenersOnReplication)
Specified by:
setNotifyListenersOnReplication in interface ClusterManager


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