org.apache.catalina.ha.tcp

Class SimpleTcpCluster

public class SimpleTcpCluster extends 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

Version: $Revision: 697040 $, $Date: 2008-09-19 12:39:02 +0200 (Fri, 19 Sep 2008) $

Author: Filip Hanik Remy Maucherat Peter Rossbach

Field Summary
static StringAFTER_MANAGERREGISTER_EVENT
static StringAFTER_MANAGERUNREGISTER_EVENT
static StringAFTER_MEMBERREGISTER_EVENT
static StringAFTER_MEMBERUNREGISTER_EVENT
static StringBEFORE_MANAGERREGISTER_EVENT
static StringBEFORE_MANAGERUNREGISTER_EVENT
static StringBEFORE_MEMBERREGISTER_EVENT
static StringBEFORE_MEMBERUNREGISTER_EVENT
protected Channelchannel
Group channel.
protected StringclusterImpName
Name for logging purpose
protected ListclusterListeners
Listeners of messages
protected StringclusterName
The cluster name to join
protected Containercontainer
The Container associated with this Cluster.
protected booleanhasMembers
has members
protected booleanheartbeatBackgroundEnabled
call Channel.heartbeat() at container background thread
protected static Stringinfo
Descriptive information about this component implementation.
protected LifecycleSupportlifecycle
The lifecycle event support for this component.
static Loglog
protected Mapmanagers
The context name <->manager association for distributed contexts.
protected ClusterManagermanagerTemplate
static StringRECEIVE_MESSAGE_FAILURE_EVENT
protected StringManagersm
The string manager for this package.
protected booleanstarted
Has this component been started?
protected PropertyChangeSupportsupport
The property change support for this component.
static StringSEND_MESSAGE_FAILURE_EVENT
Constructor Summary
SimpleTcpCluster()
Method Summary
booleanaccept(Serializable msg, Member sender)
notify all listeners from receiving a new message is not ClusterMessage emitt Failure Event to LifecylceListener
voidaddClusterListener(ClusterListener listener)
add cluster message listener and register cluster to this listener
voidaddLifecycleListener(LifecycleListener listener)
Add a lifecycle event listener to this component.
voidaddValve(Valve valve)
Add cluster valve Cluster Valves are only add to container when cluster is started!
voidbackgroundProcess()
Execute a periodic task, such as reloading, etc.
protected voidcheckDefaults()
ManagercreateManager(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.
ChannelgetChannel()
intgetChannelSendOptions()
intgetChannelStartOptions()
ClusterDeployergetClusterDeployer()
get current Deployer
StringgetClusterName()
Return the name of the cluster that this Server is currently configured to operate within.
ContainergetContainer()
Get the Container associated with our Cluster
StringgetInfo()
Return descriptive information about this Cluster implementation and the corresponding version number, in the format <description>/<version>.
MembergetLocalMember()
Return the member that represents this node.
LoggetLogger()
ManagergetManager(String name)
StringgetManagerClassName()
StringgetManagerName(String name, Manager manager)
MapgetManagers()
ClusterManagergetManagerTemplate()
Member[]getMembers()
Get all current cluster members
ObjectgetProperty(String key)
get current config
IteratorgetPropertyNames()
Get all properties keys
StringgetProtocol()
Valve[]getValves()
get all cluster valves
booleanhasMembers()
booleanisHeartbeatBackgroundEnabled()
Return heartbeat enable flag (default false)
booleanisNotifyLifecycleListenerOnFailure()
voidlifecycleEvent(LifecycleEvent lifecycleEvent)
Use as base to handle start/stop/periodic Events from host.
voidmemberAdded(Member member)
New cluster member is registered
voidmemberDisappeared(Member member)
Cluster member is gone
voidmessageReceived(Serializable message, Member sender)
voidmessageReceived(ClusterMessage message)
protected voidregisterClusterValve()
register all cluster valve to host or engine
voidregisterManager(Manager manager)
voidremoveClusterListener(ClusterListener listener)
remove message listener and deregister Cluster from listener
voidremoveLifecycleListener(LifecycleListener listener)
Remove a lifecycle event listener from this component.
voidremoveManager(Manager manager)
remove an application form cluster replication bus
voidremoveProperty(String key)
remove a configured property.
voidsend(ClusterMessage msg)
send message to all cluster members
voidsend(ClusterMessage msg, Member dest)
send a cluster message to one member
voidsendClusterDomain(ClusterMessage msg)
send message to all cluster members same cluster domain
voidsetChannel(Channel channel)
voidsetChannelSendOptions(int channelSendOptions)
voidsetChannelStartOptions(int channelStartOptions)
voidsetClusterDeployer(ClusterDeployer clusterDeployer)
set a new Deployer, must be set before cluster started!
voidsetClusterName(String clusterName)
Set the name of the cluster to join, if no cluster with this name is present create one.
voidsetContainer(Container container)
Set the Container associated with our Cluster
voidsetHeartbeatBackgroundEnabled(boolean heartbeatBackgroundEnabled)
enabled that container backgroundThread call heartbeat at channel
voidsetManagerClassName(String managerClassName)
voidsetManagerTemplate(ClusterManager managerTemplate)
voidsetNotifyLifecycleListenerOnFailure(boolean notifyListenerOnFailure)
booleansetProperty(String name, String value)
JMX hack to direct use at jconsole
booleansetProperty(String name, Object value)
set config attributes with reflect and propagate to all managers
voidsetProtocol(String protocol)
voidstart()
Prepare for the beginning of active use of the public methods of this component.
voidstop()
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.
protected voidtransferProperty(String prefix, Object bean)
transfer properties from cluster configuration to subelement bean.
protected voidunregisterClusterValve()
unregister all cluster valve to host or engine

Field Detail

AFTER_MANAGERREGISTER_EVENT

public static final String AFTER_MANAGERREGISTER_EVENT

AFTER_MANAGERUNREGISTER_EVENT

public static final String AFTER_MANAGERUNREGISTER_EVENT

AFTER_MEMBERREGISTER_EVENT

public static final String AFTER_MEMBERREGISTER_EVENT

AFTER_MEMBERUNREGISTER_EVENT

public static final String AFTER_MEMBERUNREGISTER_EVENT

BEFORE_MANAGERREGISTER_EVENT

public static final String BEFORE_MANAGERREGISTER_EVENT

BEFORE_MANAGERUNREGISTER_EVENT

public static final String BEFORE_MANAGERUNREGISTER_EVENT

BEFORE_MEMBERREGISTER_EVENT

public static final String BEFORE_MEMBERREGISTER_EVENT

BEFORE_MEMBERUNREGISTER_EVENT

public static final String BEFORE_MEMBERUNREGISTER_EVENT

channel

protected Channel channel
Group channel.

clusterImpName

protected String clusterImpName
Name for logging purpose

clusterListeners

protected List clusterListeners
Listeners of messages

clusterName

protected String clusterName
The cluster name to join

container

protected Container container
The Container associated with this Cluster.

hasMembers

protected boolean hasMembers
has members

heartbeatBackgroundEnabled

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

See Also: heartbeat

info

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

lifecycle

protected LifecycleSupport lifecycle
The lifecycle event support for this component.

log

public static Log log

managers

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

managerTemplate

protected ClusterManager managerTemplate

RECEIVE_MESSAGE_FAILURE_EVENT

public static final String RECEIVE_MESSAGE_FAILURE_EVENT

sm

protected StringManager sm
The string manager for this package.

started

protected boolean started
Has this component been started?

support

protected PropertyChangeSupport support
The property change support for this component.

SEND_MESSAGE_FAILURE_EVENT

public static final String SEND_MESSAGE_FAILURE_EVENT

Constructor Detail

SimpleTcpCluster

public SimpleTcpCluster()

Method Detail

accept

public boolean accept(Serializable msg, Member sender)
notify all listeners from receiving a new message is not ClusterMessage emitt Failure Event to LifecylceListener

Parameters: message receveived Message

addClusterListener

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

See Also: CatalinaCluster

addLifecycleListener

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

Parameters: listener The listener to add

addValve

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

Parameters: valve The new cluster Valve.

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.

See Also: backgroundProcess heartbeat

checkDefaults

protected void checkDefaults()

createManager

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

Parameters: name Context Name of this manager

See Also: Cluster SimpleTcpCluster start

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.

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.

getChannel

public Channel getChannel()

getChannelSendOptions

public int getChannelSendOptions()

getChannelStartOptions

public int getChannelStartOptions()

getClusterDeployer

public ClusterDeployer getClusterDeployer()
get current Deployer

getClusterName

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

Returns: The name of the cluster associated with this server

getContainer

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

Returns: The Container associated with our Cluster

getInfo

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

getLocalMember

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

Returns: Member

getLogger

public Log getLogger()

getManager

public Manager getManager(String name)

getManagerClassName

public String getManagerClassName()

Deprecated: use getManagerTemplate().getClass().getName() instead.

Returns: String

getManagerName

public String getManagerName(String name, Manager manager)

Parameters: name manager

Returns:

getManagers

public Map getManagers()

Returns: Returns the managers.

getManagerTemplate

public ClusterManager getManagerTemplate()

getMembers

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

Returns: all members or empty array

getProperty

public Object getProperty(String key)
get current config

Parameters: key

Returns: The property

getPropertyNames

public Iterator getPropertyNames()
Get all properties keys

Returns: An iterator over the property names.

getProtocol

public String getProtocol()

See Also: getProtocol

getValves

public Valve[] getValves()
get all cluster valves

Returns: current cluster valves

hasMembers

public boolean hasMembers()

isHeartbeatBackgroundEnabled

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

Returns: the heartbeatBackgroundEnabled

isNotifyLifecycleListenerOnFailure

public boolean isNotifyLifecycleListenerOnFailure()

Returns: Returns the notifyLifecycleListenerOnFailure.

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.

See Also: lifecycleEvent

memberAdded

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

See Also: org.apache.catalina.ha.MembershipListener#memberAdded(org.apache.catalina.ha.Member)

memberDisappeared

public void memberDisappeared(Member member)
Cluster member is gone

See Also: org.apache.catalina.ha.MembershipListener#memberDisappeared(org.apache.catalina.ha.Member)

messageReceived

public void messageReceived(Serializable message, Member sender)

messageReceived

public void messageReceived(ClusterMessage message)

registerClusterValve

protected void registerClusterValve()
register all cluster valve to host or engine

Throws: Exception ClassNotFoundException

registerManager

public void registerManager(Manager manager)

removeClusterListener

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

See Also: CatalinaCluster

removeLifecycleListener

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

Parameters: listener The listener to remove

removeManager

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

See Also: CatalinaCluster

removeProperty

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

Parameters: key

send

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

Parameters: msg message to transfer

See Also: send

send

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

Parameters: msg message to transfer dest Receiver member

See Also: CatalinaCluster

sendClusterDomain

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

See Also: send

setChannel

public void setChannel(Channel channel)

setChannelSendOptions

public void setChannelSendOptions(int channelSendOptions)

setChannelStartOptions

public void setChannelStartOptions(int channelStartOptions)

setClusterDeployer

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

setClusterName

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

Parameters: clusterName The clustername to join

setContainer

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

Parameters: container The Container to use

setHeartbeatBackgroundEnabled

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

Parameters: heartbeatBackgroundEnabled the heartbeatBackgroundEnabled to set

setManagerClassName

public void setManagerClassName(String managerClassName)

Deprecated: use nested <Manager> element inside the cluster config instead.

Parameters: managerClassName String

setManagerTemplate

public void setManagerTemplate(ClusterManager managerTemplate)

setNotifyLifecycleListenerOnFailure

public void setNotifyLifecycleListenerOnFailure(boolean notifyListenerOnFailure)

Parameters: notifyListenerOnFailure The notifyLifecycleListenerOnFailure to set.

setProperty

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

Parameters: name value

setProperty

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

Parameters: name value

setProtocol

public void setProtocol(String protocol)

See Also: Cluster

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

Throws: IllegalStateException if this component has already been started LifecycleException if this component detects a fatal error that prevents this component from being used

stop

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

Throws: IllegalStateException if this component has not been started LifecycleException if this component detects a fatal error that needs to be reported

transferProperty

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

Parameters: prefix bean

unregisterClusterValve

protected void unregisterClusterValve()
unregister all cluster valve to host or engine

Throws: Exception ClassNotFoundException

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