Apache Tomcat 6.0.53

org.apache.catalina.ha.tcp
Class SimpleTcpCluster

java.lang.Object
  extended by org.apache.catalina.ha.tcp.SimpleTcpCluster
All Implemented Interfaces:
Cluster, CatalinaCluster, IDynamicProperty, Lifecycle, LifecycleListener, ChannelListener, MembershipListener

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

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 wrote testcases

Author:
Filip Hanik, Remy Maucherat, Peter Rossbach

Field Summary
static java.lang.String AFTER_MANAGERREGISTER_EVENT
           
static java.lang.String AFTER_MANAGERUNREGISTER_EVENT
           
static java.lang.String AFTER_MEMBERREGISTER_EVENT
           
static java.lang.String AFTER_MEMBERUNREGISTER_EVENT
           
static java.lang.String BEFORE_MANAGERREGISTER_EVENT
           
static java.lang.String BEFORE_MANAGERUNREGISTER_EVENT
           
static java.lang.String BEFORE_MEMBERREGISTER_EVENT
           
static java.lang.String BEFORE_MEMBERUNREGISTER_EVENT
           
protected  Channel channel
          Group channel.
protected  java.lang.String clusterImpName
          Name for logging purpose
protected  java.util.List 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 hasMembers
          has members
protected  boolean heartbeatBackgroundEnabled
          call Channel.heartbeat() at container background thread
protected static java.lang.String info
          Descriptive information about this component implementation.
protected  LifecycleSupport lifecycle
          The lifecycle event support for this component.
static Log log
           
protected  java.util.Map managers
          The context name <->manager association for distributed contexts.
protected  ClusterManager managerTemplate
           
static java.lang.String RECEIVE_MESSAGE_FAILURE_EVENT
           
static java.lang.String SEND_MESSAGE_FAILURE_EVENT
           
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.
 
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
 boolean accept(java.io.Serializable msg, Member sender)
          Notify all listeners from receiving a new message is not ClusterMessage and emit Failure Event to LifecylceListener
 void addClusterListener(ClusterListener listener)
          add cluster message listener and register cluster to this listener
 void addLifecycleListener(LifecycleListener listener)
          Add a lifecycle event listener to this component.
 void addValve(Valve valve)
          Add cluster valve Cluster Valves are only add to container when cluster is started!
 void backgroundProcess()
          Execute a periodic task, such as reloading, etc.
protected  void checkDefaults()
           
 Manager createManager(java.lang.String name)
          Create new Manager without add to cluster (comes with start the manager)
 ClusterListener[] findClusterListeners()
          Get the cluster listeners associated with this cluster.
 LifecycleListener[] findLifecycleListeners()
          Get the lifecycle listeners associated with this lifecycle.
 Channel getChannel()
           
 int getChannelSendOptions()
           
 int getChannelStartOptions()
           
 ClusterDeployer getClusterDeployer()
          get current Deployer
 java.lang.String getClusterName()
          Return the name of the cluster that this Server is currently configured to operate within.
 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>.
 Member getLocalMember()
          Return the member that represents this node.
 Log getLogger()
          Returns the associates logger with this cluster.
 Manager getManager(java.lang.String name)
           
 java.lang.String getManagerClassName()
          Deprecated. use getManagerTemplate().getClass().getName() instead.
 java.lang.String getManagerName(java.lang.String name, Manager manager)
           
 java.util.Map getManagers()
           
 ClusterManager getManagerTemplate()
           
 Member[] getMembers()
          Get all current cluster members
 java.lang.Object getProperty(java.lang.String key)
          get current config
 java.util.Iterator getPropertyNames()
          Get all properties keys
 java.lang.String getProtocol()
          Get the protocol used by the cluster.
 Valve[] getValves()
          get all cluster valves
 boolean hasMembers()
          Returns that cluster has members.
 boolean isHeartbeatBackgroundEnabled()
          Return heartbeat enable flag (default false)
 boolean isNotifyLifecycleListenerOnFailure()
           
 void lifecycleEvent(LifecycleEvent lifecycleEvent)
          Use as base to handle start/stop/periodic Events from host.
 void memberAdded(Member member)
          New cluster member is registered
 void memberDisappeared(Member member)
          Cluster member is gone
 void messageReceived(ClusterMessage message)
           
 void messageReceived(java.io.Serializable message, Member sender)
          Receive a message from the channel
