org.apache.catalina.cluster.tcp
Class SimpleTcpCluster

java.lang.Object
  extended byorg.apache.catalina.cluster.tcp.SimpleTcpCluster
All Implemented Interfaces:
CatalinaCluster, Cluster, Lifecycle, LifecycleListener, ListenCallback, MembershipListener

public class SimpleTcpCluster
extends java.lang.Object
implements CatalinaCluster, Lifecycle, MembershipListener, ListenCallback, LifecycleListener

A Cluster implementation using simple multicast. Responsible for setting up a cluster and provides callers with a valid multicast receiver/sender. FIXME remove install/remove/start/stop context dummys FIXME better stats FIXME factor out receiver handling FIXME Support JMX and Lifecycle Listener Notification (start/stop member) (start/stop context/manager) FIXME optimize message package creation FIXME better compress message handling FIXME Clearer implementation from notifyListenersOnReplication flag

Version:
$Revision: 1.59 $, $Date: 2005/03/25 22:11:39 $
Author:
Filip Hanik, Remy Maucherat, Peter Rossbach

Field Summary
protected  java.lang.String clusterImpName
          Name for logging purpose
protected  java.util.Vector clusterListeners
          Listeners of messages
protected  java.lang.String clusterName
          The cluster name to join
protected  Container container
          The Container associated with this Cluster.
protected  boolean expireSessionsOnShutdown
          Whether to expire sessions when shutting down
protected static java.lang.String info
          Descriptive information about this component implementation.
protected  LifecycleSupport lifecycle
          The lifecycle event support for this component.
static org.apache.commons.logging.Log log
           
protected  java.util.HashMap managers
          The context name <->manager association for distributed contexts.
protected  org.apache.catalina.cluster.tcp.SimpleTcpCluster.MemberComparator memberComparator
           
protected  MembershipService membershipService
          the service that provides the membership
protected  boolean printToScreen
          Print debug to std.out?
protected  StringManager sm
          The string manager for this package.
protected  boolean started
          Has this component been started?
protected  java.beans.PropertyChangeSupport support
          The property change support for this component.
protected  boolean useDirtyFlag
          Replicate only sessions that have been marked dirty false=replicate sessions after each request
 
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
SimpleTcpCluster()
           
 
Method Summary
 void addClusterListener(MessageListener listener)
           
 void addLifecycleListener(LifecycleListener listener)
          Add a lifecycle event listener to this component.
 void addManager(java.lang.String name, ClusterManager manager)
           
 void addValve(Valve valve)
           
 void backgroundProcess()
          Execute a periodic task, such as reloading, etc.
 Manager createManager(java.lang.String name)
          Create a new manager which will use this cluster to replicate its sessions.
protected  byte[] createMessageData(ClusterMessage msg)
          Send Message create Timestamp and generate message bytes form msg
 LifecycleListener[] findLifecycleListeners()
          Get the lifecycle listeners associated with this lifecycle.
 ClusterDeployer getClusterDeployer()
           
 java.lang.String getClusterName()
          Return the name of the cluster that this Server is currently configured to operate within.
 ClusterReceiver getClusterReceiver()
           
 ClusterSender getClusterSender()
           
 Container getContainer()
          Get the Container associated with our Cluster
 java.lang.String getInfo()
          Return descriptive information about this Cluster implementation and the corresponding version number, in the format <description>/<version>.
 long getLastChecked()
           
 Member getLocalMember()
          Return the member that represents this node.
 org.apache.commons.logging.Log getLogger()
          Returns the associates logger with this cluster
protected  javax.management.modelmbean.ModelMBean getManagedBean(java.lang.Object object)
          Returns the ModelMBean
 Manager getManager(java.lang.String name)
           
 java.lang.String getManagerClassName()
           
protected  javax.management.MBeanServer getMBeanServer()
          Get current Catalina MBean Server and load mbean registry
 Member[] getMembers()
          returns all the members currently participating in the cluster
 MembershipService getMembershipService()
           
 long getMsgSendTime()
           
 boolean getNotifyListenersOnReplication()
           
 long getNrOfMsgsReceived()
           
 javax.management.ObjectName getObjectName()
           
 java.lang.String getProtocol()
          Returns the protocol.
 Valve getValve()
           
 void installContext(java.lang.String contextPath, java.net.URL war)
          Install a new web application, whose web application archive is at the specified URL, into this container with the specified context path.
 boolean isExpireSessionsOnShutdown()
           
 boolean isPrintToScreen()
           
 boolean isUseDirtyFlag()
           
 void lifecycleEvent(LifecycleEvent lifecycleEvent)
          Acknowledge the occurrence of the specified event.
 void memberAdded(Member member)
           
 void memberDisappeared(Member member)
           
 void messageDataReceived(byte[] data)
          This method is invoked on the callback object to notify it that new data has been received from one of the cluster nodes.
