org.apache.catalina.ha.tcp

## Class SimpleTcpCluster

- java.lang.Object
- - org.apache.catalina.util.LifecycleBase
  - - org.apache.catalina.util.LifecycleMBeanBase
    - - org.apache.catalina.ha.tcp.SimpleTcpCluster

All Implemented Interfaces:
  MBeanRegistration, Cluster, CatalinaCluster, IDynamicProperty, Lifecycle, LifecycleListener, ChannelListener, MembershipListener

    public class SimpleTcpCluster
    extends LifecycleMBeanBase
    implements CatalinaCluster, 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 wrote testcases

Author:
  Filip Hanik, Remy Maucherat, Peter Rossbach

### Field Summary

Fields
`static String` `AFTER_MANAGERREGISTER_EVENT`
`static String` `AFTER_MANAGERUNREGISTER_EVENT`
`static String` `AFTER_MEMBERREGISTER_EVENT`
`static String` `AFTER_MEMBERUNREGISTER_EVENT`
`static String` `BEFORE_MANAGERREGISTER_EVENT`
`static String` `BEFORE_MANAGERUNREGISTER_EVENT`
`static String` `BEFORE_MEMBERREGISTER_EVENT`
`static String` `BEFORE_MEMBERUNREGISTER_EVENT`
`protected Channel` `channel` Group channel.
`protected String` `clusterImpName` Name for logging purpose
`protected List<ClusterListener>` `clusterListeners` Listeners of messages
`protected 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 String` `info` Descriptive information about this component implementation.
`static Log` `log`
`protected Map<String,ClusterManager>` `managers` The context name <->manager association for distributed contexts.
`protected ClusterManager` `managerTemplate`
`static String` `RECEIVE_MESSAGE_FAILURE_EVENT`
`static String` `SEND_MESSAGE_FAILURE_EVENT`
`protected static StringManager` `sm` The string manager for this package.
`protected PropertyChangeSupport` `support` The property change support for this component.

### Fields inherited from class org.apache.catalina.util.LifecycleMBeanBase

`mserver`

### Fields inherited from interface org.apache.catalina.Lifecycle

`AFTER_DESTROY_EVENT, AFTER_INIT_EVENT, AFTER_START_EVENT, AFTER_STOP_EVENT, BEFORE_DESTROY_EVENT, BEFORE_INIT_EVENT, BEFORE_START_EVENT, BEFORE_STOP_EVENT, CONFIGURE_START_EVENT, CONFIGURE_STOP_EVENT, PERIODIC_EVENT, START_EVENT, STOP_EVENT`

### Constructor Summary

Constructors
Constructor and Description
`SimpleTcpCluster()`

### Method Summary