protected  void registerClusterValve()
          register all cluster valve to host or engine
 void registerManager(Manager manager)
          Register a manager with the cluster.
 void removeClusterListener(ClusterListener listener)
          remove message listener and deregister Cluster from listener
 void removeLifecycleListener(LifecycleListener listener)
          Remove a lifecycle event listener from this component.
 void removeManager(Manager manager)
          remove an application form cluster replication bus
 void removeProperty(java.lang.String key)
          remove a configured property.
 void send(ClusterMessage msg)
          send message to all cluster members
 void send(ClusterMessage msg, Member dest)
          send a cluster message to one member
 void sendClusterDomain(ClusterMessage msg)
          send message to all cluster members same cluster domain
 void setChannel(Channel channel)
           
 void setChannelSendOptions(int channelSendOptions)
           
 void setChannelStartOptions(int channelStartOptions)
           
 void setClusterDeployer(ClusterDeployer clusterDeployer)
          set a new Deployer, must be set before cluster started!
 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 setContainer(Container container)
          Set the Container associated with our Cluster
 void setHeartbeatBackgroundEnabled(boolean heartbeatBackgroundEnabled)
          enabled that container backgroundThread call heartbeat at channel
 void setManagerClassName(java.lang.String managerClassName)
          Deprecated. use nested <Manager> element inside the cluster config instead.
 void setManagerTemplate(ClusterManager managerTemplate)
           
 void setNotifyLifecycleListenerOnFailure(boolean notifyListenerOnFailure)
           
 boolean setProperty(java.lang.String name, java.lang.Object value)
          set config attributes with reflect and propagate to all managers
 boolean setProperty(java.lang.String name, java.lang.String value)
          JMX hack to direct use at jconsole
 void setProtocol(java.lang.String protocol)
          Set the protocol parameters.
 void start()
          Prepare for the beginning of active use of the public methods of this component.
 void stop()
          Gracefully terminate the active cluster component.
protected  void transferProperty(java.lang.String prefix, java.lang.Object bean)
          transfer properties from cluster configuration to subelement bean.
protected  void unregisterClusterValve()
          unregister all cluster valve to host or engine
 
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.tribes.ChannelListener
equals, hashCode
 

Field Detail

log

public static Log log

info

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

See Also:
Constant Field Values

BEFORE_MEMBERREGISTER_EVENT

public static final java.lang.String BEFORE_MEMBERREGISTER_EVENT
See Also:
Constant Field Values

AFTER_MEMBERREGISTER_EVENT

public static final java.lang.String AFTER_MEMBERREGISTER_EVENT
See Also:
Constant Field Values

BEFORE_MANAGERREGISTER_EVENT

public static final java.lang.String BEFORE_MANAGERREGISTER_EVENT
See Also:
Constant Field Values

AFTER_MANAGERREGISTER_EVENT

public static final java.lang.String AFTER_MANAGERREGISTER_EVENT
See Also:
Constant Field Values

BEFORE_MANAGERUNREGISTER_EVENT

public static final java.lang.String BEFORE_MANAGERUNREGISTER_EVENT
See Also:
Constant Field Values

AFTER_MANAGERUNREGISTER_EVENT

public static final java.lang.String AFTER_MANAGERUNREGISTER_EVENT
See Also:
Constant Field Values

BEFORE_MEMBERUNREGISTER_EVENT

public static final java.lang.String BEFORE_MEMBERUNREGISTER_EVENT
See Also:
Constant Field Values

AFTER_MEMBERUNREGISTER_EVENT

public static final java.lang.String AFTER_MEMBERUNREGISTER_EVENT
See Also:
Constant Field Values

SEND_MESSAGE_FAILURE_EVENT

public static final java.lang.String SEND_MESSAGE_FAILURE_EVENT
See Also:
Constant Field Values

RECEIVE_MESSAGE_FAILURE_EVENT

public static final java.lang.String RECEIVE_MESSAGE_FAILURE_EVENT
See Also:
Constant Field Values

channel

protected Channel channel
Group channel.


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


heartbeatBackgroundEnabled

protected boolean heartbeatBackgroundEnabled
call Channel.heartbeat() at container background thread

See Also:
GroupChannel.heartbeat()

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.Map managers
The context name <->manager association for distributed contexts.


managerTemplate

protected ClusterManager managerTemplate

clusterListeners

protected java.util.List clusterListeners
Listeners of messages


hasMembers

protected boolean hasMembers
has members

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

isHeartbeatBackgroundEnabled

public boolean isHeartbeatBackgroundEnabled()
Return heartbeat enable flag (default false)

Returns:
the heartbeatBackgroundEnabled

setHeartbeatBackgroundEnabled

public void setHeartbeatBackgroundEnabled(boolean heartbeatBackgroundEnabled)
enabled that container backgroundThread call heartbeat at channel