protected  void registerMBeans()
          register Means at cluster
 void removeClusterListener(MessageListener listener)
           
 void removeLifecycleListener(LifecycleListener listener)
          Remove a lifecycle event listener from this component.
 void removeManager(java.lang.String name)
           
 void send(ClusterMessage msg)
          send message to all cluster members
 void send(ClusterMessage msg, Member dest)
          Sends a message to a specific member in the cluster
 void setClusterDeployer(ClusterDeployer clusterDeployer)
           
 void setClusterName(java.lang.String clusterName)
          Set the name of the cluster to join, if no cluster with this name is present create one.
 void setClusterReceiver(ClusterReceiver clusterReceiver)
           
 void setClusterSender(ClusterSender clusterSender)
           
 void setContainer(Container container)
          Set the Container associated with our Cluster
 void setExpireSessionsOnShutdown(boolean expireSessionsOnShutdown)
           
 void setManagerClassName(java.lang.String managerClassName)
           
 void setMembershipService(MembershipService membershipService)
           
 void setNotifyListenersOnReplication(boolean notifyListenersOnReplication)
           
 void setObjectName(javax.management.ObjectName name)
           
 void setPrintToScreen(boolean printToScreen)
           
 void setProtocol(java.lang.String protocol)
          Sets the configurable protocol stack.
 void setUseDirtyFlag(boolean useDirtyFlag)
           
 void start()
          Prepare for the beginning of active use of the public methods of this component.
 void startContext(java.lang.String contextPath)
          Start an existing web application, attached to the specified context path in all the other nodes in the cluster.
 void stop()
          Gracefully terminate the active use of the public methods of this component.
 void stop(java.lang.String contextPath)
          Stop an existing web application, attached to the specified context path.
protected  void unregisterMBeans()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

log

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

info

protected static final java.lang.String info
Descriptive information about this component implementation.

See Also:
Constant Field Values

membershipService

protected MembershipService membershipService
the service that provides the membership


expireSessionsOnShutdown

protected boolean expireSessionsOnShutdown
Whether to expire sessions when shutting down


printToScreen

protected boolean printToScreen
Print debug to std.out?


useDirtyFlag

protected boolean useDirtyFlag
Replicate only sessions that have been marked dirty false=replicate sessions after each request


clusterImpName

protected java.lang.String clusterImpName
Name for logging purpose


sm

protected StringManager sm
The string manager for this package.


clusterName

protected java.lang.String clusterName
The cluster name to join


container

protected Container container
The Container associated with this Cluster.


lifecycle

protected LifecycleSupport lifecycle
The lifecycle event support for this component.


started

protected boolean started
Has this component been started?


support

protected java.beans.PropertyChangeSupport support
The property change support for this component.


managers

protected java.util.HashMap managers
The context name <->manager association for distributed contexts.


memberComparator

protected org.apache.catalina.cluster.tcp.SimpleTcpCluster.MemberComparator memberComparator

clusterListeners

protected java.util.Vector clusterListeners
Listeners of messages

Constructor Detail

SimpleTcpCluster

public SimpleTcpCluster()
Method Detail

getInfo

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

Specified by:
getInfo in interface Cluster

setClusterName

public void setClusterName(java.lang.String clusterName)
Set the name of the cluster to join, if no cluster with this name is present create one.

Specified by:
setClusterName in interface Cluster
Parameters:
clusterName - The clustername to join

getClusterName

public java.lang.String getClusterName()
Return the name of the cluster that this Server is currently configured to operate within.

Specified by:
getClusterName in interface Cluster
Returns:
The name of the cluster associated with this server

setContainer

public void setContainer(Container container)
Set the Container associated with our Cluster

Specified by:
setContainer in interface Cluster
Parameters:
container - The Container to use

getContainer

public Container getContainer()
Get the Container associated with our Cluster

Specified by:
getContainer in interface Cluster
Returns:
The Container associated with our Cluster

setProtocol

public void setProtocol(java.lang.String protocol)
Sets the configurable protocol stack. This is a setting in server.xml where you can configure your protocol.

Specified by:
setProtocol in interface Cluster
Parameters:
protocol - the protocol stack - this method is called by the server configuration at startup
See Also:
JavaGroups for details

getProtocol

public java.lang.String getProtocol()
Returns the protocol.

Specified by:
getProtocol in interface Cluster
Returns:
The protocol

getMembers

