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.
-
Nested Class Summary
Nested classes/interfaces inherited from interface Lifecycle
Lifecycle.SingleUse -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final StringLifecycle event fired after a manager is registered.static final StringLifecycle event fired after a manager is unregistered.static final StringLifecycle event fired after a member is registered.static final StringLifecycle event fired after a member is unregistered.static final StringLifecycle event fired before a manager is registered.static final StringLifecycle event fired before a manager is unregistered.static final StringLifecycle event fired before a member is registered.static final StringLifecycle event fired before a member is unregistered.protected ChannelGroup channel.protected final List<ClusterListener> Listeners of messagesprotected StringThe cluster name to joinprotected ContainerThe Container associated with this Cluster.protected booleanhas membersprotected booleancall Channel.heartbeat() at container background threadstatic final LogLogger for this class.protected final Map<String, ClusterManager> The context name <-> manager association for distributed contexts.protected ClusterManagerTemplate used to create new cluster managers for contexts.static final StringLifecycle event fired when receiving a message fails.static final StringLifecycle event fired when sending a message fails.protected static final StringManagerThe string manager for this package.protected final PropertyChangeSupportThe property change support for this component.Fields inherited from interface 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 -
Method Summary
Modifier and TypeMethodDescriptionbooleanaccept(Serializable msg, Member sender) Invoked by the channel to determine if the listener will process this message or not.voidaddClusterListener(ClusterListener listener) Add cluster message listener and register cluster to this listener.voidAdd cluster valve.voidExecute a periodic task, such as reloading, etc.protected voidSets default values for cluster listeners, valves, deployer, and channel when they have not been configured explicitly.createManager(String name) Create a new manager which will use this cluster to replicate its sessions.protected voidDestroys the cluster component and unregisters JMX MBeans.Get the cluster listeners associated with this cluster.Returns the channel associated with the cluster.intReturns the channel send options as an integer flag value.returns the SendOptions as a comma separated list of names for use by JMXintReturns the channel start options.Returns the current Deployer.Return the name of the cluster that this Server is currently configured to operate within.Get theContainerwith which this instance is associated.protected StringReturns the JMX domain for this cluster, derived from the associated container.Returns the member that represents this node.getManager(String name) Get ManagergetManagerName(String name, Manager manager) Get a new cluster name for a manager.Returns the map of managers.Returns the manager template used to create new cluster managers.Member[]Returns all the members currently participating in the cluster.protected StringReturns the key properties used to build the JMX ObjectName for this cluster.Valve[]Returns the current cluster valves.booleanChecks if the cluster has members.protected voidInitializes the cluster component and registers the cluster deployer with JMX.booleanReturns whether the heartbeat background thread is enabled.booleanReturn whether the lifecycle listener should be notified on failure.voidmemberAdded(Member member) A member was added to the groupvoidmemberDisappeared(Member member) A member was removed from the group
If the member left voluntarily, the Member.getCommand will contain the Member.SHUTDOWN_PAYLOAD datavoidmessageReceived(Serializable message, Member sender) Receive a message from the channelvoidmessageReceived(ClusterMessage message) Processes a received cluster message by dispatching it to registered cluster listeners.protected voidregister all cluster valve to host or enginevoidregisterManager(Manager manager) Register a manager with the cluster.voidremoveClusterListener(ClusterListener listener) Remove message listener and deregister Cluster from listener.voidremoveManager(Manager manager) Removes a manager from the clustervoidsend(ClusterMessage msg) Sends a message to all the members in the clustervoidsend(ClusterMessage msg, Member dest) Sends a message to a specific member in the cluster.voidsend(ClusterMessage msg, Member dest, int sendOptions) Sends a message with the specified sendOptions to a specific member in the cluster.voidsetChannel(Channel channel) Set the channel associated with the cluster.voidsetChannelSendOptions(int channelSendOptions) Sets the channel send options as an integer flag value.voidsetChannelSendOptions(String channelSendOptions) Sets the channel send options as a comma-separated string of option names.voidsetChannelStartOptions(int channelStartOptions) Sets the channel start options.voidsetClusterDeployer(ClusterDeployer clusterDeployer) Set a new Deployer, must be set before the 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 theContainerwith which this instance is associated.voidsetHeartbeatBackgroundEnabled(boolean heartbeatBackgroundEnabled) Enables or disables the heartbeat background thread that calls heartbeat on the channel.voidsetManagerTemplate(ClusterManager managerTemplate) Sets the manager template used to create new cluster managers.voidsetNotifyLifecycleListenerOnFailure(boolean notifyListenerOnFailure) Set whether the lifecycle listener should be notified on failure.protected voidStart Cluster and implement the requirements ofLifecycleBase.startInternal().protected voidStop Cluster and implement the requirements ofLifecycleBase.stopInternal().toString()protected voidunregister all cluster valve to host or engineMethods inherited from class LifecycleMBeanBase
getDomain, getObjectName, postDeregister, postRegister, preDeregister, preRegister, register, setDomain, unregister, unregisterMethods inherited from class LifecycleBase
addLifecycleListener, destroy, findLifecycleListeners, fireLifecycleEvent, getState, getStateName, getThrowOnFailure, init, removeLifecycleListener, setState, setState, setThrowOnFailure, start, stop
-
Field Details
-
log
Logger for this class. -
BEFORE_MEMBERREGISTER_EVENT
Lifecycle event fired before a member is registered.- See Also:
-
AFTER_MEMBERREGISTER_EVENT
Lifecycle event fired after a member is registered.- See Also:
-
BEFORE_MANAGERREGISTER_EVENT
Lifecycle event fired before a manager is registered.- See Also:
-
AFTER_MANAGERREGISTER_EVENT
Lifecycle event fired after a manager is registered.- See Also:
-
BEFORE_MANAGERUNREGISTER_EVENT
Lifecycle event fired before a manager is unregistered.- See Also:
-
AFTER_MANAGERUNREGISTER_EVENT
Lifecycle event fired after a manager is unregistered.- See Also:
-
BEFORE_MEMBERUNREGISTER_EVENT
Lifecycle event fired before a member is unregistered.- See Also:
-
AFTER_MEMBERUNREGISTER_EVENT
Lifecycle event fired after a member is unregistered.- See Also:
-
SEND_MESSAGE_FAILURE_EVENT
Lifecycle event fired when sending a message fails.- See Also:
-
RECEIVE_MESSAGE_FAILURE_EVENT
Lifecycle event fired when receiving a message fails.- 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
Template used to create new cluster managers for contexts. -
clusterListeners
Listeners of messages -
hasMembers
protected boolean hasMembershas members
-
-
Constructor Details
-
SimpleTcpCluster
public SimpleTcpCluster()Creates a new SimpleTcpCluster instance.
-
-
Method Details
-
isHeartbeatBackgroundEnabled
public boolean isHeartbeatBackgroundEnabled()Returns whether the heartbeat background thread is enabled.- Returns:
trueif heartbeat is enabled in the background
-
setHeartbeatBackgroundEnabled
public void setHeartbeatBackgroundEnabled(boolean heartbeatBackgroundEnabled) Enables or disables the heartbeat background thread that calls heartbeat on the channel.- Parameters:
heartbeatBackgroundEnabled-trueto enable background heartbeat
-
setClusterName
Set the name of the cluster to join, if no cluster with this name is present create one.- Specified by:
setClusterNamein interfaceCluster- Parameters:
clusterName- The clustername to join
-
getClusterName
Return the name of the cluster that this Server is currently configured to operate within.- Specified by:
getClusterNamein interfaceCluster- Returns:
- The name of the cluster associated with this server
-
setContainer
Set theContainerwith which this instance is associated.- Specified by:
setContainerin interfaceContained- Parameters:
container- The Container instance with which this instance is to be associated, ornullto disassociate this instance from any Container
-
getContainer
Get theContainerwith which this instance is associated.- Specified by:
getContainerin interfaceContained- Returns:
- The Container with which this instance is associated or
nullif not associated with a Container
-
isNotifyLifecycleListenerOnFailure
public boolean isNotifyLifecycleListenerOnFailure()Return whether the lifecycle listener should be notified on failure.- Returns:
trueif the lifecycle listener should be notified on failure
-
setNotifyLifecycleListenerOnFailure
public void setNotifyLifecycleListenerOnFailure(boolean notifyListenerOnFailure) Set whether the lifecycle listener should be notified on failure.- Parameters:
notifyListenerOnFailure-trueto notify the lifecycle listener on failure
-
addValve
Add cluster valve. Cluster Valves are only add to container when cluster is started.- Specified by:
addValvein interfaceCatalinaCluster- Parameters:
valve- The new cluster Valve.
-
getValves
Returns the current cluster valves.- Specified by:
getValvesin 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
Add cluster message listener and register cluster to this listener.- Specified by:
addClusterListenerin interfaceCatalinaCluster- Parameters:
listener- The new listener
-
removeClusterListener
Remove message listener and deregister Cluster from listener.- Specified by:
removeClusterListenerin interfaceCatalinaCluster- Parameters:
listener- The listener to remove
-
getClusterDeployer
Returns the current Deployer.- Specified by:
getClusterDeployerin interfaceCatalinaCluster- Returns:
- the current Deployer
-
setClusterDeployer
Set a new Deployer, must be set before the cluster started.- Specified by:
setClusterDeployerin interfaceCatalinaCluster- Parameters:
clusterDeployer- The associated deployer
-
setChannel
Set the channel associated with the cluster.- Specified by:
setChannelin interfaceCatalinaCluster- Parameters:
channel- the channel
-
setManagerTemplate
Sets the manager template used to create new cluster managers.- Parameters:
managerTemplate- the manager template
-
setChannelSendOptions
public void setChannelSendOptions(int channelSendOptions) Sets the channel send options as an integer flag value.- Parameters:
channelSendOptions- the send options
-
setChannelSendOptions
Sets the channel send options as a comma-separated string of option names.- Parameters:
channelSendOptions- the send options as a string
-
hasMembers
public boolean hasMembers()Checks if the cluster has members.- Specified by:
hasMembersin interfaceCatalinaCluster- Returns:
trueif the cluster has members.
-
getMembers
Returns all the members currently participating in the cluster.- Specified by:
getMembersin interfaceCatalinaCluster- Returns:
- an array containing all the members currently participating in the cluster.
-
getLocalMember
Returns the member that represents this node.- Specified by:
getLocalMemberin interfaceCatalinaCluster- Returns:
- the member that represents this node.
-
getManagers
Returns the map of managers.- Specified by:
getManagersin interfaceCatalinaCluster- Returns:
- The map of managers
-
getChannel
Returns the channel associated with the cluster.- Specified by:
getChannelin interfaceCatalinaCluster- Returns:
- the channel associated with the cluster
-
getManagerTemplate
Returns the manager template used to create new cluster managers.- Returns:
- the manager template
-
getChannelSendOptions
public int getChannelSendOptions()Returns the channel send options as an integer flag value.- Returns:
- the channel send options
-
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
Create a new manager which will use this cluster to replicate its sessions.- Specified by:
createManagerin interfaceCluster- Parameters:
name- Name (key) of the application with which the manager is associated- Returns:
- The newly created Manager instance
-
registerManager
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:
registerManagerin interfaceCluster- Parameters:
manager- Manager
-
removeManager
Removes a manager from the cluster- Specified by:
removeManagerin interfaceCluster- Parameters:
manager- Manager
-
getManagerName
Get a new cluster name for a manager.- Specified by:
getManagerNamein interfaceCatalinaCluster- Parameters:
name- Override name (optional)manager- The manager- Returns:
- the manager name in the cluster
-
getManager
Get Manager- Specified by:
getManagerin interfaceCatalinaCluster- Parameters:
name- The manager name- Returns:
- The manager
-
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:
backgroundProcessin interfaceCluster
-
initInternal
Initializes the cluster component and registers the cluster deployer with JMX.- Overrides:
initInternalin classLifecycleMBeanBase- Throws:
LifecycleException- if an initialization error occurs
-
startInternal
Start Cluster and implement the requirements ofLifecycleBase.startInternal().- Specified by:
startInternalin classLifecycleBase- Throws:
LifecycleException- if this component detects a fatal error that prevents this component from being used
-
checkDefaults
protected void checkDefaults()Sets default values for cluster listeners, valves, deployer, and channel when they have not been configured explicitly. -
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:
stopInternalin classLifecycleBase- Throws:
LifecycleException- if this component detects a fatal error that prevents this component from being used
-
destroyInternal
Destroys the cluster component and unregisters JMX MBeans.- Overrides:
destroyInternalin classLifecycleMBeanBase- Throws:
LifecycleException- if a destruction error occurs
-
toString
-
send
Sends a message to all the members in the cluster- Specified by:
sendin interfaceCatalinaCluster- Parameters:
msg- ClusterMessage
-
send
Sends a message to a specific member in the cluster.- Specified by:
sendin interfaceCatalinaCluster- Parameters:
msg- ClusterMessagedest- Member
-
send
Sends a message with the specified sendOptions to a specific member in the cluster.- Specified by:
sendin interfaceCatalinaCluster- Parameters:
msg- ClusterMessagedest- MembersendOptions- sendOptions
-
memberAdded
A member was added to the group- Specified by:
memberAddedin interfaceMembershipListener- Parameters:
member- Member - the member that was added
-
memberDisappeared
A member was removed from the group
If the member left voluntarily, the Member.getCommand will contain the Member.SHUTDOWN_PAYLOAD data- Specified by:
memberDisappearedin interfaceMembershipListener- Parameters:
member- Member- See Also:
-
accept
Invoked by the channel to determine if the listener will process this message or not.- Specified by:
acceptin interfaceChannelListener- Parameters:
msg- Serializablesender- Member- Returns:
- boolean
-
messageReceived
Receive a message from the channel- Specified by:
messageReceivedin interfaceChannelListener- Parameters:
message- Serializablesender- - the source of the message
-
messageReceived
Processes a received cluster message by dispatching it to registered cluster listeners.- Parameters:
message- the cluster message that was received
-
getChannelStartOptions
public int getChannelStartOptions()Returns the channel start options.- Returns:
- the channel start options
-
setChannelStartOptions
public void setChannelStartOptions(int channelStartOptions) Sets the channel start options.- Parameters:
channelStartOptions- the channel start options
-
getDomainInternal
Returns the JMX domain for this cluster, derived from the associated container.- Specified by:
getDomainInternalin classLifecycleMBeanBase- Returns:
- the JMX domain, or
nullif no container is set
-
getObjectNameKeyProperties
Returns the key properties used to build the JMX ObjectName for this cluster.- Specified by:
getObjectNameKeyPropertiesin classLifecycleMBeanBase- Returns:
- the key properties string for JMX registration
-