Parameters:
heartbeatBackgroundEnabled - the heartbeatBackgroundEnabled to set

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

isNotifyLifecycleListenerOnFailure

public boolean isNotifyLifecycleListenerOnFailure()
Returns:
Returns the notifyLifecycleListenerOnFailure.

setNotifyLifecycleListenerOnFailure

public void setNotifyLifecycleListenerOnFailure(boolean notifyListenerOnFailure)
Parameters:
notifyListenerOnFailure - The notifyLifecycleListenerOnFailure to set.

getManagerClassName

public java.lang.String getManagerClassName()
Deprecated. use getManagerTemplate().getClass().getName() instead.

Returns:
String

setManagerClassName

public void setManagerClassName(java.lang.String managerClassName)
Deprecated. use nested <Manager> element inside the cluster config instead.

Parameters:
managerClassName - String

addValve

public void addValve(Valve valve)
Add cluster valve Cluster Valves are only add to container when cluster is started!

Specified by:
addValve in interface CatalinaCluster
Parameters:
valve - The new cluster Valve.

getValves

public Valve[] getValves()
get all cluster valves

Specified by:
getValves in interface CatalinaCluster
Returns:
current cluster valves

findClusterListeners

public ClusterListener[] findClusterListeners()
Get the cluster listeners associated with this cluster. If this Array has no listeners registered, a zero-length array is returned.


addClusterListener

public void addClusterListener(ClusterListener listener)
add cluster message listener and register cluster to this listener

Specified by:
addClusterListener in interface CatalinaCluster
See Also:
CatalinaCluster.addClusterListener(org.apache.catalina.ha.ClusterListener)

removeClusterListener

public void removeClusterListener(ClusterListener listener)
remove message listener and deregister Cluster from listener

Specified by:
removeClusterListener in interface CatalinaCluster
See Also:
CatalinaCluster.removeClusterListener(org.apache.catalina.ha.ClusterListener)

getClusterDeployer

public ClusterDeployer getClusterDeployer()
get current Deployer

Specified by:
getClusterDeployer in interface CatalinaCluster

setClusterDeployer

public void setClusterDeployer(ClusterDeployer clusterDeployer)
set a new Deployer, must be set before cluster started!

Specified by:
setClusterDeployer in interface CatalinaCluster

setChannel

public void setChannel(Channel channel)
Specified by:
setChannel in interface CatalinaCluster

setManagerTemplate

public void setManagerTemplate(ClusterManager managerTemplate)

setChannelSendOptions

public void setChannelSendOptions(int channelSendOptions)

hasMembers

public boolean hasMembers()
Description copied from interface: CatalinaCluster
Returns that cluster has members.

Specified by:
hasMembers in interface CatalinaCluster

getMembers

public Member[] getMembers()
Get all current cluster members

Specified by:
getMembers in interface CatalinaCluster
Returns:
all members or empty array

getLocalMember

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

Specified by:
getLocalMember in interface CatalinaCluster
Returns:
Member

setProperty

public boolean setProperty(java.lang.String name,
                           java.lang.String value)
JMX hack to direct use at jconsole

Parameters:
name -
value -

setProperty

public boolean setProperty(java.lang.String name,
                           java.lang.Object value)
set config attributes with reflect and propagate to all managers

Specified by:
setProperty in interface IDynamicProperty
Parameters:
name -
value -

getProperty

public java.lang.Object getProperty(java.lang.String key)
get current config

Specified by:
getProperty in interface IDynamicProperty
Parameters:
key -
Returns:
The property

getPropertyNames

public java.util.Iterator getPropertyNames()
Get all properties keys

Specified by:
getPropertyNames in interface IDynamicProperty
Returns:
An iterator over the property names.

removeProperty

public void removeProperty(java.lang.String key)
remove a configured property.

Specified by:
removeProperty in interface IDynamicProperty
Parameters:
key -

transferProperty

protected void transferProperty(java.lang.String prefix,
                                java.lang.Object bean)
transfer properties from cluster configuration to subelement bean.

Parameters:
prefix -
bean -

getManagers

public java.util.Map getManagers()
Specified by:
getManagers in interface CatalinaCluster
Returns:
Returns the managers.

getChannel

public Channel getChannel()
Specified by:
getChannel in interface CatalinaCluster

getManagerTemplate

public ClusterManager getManagerTemplate()

getChannelSendOptions

public int getChannelSendOptions()

createManager

public Manager createManager(java.lang.String name)
Create new Manager without add to cluster (comes with start the manager)

Specified by:
createManager in interface Cluster
Parameters:
name - Context Name of this manager
See Also:
Cluster.createManager(java.lang.String), registerManager(Manager), DeltaManager.start()