public Member[] getMembers()
Description copied from interface: CatalinaCluster
returns all the members currently participating in the cluster

Specified by:
getMembers in interface CatalinaCluster
Returns:
Member[]

getLocalMember

public Member getLocalMember()
Return the member that represents this node.

Specified by:
getLocalMember in interface CatalinaCluster
Returns:
Member

createManager

public Manager createManager(java.lang.String name)
Description copied from interface: Cluster
Create a new manager which will use this cluster to replicate its sessions.

Specified by:
createManager in interface Cluster
Parameters:
name - Name (key) of the application with which the manager is associated

removeManager

public void removeManager(java.lang.String name)
Specified by:
removeManager in interface CatalinaCluster

addManager

public void addManager(java.lang.String name,
                       ClusterManager manager)
Specified by:
addManager in interface CatalinaCluster

getManager

public Manager getManager(java.lang.String name)
Specified by:
getManager in interface CatalinaCluster

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

backgroundProcess

public void backgroundProcess()
Execute a periodic task, such as reloading, etc. This method will be invoked inside the classloading context of this container. Unexpected throwables will be caught and logged.

Specified by:
backgroundProcess in interface Cluster

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.
Starts the cluster communication channel, this will connect with the other nodes in the cluster, and request the current session state to be transferred to this node. FIXME notify someone (JMX(Listener)

Specified by:
start in interface CatalinaCluster
Throws:
java.lang.IllegalStateException - if this component has already been started
LifecycleException - if this component detects a fatal error that prevents this component from being used

send

public void send(ClusterMessage msg,
                 Member dest)
Description copied from interface: CatalinaCluster
Sends a message to a specific member in the cluster

Specified by:
send in interface CatalinaCluster
Parameters:
msg - SessionMessage
dest - Member

createMessageData

protected byte[] createMessageData(ClusterMessage msg)
                            throws java.io.IOException
Send Message create Timestamp and generate message bytes form msg

Parameters:
msg - cluster message
Returns:
cluster message as byte array
Throws:
java.io.IOException

send

public void send(ClusterMessage msg)
send message to all cluster members

Specified by:
send in interface CatalinaCluster
Parameters:
msg - SessionMessage
See Also:
CatalinaCluster.send(org.apache.catalina.cluster.ClusterMessage)

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.
This will disconnect the cluster communication channel and stop the listener thread. FIXME notify someone (JMX(Listener)

Specified by:
stop in interface CatalinaCluster
Throws:
java.lang.IllegalStateException - if this component has not been started
LifecycleException - if this component detects a fatal error that needs to be reported

memberAdded

public void memberAdded(Member member)
Specified by:
memberAdded in interface MembershipListener

memberDisappeared

public void memberDisappeared(Member member)
Specified by:
memberDisappeared in interface MembershipListener

setExpireSessionsOnShutdown

public void setExpireSessionsOnShutdown(boolean expireSessionsOnShutdown)

setPrintToScreen

public void setPrintToScreen(boolean printToScreen)

getMsgSendTime

public long getMsgSendTime()
Returns:
Returns the msgSendTime.

getLastChecked

public long getLastChecked()
Returns:
Returns the lastChecked.

getNrOfMsgsReceived

public long getNrOfMsgsReceived()
Returns:
Returns the nrOfMsgsReceived.

isExpireSessionsOnShutdown

public boolean isExpireSessionsOnShutdown()
Returns:
Returns the expireSessionsOnShutdown.

isPrintToScreen

public boolean isPrintToScreen()
Returns:
Returns the printToScreen.

isUseDirtyFlag

public boolean isUseDirtyFlag()
Returns:
Returns the useDirtyFlag.

setUseDirtyFlag

public void setUseDirtyFlag(boolean useDirtyFlag)

messageDataReceived

public void messageDataReceived(byte[] data)
Description copied from interface: ListenCallback
This method is invoked on the callback object to notify it that new data has been received from one of the cluster nodes.

Specified by:
messageDataReceived in interface ListenCallback
Parameters:
data - - the message bytes received from the cluster/replication system

lifecycleEvent

public void lifecycleEvent(LifecycleEvent lifecycleEvent)
Description copied from interface: LifecycleListener
Acknowledge the occurrence of the specified event.

Specified by:
lifecycleEvent in interface LifecycleListener
Parameters:
lifecycleEvent - LifecycleEvent that has occurred

startContext

public void startContext(java.lang.String contextPath)
                  throws java.io.IOException
Start an existing web application, attached to the specified context path in all the other nodes in the cluster. Only starts a web application if it is not running.

Specified by:
startContext in interface Cluster
Parameters:
contextPath - The context path of the application to be started
Throws:
java.lang.IllegalArgumentException - if the specified context path is malformed (it must be "" or start with a slash)
java.lang.IllegalArgumentException - if the specified context path does not identify a currently installed web application
java.io.IOException - if an input/output error occurs during startup

installContext

public void installContext(java.lang.String contextPath,
                           java.net.URL war)
Install a new web application, whose web application archive is at the specified URL, into this container with the specified context path. A context path of "" (the empty string) should be used for the root application for this container. Otherwise, the context path must start with a slash.

If this application is successfully installed, a ContainerEvent of type PRE_INSTALL_EVENT will be sent to registered listeners before the associated Context is started, and a ContainerEvent of type INSTALL_EVENT will be sent to all registered listeners after the associated Context is started, with the newly created Context as an argument.

Specified by:
installContext in interface Cluster
Parameters:
contextPath - The context path to which this application should be installed (must be unique)
war - A URL of type "jar:" that points to a WAR file, or type "file:" that points to an unpacked directory structure containing the web application to be installed
Throws:
java.lang.IllegalArgumentException - if the specified context path is malformed (it must be "" or start with a slash)
java.lang.IllegalStateException - if the specified context path is already attached to an existing web application

stop

public void stop(java.lang.String contextPath)
          throws java.io.IOException
Stop an existing web application, attached to the specified context path. Only stops a web application if it is running.

Specified by:
stop in interface Cluster
Parameters:
contextPath - The context path of the application to be stopped
Throws:
java.lang.IllegalArgumentException - if the specified context path is malformed (it must be "" or start with a slash)
java.lang.IllegalArgumentException - if the specified context path does not identify a currently installed web application
java.io.IOException - if an input/output error occurs while stopping the web application

getLogger

public org.apache.commons.logging.Log getLogger()
Description copied from interface: CatalinaCluster
Returns the associates logger with this cluster

Specified by:
getLogger in interface CatalinaCluster
Returns:
Log

getManagerClassName

public java.lang.String getManagerClassName()

setManagerClassName

public void setManagerClassName(java.lang.String managerClassName)

getClusterSender

public ClusterSender getClusterSender()
Specified by:
getClusterSender in interface CatalinaCluster

setClusterSender

public void setClusterSender(ClusterSender clusterSender)
Specified by:
setClusterSender in interface CatalinaCluster

getClusterReceiver

public ClusterReceiver getClusterReceiver()
Specified by:
getClusterReceiver in interface CatalinaCluster

setClusterReceiver

public void setClusterReceiver(ClusterReceiver clusterReceiver)
Specified by:
setClusterReceiver in interface CatalinaCluster

getMembershipService

public MembershipService getMembershipService()
Specified by:
getMembershipService in interface CatalinaCluster

setMembershipService

public void setMembershipService(MembershipService membershipService)
Specified by:
setMembershipService in interface CatalinaCluster

addValve

public void addValve(Valve valve)
Specified by:
addValve in interface CatalinaCluster

getValve

public Valve getValve()
Specified by:
getValve in interface CatalinaCluster

addClusterListener

public void addClusterListener(MessageListener listener)
Specified by:
addClusterListener in interface CatalinaCluster

removeClusterListener

public void removeClusterListener(MessageListener listener)
Specified by:
removeClusterListener in interface CatalinaCluster

getClusterDeployer

public ClusterDeployer getClusterDeployer()
Specified by:
getClusterDeployer in interface CatalinaCluster

setClusterDeployer

public void setClusterDeployer(ClusterDeployer clusterDeployer)
Specified by:
setClusterDeployer in interface CatalinaCluster

getNotifyListenersOnReplication

public boolean getNotifyListenersOnReplication()

setNotifyListenersOnReplication

public void setNotifyListenersOnReplication(boolean notifyListenersOnReplication)

registerMBeans

protected void registerMBeans()
register Means at cluster


unregisterMBeans

protected void unregisterMBeans()

getMBeanServer

protected javax.management.MBeanServer getMBeanServer()
                                               throws java.lang.Exception
Get current Catalina MBean Server and load mbean registry

Returns:
Throws:
java.lang.Exception

getManagedBean

protected javax.management.modelmbean.ModelMBean getManagedBean(java.lang.Object object)
                                                         throws java.lang.Exception
Returns the ModelMBean

Parameters:
object - The Object to get the ModelMBean for
Returns:
The ModelMBean
Throws:
java.lang.Exception - If an error occurs this constructors throws this exception

setObjectName

public void setObjectName(javax.management.ObjectName name)

getObjectName

public javax.management.ObjectName getObjectName()


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