Methods
`boolean` `accept(Serializable msg, Member sender)` notify all listeners from receiving a new message is not ClusterMessage emit Failure Event to LifecylceListener
`void` `addClusterListener(ClusterListener listener)` Add cluster message listener and register cluster to this listener.
`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(String name)` Create new Manager without add to cluster (comes with start the manager)
`protected void` `destroyInternal()` Sub-classes wishing to perform additional clean-up should override this method, ensuring that super.destroyInternal() is the last call in the overriding method.
`ClusterListener[]` `findClusterListeners()` Get the cluster listeners associated with this cluster.
`Channel` `getChannel()`
`int` `getChannelSendOptions()`
`int` `getChannelStartOptions()`
`ClusterDeployer` `getClusterDeployer()` get current Deployer
`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
`protected String` `getDomainInternal()` Method implemented by sub-classes to identify the domain in which MBeans should be registered.
`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(String name)`
`String` `getManagerName(String name, Manager manager)`
`Map<String,ClusterManager>` `getManagers()`
`ClusterManager` `getManagerTemplate()`
`Member[]` `getMembers()` Get all current cluster members
`protected String` `getObjectNameKeyProperties()` Allow sub-classes to specify the key properties component of the `ObjectName` that will be used to register this component.
`Object` `getProperty(String key)` Deprecated. Unused - will be removed in Tomcat 8.0.x
`Iterator<String>` `getPropertyNames()` Deprecated. Unused - will be removed in Tomcat 8.0.x
`String` `getProtocol()` Get the protocol used by the cluster.
`Valve[]` `getValves()` get all cluster valves
`boolean` `hasMembers()` Returns that cluster has members.
`protected void` `initInternal()` Sub-classes wishing to perform additional initialization should override this method, ensuring that super.initInternal() is the first call in the overriding method.
`boolean` `isHeartbeatBackgroundEnabled()` Return heartbeat enable flag (default false)
`boolean` `isNotifyLifecycleListenerOnFailure()`
`void` `lifecycleEvent(LifecycleEvent lifecycleEvent)` Deprecated. Unused - will be removed in Tomcat 8.0.x
`void` `memberAdded(Member member)` New cluster member is registered
`void` `memberDisappeared(Member member)` Cluster member is gone
`void` `messageReceived(ClusterMessage message)`
`void` `messageReceived(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` `removeManager(Manager manager)` Remove an application from cluster replication bus.
`void` `removeProperty(String key)` Deprecated. Unused - will be removed in Tomcat 8.0.x
`void` `send(ClusterMessage msg)` send message to all cluster members
`void` `send(ClusterMessage msg, Member dest)` send a cluster message to one member
`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(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` `setManagerTemplate(ClusterManager managerTemplate)`
`void` `setNotifyLifecycleListenerOnFailure(boolean notifyListenerOnFailure)`
`boolean` `setProperty(String name, Object value)` Deprecated. Unused - will be removed in Tomcat 8.0.x
`boolean` `setProperty(String name, String value)` Deprecated. Unused - will be removed in Tomcat 8.0.x
`void` `setProtocol(String protocol)` Set the protocol parameters.
`protected void` `startInternal()` Start Cluster and implement the requirements of `LifecycleBase.startInternal()`.
`protected void` `stopInternal()` Stop Cluster and implement the requirements of `LifecycleBase.stopInternal()`.
`String` `toString()` Return a String rendering of this object.
`protected void` `transferProperty(String prefix, Object bean)` Deprecated. Unused - will be removed in Tomcat 8.0.x
`protected void` `unregisterClusterValve()` unregister all cluster valve to host or engine

### Methods inherited from class org.apache.catalina.util.LifecycleMBeanBase

`getDomain, getObjectName, postDeregister, postRegister, preDeregister, preRegister, register, setDomain, unregister`

### Methods inherited from class org.apache.catalina.util.LifecycleBase

`addLifecycleListener, destroy, findLifecycleListeners, fireLifecycleEvent, getState, getStateName, init, removeLifecycleListener, setState, setState, start, stop`

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

### Methods inherited from interface org.apache.catalina.ha.CatalinaCluster

`start, stop`

### Methods inherited from interface org.apache.catalina.tribes.ChannelListener

`equals, hashCode`

### Field Detail

#### log

    public static final Log log

#### info

    protected static final String info

Descriptive information about this component implementation.

See Also:
  Constant Field Values

#### BEFORE_MEMBERREGISTER_EVENT

    public static final String BEFORE_MEMBERREGISTER_EVENT

See Also:
  Constant Field Values

#### AFTER_MEMBERREGISTER_EVENT

    public static final String AFTER_MEMBERREGISTER_EVENT

See Also:
  Constant Field Values

#### BEFORE_MANAGERREGISTER_EVENT

    public static final String BEFORE_MANAGERREGISTER_EVENT

See Also:
  Constant Field Values

#### AFTER_MANAGERREGISTER_EVENT

    public static final String AFTER_MANAGERREGISTER_EVENT

See Also:
  Constant Field Values

#### BEFORE_MANAGERUNREGISTER_EVENT

    public static final String BEFORE_MANAGERUNREGISTER_EVENT

See Also:
  Constant Field Values

#### AFTER_MANAGERUNREGISTER_EVENT

    public static final String AFTER_MANAGERUNREGISTER_EVENT

See Also:
  Constant Field Values

#### BEFORE_MEMBERUNREGISTER_EVENT

    public static final String BEFORE_MEMBERUNREGISTER_EVENT

See Also:
  Constant Field Values

#### AFTER_MEMBERUNREGISTER_EVENT

    public static final String AFTER_MEMBERUNREGISTER_EVENT

See Also:
  Constant Field Values

#### SEND_MESSAGE_FAILURE_EVENT

    public static final String SEND_MESSAGE_FAILURE_EVENT

See Also:
  Constant Field Values

#### RECEIVE_MESSAGE_FAILURE_EVENT

    public static final String RECEIVE_MESSAGE_FAILURE_EVENT

See Also:
  Constant Field Values

#### channel

    protected Channel channel

Group channel.

#### clusterImpName

    protected String clusterImpName

Name for logging purpose

#### sm

    protected static final StringManager sm

The string manager for this package.

#### clusterName

    protected 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.

#### support

    protected PropertyChangeSupport support

The property change support for this component.

#### managers

    protected Map<String,ClusterManager> managers

The context name <->manager association for distributed contexts.

#### managerTemplate

    protected ClusterManager managerTemplate

#### clusterListeners

    protected List<ClusterListener> clusterListeners

Listeners of messages

#### hasMembers

    protected boolean hasMembers

has members

### Constructor Detail

#### SimpleTcpCluster

    public SimpleTcpCluster()

### Method Detail

#### getInfo

    public 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(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 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.

#### 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

    @Deprecated
    public boolean setProperty(String name,
                                 String value)

Deprecated. Unused - will be removed in Tomcat 8.0.x
JMX hack to direct use at jconsole

Parameters:
  `name` -
  `value` -

#### setProperty

    @Deprecated
    public boolean setProperty(String name,
                                 Object value)

Deprecated. Unused - will be removed in Tomcat 8.0.x
set config attributes with reflect and propagate to all managers

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

#### getProperty

    @Deprecated
    public Object getProperty(String key)

Deprecated. Unused - will be removed in Tomcat 8.0.x
get current config

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

#### getPropertyNames

    @Deprecated
    public Iterator<String> getPropertyNames()

Deprecated. Unused - will be removed in Tomcat 8.0.x
Get all properties keys

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

#### removeProperty

    @Deprecated
    public void removeProperty(String key)

Deprecated. Unused - will be removed in Tomcat 8.0.x
remove a configured property.

Specified by:
  `removeProperty` in interface `IDynamicProperty`
Parameters:
  `key` -

#### transferProperty

    @Deprecated
    protected void transferProperty(String prefix,
                                   Object bean)

Deprecated. Unused - will be removed in Tomcat 8.0.x
transfer properties from cluster configuration to subelement bean.

Parameters:
  `prefix` -
  `bean` -

#### getManagers

    public Map<String,ClusterManager> 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(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)`, `LifecycleBase.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 manager is participating in the cluster.

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

#### removeManager

    public void removeManager(Manager manager)

Remove an application from cluster replication bus.

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

#### getManagerName

    public String getManagerName(String name,
                        Manager manager)

Specified by:
  `getManagerName` in interface `CatalinaCluster`
Parameters:
  `name` -
  `manager` -
Returns:
  TODO

#### getManager

    public Manager getManager(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()`

#### lifecycleEvent

    @Deprecated
    public void lifecycleEvent(LifecycleEvent lifecycleEvent)

Deprecated. Unused - will be removed in Tomcat 8.0.x
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)`

#### initInternal

    protected void initInternal()
                         throws LifecycleException

Description copied from class: `LifecycleMBeanBase`
Sub-classes wishing to perform additional initialization should override this method, ensuring that super.initInternal() is the first call in the overriding method.

Overrides:
  `initInternal` in class `LifecycleMBeanBase`
Throws:
  `LifecycleException`

#### startInternal

    protected void startInternal()
                          throws LifecycleException

Start Cluster and implement the requirements of `LifecycleBase.startInternal()`.

Specified by:
  `startInternal` in class `LifecycleBase`
Throws:
  `LifecycleException` - if this component detects a fatal error that prevents this component from being used

#### checkDefaults

    protected void checkDefaults()

#### registerClusterValve

    protected void registerClusterValve()

register all cluster valve to host or engine

#### unregisterClusterValve

    protected void unregisterClusterValve()

unregister all cluster valve to host or engine

#### stopInternal

    protected void stopInternal()
                         throws LifecycleException

Stop Cluster and implement the requirements of `LifecycleBase.stopInternal()`.

Specified by:
  `stopInternal` in class `LifecycleBase`
Throws:
  `LifecycleException` - if this component detects a fatal error that prevents this component from being used

#### destroyInternal

    protected void destroyInternal()
                            throws LifecycleException

Description copied from class: `LifecycleMBeanBase`
Sub-classes wishing to perform additional clean-up should override this method, ensuring that super.destroyInternal() is the last call in the overriding method.

Overrides:
  `destroyInternal` in class `LifecycleMBeanBase`
Throws:
  `LifecycleException`

#### toString

    public String toString()

Return a String rendering of this object.

Overrides:
  `toString` in class `Object`

#### 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(org.apache.catalina.ha.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(org.apache.catalina.ha.ClusterMessage, org.apache.catalina.tribes.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(org.apache.catalina.tribes.Member)`

#### memberDisappeared

    public void memberDisappeared(Member member)

Cluster member is gone

Specified by:
  `memberDisappeared` in interface `MembershipListener`
Parameters:
  `member` - Member
See Also:
  `MembershipListener.memberDisappeared(org.apache.catalina.tribes.Member)`

#### accept

    public boolean accept(Serializable msg,
                 Member sender)

notify all listeners from receiving a new message is not ClusterMessage emit Failure Event to LifecylceListener

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

#### messageReceived

    public void messageReceived(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(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 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)

#### getDomainInternal

    protected String getDomainInternal()

Description copied from class: `LifecycleMBeanBase`
Method implemented by sub-classes to identify the domain in which MBeans should be registered.

Specified by:
  `getDomainInternal` in class `LifecycleMBeanBase`
Returns:
  The name of the domain to use to register MBeans.

#### getObjectNameKeyProperties

    protected String getObjectNameKeyProperties()

Description copied from class: `LifecycleMBeanBase`
Allow sub-classes to specify the key properties component of the `ObjectName` that will be used to register this component.

Specified by:
  `getObjectNameKeyProperties` in class `LifecycleMBeanBase`
Returns:
  The string representation of the key properties component of the desired `ObjectName`