registerManager

public void registerManager(Manager manager)
Description copied from interface: Cluster
Register a manager with the cluster. If the cluster is not responsible for creating a manager, then the container will at least notify the cluster that this mananger is participating in the cluster.

Specified by:
registerManager in interface Cluster
Parameters:
manager - Manager

removeManager

public void removeManager(Manager manager)
remove an application form cluster replication bus

Specified by:
removeManager in interface Cluster
Parameters:
manager - Manager
See Also:
Cluster.removeManager(Manager)

getManagerName

public java.lang.String getManagerName(java.lang.String name,
                                       Manager manager)
Specified by:
getManagerName in interface CatalinaCluster

getManager

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

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
See Also:
FarmWarDeployer.backgroundProcess(), GroupChannel.heartbeat(), GroupChannel.HeartbeatThread.run()

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

lifecycleEvent

public void lifecycleEvent(LifecycleEvent lifecycleEvent)
Use as base to handle start/stop/periodic Events from host. Currently only log the messages as trace level.

Specified by:
lifecycleEvent in interface LifecycleListener
Parameters:
lifecycleEvent - LifecycleEvent that has occurred
See Also:
LifecycleListener.lifecycleEvent(org.apache.catalina.LifecycleEvent)

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.

Specified by:
start in interface CatalinaCluster
Specified by:
start in interface Lifecycle
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

checkDefaults

protected void checkDefaults()

registerClusterValve

protected void registerClusterValve()
                             throws java.lang.Exception
register all cluster valve to host or engine

Throws:
java.lang.Exception
java.lang.ClassNotFoundException

unregisterClusterValve

protected void unregisterClusterValve()
                               throws java.lang.Exception
unregister all cluster valve to host or engine

Throws:
java.lang.Exception
java.lang.ClassNotFoundException

stop

public void stop()
          throws LifecycleException
Gracefully terminate the active cluster component.
This will disconnect the cluster communication channel, stop the listener and deregister the valves from host or engine.

Note:
The sub elements receiver, sender, membership, listener or valves are not removed. You can easily start the cluster again.

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

send

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

Specified by:
send in interface CatalinaCluster
Parameters:
msg - message to transfer
See Also:
CatalinaCluster.send(ClusterMessage)

sendClusterDomain

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

Specified by:
sendClusterDomain in interface CatalinaCluster
Parameters:
msg - ClusterMessage
See Also:
CatalinaCluster.send(ClusterMessage)

send

public void send(ClusterMessage msg,
                 Member dest)
send a cluster message to one member

Specified by:
send in interface CatalinaCluster
Parameters:
msg - message to transfer
dest - Receiver member
See Also:
CatalinaCluster.send(ClusterMessage,Member)

memberAdded

public void memberAdded(Member member)
New cluster member is registered

Specified by:
memberAdded in interface MembershipListener
Parameters:
member - Member - the member that was added
See Also:
MembershipListener.memberAdded(Member)

memberDisappeared

public void memberDisappeared(Member member)
Cluster member is gone

Specified by:
memberDisappeared in interface MembershipListener
Parameters:
member - Member
See Also:
MembershipListener.memberDisappeared(Member)

accept

public boolean accept(java.io.Serializable msg,
                      Member sender)
Notify all listeners from receiving a new message is not ClusterMessage and emit Failure Event to LifecylceListener

Specified by:
accept in interface ChannelListener
Parameters:
msg - received Message
sender - Member
Returns:
boolean

messageReceived

public void messageReceived(java.io.Serializable message,
                            Member sender)
Description copied from interface: ChannelListener
Receive a message from the channel

Specified by:
messageReceived in interface ChannelListener
Parameters:
message - Serializable
sender - - the source of the message

messageReceived

public void messageReceived(ClusterMessage message)

getLogger

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

Specified by:
getLogger in interface CatalinaCluster
Returns:
Log

setProtocol

public void setProtocol(java.lang.String protocol)
Description copied from interface: Cluster
Set the protocol parameters.

Specified by:
setProtocol in interface Cluster
Parameters:
protocol - The protocol used by the cluster
See Also:
Cluster.setProtocol(java.lang.String)

getProtocol

public java.lang.String getProtocol()
Description copied from interface: Cluster
Get the protocol used by the cluster.

Specified by:
getProtocol in interface Cluster
Returns:
The protocol
See Also:
Cluster.getProtocol()

getChannelStartOptions

public int getChannelStartOptions()

setChannelStartOptions

public void setChannelStartOptions(int channelStartOptions)

Apache Tomcat 6.0.53

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