Package 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
,Contained
,CatalinaCluster
,JmxEnabled
,Lifecycle
,ChannelListener
,MembershipListener
public class SimpleTcpCluster
extends LifecycleMBeanBase
implements CatalinaCluster, MembershipListener, ChannelListener
A Cluster implementation using simple multicast. Responsible for setting up a cluster and provides callers
with a valid multicast receiver/sender.
- Author:
- Remy Maucherat, Peter Rossbach
-
Nested Class Summary
Nested classes/interfaces inherited from interface org.apache.catalina.Lifecycle
Lifecycle.SingleUse
-
Field Summary
Modifier and TypeFieldDescriptionstatic final String
static final String
static final String
static final String
static final String
static final String
static final String
static final String
protected Channel
Group channel.protected final List
<ClusterListener> Listeners of messagesprotected String
The cluster name to joinprotected Container
The Container associated with this Cluster.protected boolean
has membersprotected boolean
call Channel.heartbeat() at container background threadstatic final Log
protected final Map
<String, ClusterManager> The context name <-> manager association for distributed contexts.protected ClusterManager
static final String
static final String
protected static final StringManager
The string manager for this package.protected final PropertyChangeSupport
The property change support for this component.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
-
Method Summary
Modifier and TypeMethodDescriptionboolean
accept
(Serializable msg, Member sender) notify all listeners from receiving a new message is not ClusterMessage emit Failure Event to LifecycleListenervoid
addClusterListener
(ClusterListener listener) Add cluster message listener and register cluster to this listener.void
Add cluster valve.void
Execute a periodic task, such as reloading, etc.protected void
createManager
(String name) Create a new manager which will use this cluster to replicate its sessions.protected void
Sub-classes implement this method to perform any instance destruction required.Get the cluster listeners associated with this cluster.int
returns the SendOptions as a comma separated list of names for use by JMXint
Return the name of the cluster that this Server is currently configured to operate within.Get theContainer
with which this instance is associated.protected String
Method implemented by sub-classes to identify the domain in which MBeans should be registered.getManager
(String name) Get ManagergetManagerName
(String name, Manager manager) Get a new cluster name for a manager.Member[]
protected String
Allow sub-classes to specify the key properties component of theObjectName
that will be used to register this component.Valve[]
boolean
protected void
Sub-classes implement this method to perform any instance initialisation required.boolean
Return heartbeat enable flag (default false)boolean
void
memberAdded
(Member member) A member was added to the groupvoid
memberDisappeared
(Member member) A member was removed from the group
If the member left voluntarily, the Member.getCommand will contain the Member.SHUTDOWN_PAYLOAD datavoid
messageReceived
(Serializable message, Member sender) Receive a message from the channelvoid
messageReceived
(ClusterMessage message) protected void
register all cluster valve to host or enginevoid
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) Removes a manager from the clustervoid
send
(ClusterMessage msg) Sends a message to all the members in the clustervoid
send
(ClusterMessage msg, Member dest) Sends a message to a specific member in the cluster.void
send
(ClusterMessage msg, Member dest, int sendOptions) Sends a message with the specified sendOptions to a specific member in the cluster.void
setChannel
(Channel channel) Set the channel associated with the cluster.void
setChannelSendOptions
(int channelSendOptions) void
setChannelSendOptions
(String channelSendOptions) void
setChannelStartOptions
(int channelStartOptions) void
setClusterDeployer
(ClusterDeployer clusterDeployer) Set a new Deployer, must be set before the 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 theContainer
with which this instance is associated.void
setHeartbeatBackgroundEnabled
(boolean heartbeatBackgroundEnabled) enabled that container backgroundThread call heartbeat at channelvoid
setManagerTemplate
(ClusterManager managerTemplate) void
setNotifyLifecycleListenerOnFailure
(boolean notifyListenerOnFailure) protected void
Start Cluster and implement the requirements ofLifecycleBase.startInternal()
.protected void
Stop Cluster and implement the requirements ofLifecycleBase.stopInternal()
.toString()
protected void
unregister all cluster valve to host or engineMethods inherited from class org.apache.catalina.util.LifecycleMBeanBase
getDomain, getObjectName, postDeregister, postRegister, preDeregister, preRegister, register, setDomain, unregister, unregister
Methods inherited from class org.apache.catalina.util.LifecycleBase
addLifecycleListener, destroy, findLifecycleListeners, fireLifecycleEvent, getState, getStateName, getThrowOnFailure, init, removeLifecycleListener, setState, setState, setThrowOnFailure, start, stop
-
Field Details
-
log
-
BEFORE_MEMBERREGISTER_EVENT
- See Also:
-
AFTER_MEMBERREGISTER_EVENT
- See Also:
-
BEFORE_MANAGERREGISTER_EVENT
- See Also:
-
AFTER_MANAGERREGISTER_EVENT
- See Also:
-
BEFORE_MANAGERUNREGISTER_EVENT
- See Also:
-
AFTER_MANAGERUNREGISTER_EVENT
- See Also:
-
BEFORE_MEMBERUNREGISTER_EVENT
- See Also:
-
AFTER_MEMBERUNREGISTER_EVENT
- See Also:
-
SEND_MESSAGE_FAILURE_EVENT
- See Also:
-
RECEIVE_MESSAGE_FAILURE_EVENT
- See Also:
-
channel
Group channel. -
sm
The string manager for this package. -
clusterName
The cluster name to join -
heartbeatBackgroundEnabled
protected boolean heartbeatBackgroundEnabledcall Channel.heartbeat() at container background thread- See Also:
-
container
The Container associated with this Cluster. -
support
The property change support for this component. -
managers
The context name <-> manager association for distributed contexts. -
managerTemplate
-
clusterListeners
Listeners of messages -
hasMembers
protected boolean hasMembershas members
-
-
Constructor Details
-
SimpleTcpCluster
public SimpleTcpCluster()
-
-
Method Details
-
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
Description copied from interface:Cluster
Set the name of the cluster to join, if no cluster with this name is present create one.- Specified by:
setClusterName
in interfaceCluster
- Parameters:
clusterName
- The clustername to join
-
getClusterName
Description copied from interface:Cluster
Return the name of the cluster that this Server is currently configured to operate within.- Specified by:
getClusterName
in interfaceCluster
- Returns:
- The name of the cluster associated with this server
-
setContainer
Description copied from interface:Contained
Set theContainer
with which this instance is associated.- Specified by:
setContainer
in interfaceContained
- Parameters:
container
- The Container instance with which this instance is to be associated, ornull
to disassociate this instance from any Container
-
getContainer
Description copied from interface:Contained
Get theContainer
with which this instance is associated.- Specified by:
getContainer
in interfaceContained
- Returns:
- The Container with which this instance is associated or
null
if not associated with a Container
-
isNotifyLifecycleListenerOnFailure
public boolean isNotifyLifecycleListenerOnFailure()- Returns:
- Returns the notifyLifecycleListenerOnFailure.
-
setNotifyLifecycleListenerOnFailure
public void setNotifyLifecycleListenerOnFailure(boolean notifyListenerOnFailure) - Parameters:
notifyListenerOnFailure
- The notifyLifecycleListenerOnFailure to set.
-
addValve
Description copied from interface:CatalinaCluster
Add cluster valve. Cluster Valves are only add to container when cluster is started.- Specified by:
addValve
in interfaceCatalinaCluster
- Parameters:
valve
- The new cluster Valve.
-
getValves
- Specified by:
getValves
in interfaceCatalinaCluster
- Returns:
- the current cluster valves
-
findClusterListeners
Get the cluster listeners associated with this cluster. If this Array has no listeners registered, a zero-length array is returned.- Returns:
- the listener array
-
addClusterListener
Description copied from interface:CatalinaCluster
Add cluster message listener and register cluster to this listener.- Specified by:
addClusterListener
in interfaceCatalinaCluster
- Parameters:
listener
- The new listener
-
removeClusterListener
Description copied from interface:CatalinaCluster
Remove message listener and deregister Cluster from listener.- Specified by:
removeClusterListener
in interfaceCatalinaCluster
- Parameters:
listener
- The listener to remove
-
getClusterDeployer
- Specified by:
getClusterDeployer
in interfaceCatalinaCluster
- Returns:
- the current Deployer
-
setClusterDeployer
Description copied from interface:CatalinaCluster
Set a new Deployer, must be set before the cluster started.- Specified by:
setClusterDeployer
in interfaceCatalinaCluster
- Parameters:
clusterDeployer
- The associated deployer
-
setChannel
Description copied from interface:CatalinaCluster
Set the channel associated with the cluster.- Specified by:
setChannel
in interfaceCatalinaCluster
- Parameters:
channel
- the channel
-
setManagerTemplate
-
setChannelSendOptions
public void setChannelSendOptions(int channelSendOptions) -
setChannelSendOptions
-
hasMembers
public boolean hasMembers()- Specified by:
hasMembers
in interfaceCatalinaCluster
- Returns:
true
if the cluster has members.
-
getMembers
- Specified by:
getMembers
in interfaceCatalinaCluster
- Returns:
- an array containing all the members currently participating in the cluster.
-
getLocalMember
- Specified by:
getLocalMember
in interfaceCatalinaCluster
- Returns:
- the member that represents this node.
-
getManagers
- Specified by:
getManagers
in interfaceCatalinaCluster
- Returns:
- The map of managers
-
getChannel
- Specified by:
getChannel
in interfaceCatalinaCluster
- Returns:
- the channel associated with the cluster
-
getManagerTemplate
-
getChannelSendOptions
public int getChannelSendOptions() -
getChannelSendOptionsName
returns the SendOptions as a comma separated list of names for use by JMX- Returns:
- a comma separated list of the option names
-
createManager
Description copied from interface:Cluster
Create a new manager which will use this cluster to replicate its sessions.- Specified by:
createManager
in interfaceCluster
- Parameters:
name
- Name (key) of the application with which the manager is associated- Returns:
- The newly created Manager instance
-
registerManager
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 interfaceCluster
- Parameters:
manager
- Manager
-
removeManager
Description copied from interface:Cluster
Removes a manager from the cluster- Specified by:
removeManager
in interfaceCluster
- Parameters:
manager
- Manager
-
getManagerName
Description copied from interface:CatalinaCluster
Get a new cluster name for a manager.- Specified by:
getManagerName
in interfaceCatalinaCluster
- Parameters:
name
- Override name (optional)manager
- The manager- Returns:
- the manager name in the cluster
-
getManager
Description copied from interface:CatalinaCluster
Get Manager- Specified by:
getManager
in interfaceCatalinaCluster
- Parameters:
name
- The manager name- Returns:
- The manager
-
backgroundProcess
public void backgroundProcess()Description copied from interface:Cluster
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 interfaceCluster
-
initInternal
Description copied from class:LifecycleBase
Sub-classes implement this method to perform any instance initialisation required.- Overrides:
initInternal
in classLifecycleMBeanBase
- Throws:
LifecycleException
- If the initialisation fails
-
startInternal
Start Cluster and implement the requirements ofLifecycleBase.startInternal()
.- Specified by:
startInternal
in classLifecycleBase
- 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
Stop Cluster and implement the requirements ofLifecycleBase.stopInternal()
.- Specified by:
stopInternal
in classLifecycleBase
- Throws:
LifecycleException
- if this component detects a fatal error that prevents this component from being used
-
destroyInternal
Description copied from class:LifecycleBase
Sub-classes implement this method to perform any instance destruction required.- Overrides:
destroyInternal
in classLifecycleMBeanBase
- Throws:
LifecycleException
- If the destruction fails
-
toString
-
send
Description copied from interface:CatalinaCluster
Sends a message to all the members in the cluster- Specified by:
send
in interfaceCatalinaCluster
- Parameters:
msg
- ClusterMessage
-
send
Description copied from interface:CatalinaCluster
Sends a message to a specific member in the cluster.- Specified by:
send
in interfaceCatalinaCluster
- Parameters:
msg
- ClusterMessagedest
- Member
-
send
Description copied from interface:CatalinaCluster
Sends a message with the specified sendOptions to a specific member in the cluster.- Specified by:
send
in interfaceCatalinaCluster
- Parameters:
msg
- ClusterMessagedest
- MembersendOptions
- sendOptions
-
memberAdded
Description copied from interface:MembershipListener
A member was added to the group- Specified by:
memberAdded
in interfaceMembershipListener
- Parameters:
member
- Member - the member that was added
-
memberDisappeared
Description copied from interface:MembershipListener
A member was removed from the group
If the member left voluntarily, the Member.getCommand will contain the Member.SHUTDOWN_PAYLOAD data- Specified by:
memberDisappeared
in interfaceMembershipListener
- Parameters:
member
- Member- See Also:
-
accept
notify all listeners from receiving a new message is not ClusterMessage emit Failure Event to LifecycleListener- Specified by:
accept
in interfaceChannelListener
- Parameters:
msg
- received Messagesender
- Member- Returns:
- boolean
-
messageReceived
Description copied from interface:ChannelListener
Receive a message from the channel- Specified by:
messageReceived
in interfaceChannelListener
- Parameters:
message
- Serializablesender
- - the source of the message
-
messageReceived
-
getChannelStartOptions
public int getChannelStartOptions() -
setChannelStartOptions
public void setChannelStartOptions(int channelStartOptions) -
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 classLifecycleMBeanBase
- Returns:
- The name of the domain to use to register MBeans.
-
getObjectNameKeyProperties
Description copied from class:LifecycleMBeanBase
Allow sub-classes to specify the key properties component of theObjectName
that will be used to register this component.- Specified by:
getObjectNameKeyProperties
in classLifecycleMBeanBase
- Returns:
- The string representation of the key properties component of the desired
ObjectName
-