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
FieldsModifier and TypeFieldDescriptionstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringprotected 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 Logprotected final Map<String,ClusterManager> The context name <-> manager association for distributed contexts.protected ClusterManagerstatic final Stringstatic final Stringprotected static final StringManagerThe string manager for this package.protected final PropertyChangeSupportThe property change support for this component.Fields inherited from class org.apache.catalina.util.LifecycleMBeanBase
mserverFields 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 -
Method Summary
Modifier and TypeMethodDescriptionbooleanaccept(Serializable msg, Member sender) notify all listeners from receiving a new message is not ClusterMessage emit Failure Event to LifecycleListenervoidaddClusterListener(ClusterListener listener) Add cluster message listener and register cluster to this listener.voidAdd cluster valve Cluster Valves are only add to container when cluster is started!voidExecute a periodic task, such as reloading, etc.protected voidcreateManager(String name) Create new Manager without add to cluster (comes with start the manager)protected voidSub-classes wishing to perform additional clean-up should override this method, ensuring that super.destroyInternal() is the last call in the overriding method.Get the cluster listeners associated with this cluster.intreturns the SendOptions as a comma separated list of names for use by JMXintReturn the name of the cluster that this Server is currently configured to operate within.Get the Container associated with our Clusterprotected StringMethod implemented by sub-classes to identify the domain in which MBeans should be registered.Return the member that represents this node.getManager(String name) Get ManagergetManagerName(String name, Manager manager) Get a new cluster name for a manager.Member[]Get all current cluster membersprotected StringAllow sub-classes to specify the key properties component of theObjectNamethat will be used to register this component.Valve[]get all cluster valvesbooleanprotected voidSub-classes wishing to perform additional initialization should override this method, ensuring that super.initInternal() is the first call in the overriding method.booleanReturn heartbeat enable flag (default false)booleanvoidmemberAdded(Member member) New cluster member is registeredvoidmemberDisappeared(Member member) Cluster member is gonevoidmessageReceived(Serializable message, Member sender) Receive a message from the channelvoidmessageReceived(ClusterMessage message) 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) Remove an application from cluster replication bus.voidsend(ClusterMessage msg) send message to all cluster membersvoidsend(ClusterMessage msg, Member dest) send a cluster message to one membervoidsend(ClusterMessage msg, Member dest, int sendOptions) Sends a message with the specified sendOptions to a specific member in the cluster.voidsetChannel(Channel channel) voidsetChannelSendOptions(int channelSendOptions) voidsetChannelSendOptions(String 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 ClustervoidsetHeartbeatBackgroundEnabled(boolean heartbeatBackgroundEnabled) enabled that container backgroundThread call heartbeat at channelvoidsetManagerTemplate(ClusterManager managerTemplate) voidsetNotifyLifecycleListenerOnFailure(boolean notifyListenerOnFailure) protected voidStart Cluster and implement the requirements ofLifecycleBase.startInternal().protected voidStop Cluster and implement the requirements ofLifecycleBase.stopInternal().toString()Return a String rendering of this object.protected voidunregister all cluster valve to host or engineMethods inherited from class org.apache.catalina.util.LifecycleMBeanBase
getDomain, getObjectName, postDeregister, postRegister, preDeregister, preRegister, register, setDomain, unregister, unregisterMethods inherited from class org.apache.catalina.util.LifecycleBase
addLifecycleListener, destroy, findLifecycleListeners, fireLifecycleEvent, getState, getStateName, getThrowOnFailure, init, removeLifecycleListener, setState, setState, setThrowOnFailure, start, stopMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface org.apache.catalina.tribes.ChannelListener
equals, hashCode
-
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
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 the Container associated with our Cluster- Specified by:
setContainerin interfaceContained- Parameters:
container- The Container to use
-
getContainer
Get the Container associated with our Cluster- Specified by:
getContainerin interfaceContained- 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
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
get all cluster valves- Specified by:
getValvesin interfaceCatalinaCluster- Returns:
- 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- See Also:
-
removeClusterListener
Remove message listener and deregister Cluster from listener.- Specified by:
removeClusterListenerin interfaceCatalinaCluster- Parameters:
listener- The listener to remove- See Also:
-
getClusterDeployer
- Specified by:
getClusterDeployerin interfaceCatalinaCluster- Returns:
- the current Deployer
-
setClusterDeployer
set a new Deployer, must be set before cluster started!- Specified by:
setClusterDeployerin interfaceCatalinaCluster- Parameters:
clusterDeployer- The associated deployer
-
setChannel
- Specified by:
setChannelin interfaceCatalinaCluster
-
setManagerTemplate
-
setChannelSendOptions
public void setChannelSendOptions(int channelSendOptions) -
setChannelSendOptions
-
hasMembers
public boolean hasMembers()- Specified by:
hasMembersin interfaceCatalinaCluster- Returns:
trueif the cluster has members.
-
getMembers
Get all current cluster members- Specified by:
getMembersin interfaceCatalinaCluster- Returns:
- all members or empty array
-
getLocalMember
Return the member that represents this node.- Specified by:
getLocalMemberin interfaceCatalinaCluster- Returns:
- Member
-
getManagers
- Specified by:
getManagersin interfaceCatalinaCluster- Returns:
- Returns the managers.
-
getChannel
- Specified by:
getChannelin interfaceCatalinaCluster
-
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
Create new Manager without add to cluster (comes with start the manager)- Specified by:
createManagerin interfaceCluster- Parameters:
name- Context Name of this manager- Returns:
- The newly created Manager instance
- See Also:
-
registerManager
Description copied from interface:ClusterRegister 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
Remove an application from cluster replication bus.- Specified by:
removeManagerin interfaceCluster- Parameters:
manager- The manager- See Also:
-
getManagerName
Description copied from interface:CatalinaClusterGet 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
Description copied from interface:CatalinaClusterGet 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- See Also:
-
initInternal
Description copied from class:LifecycleMBeanBaseSub-classes wishing to perform additional initialization should override this method, ensuring that super.initInternal() is the first call in the overriding method.- Overrides:
initInternalin classLifecycleMBeanBase- Throws:
LifecycleException- If the initialisation fails
-
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() -
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
Description copied from class:LifecycleMBeanBaseSub-classes wishing to perform additional clean-up should override this method, ensuring that super.destroyInternal() is the last call in the overriding method.- Overrides:
destroyInternalin classLifecycleMBeanBase- Throws:
LifecycleException- If the destruction fails
-
toString
Return a String rendering of this object. -
send
send message to all cluster members- Specified by:
sendin interfaceCatalinaCluster- Parameters:
msg- message to transfer- See Also:
-
send
send a cluster message to one member- Specified by:
sendin interfaceCatalinaCluster- Parameters:
msg- message to transferdest- Receiver member- See Also:
-
send
Description copied from interface:CatalinaClusterSends a message with the specified sendOptions to a specific member in the cluster.- Specified by:
sendin interfaceCatalinaCluster- Parameters:
msg- ClusterMessagedest- MembersendOptions- sendOptions
-
memberAdded
New cluster member is registered- Specified by:
memberAddedin interfaceMembershipListener- Parameters:
member- Member - the member that was added- See Also:
-
memberDisappeared
Cluster member is gone- Specified by:
memberDisappearedin 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:
acceptin interfaceChannelListener- Parameters:
msg- received Messagesender- Member- Returns:
- boolean
-
messageReceived
Description copied from interface:ChannelListenerReceive a message from the channel- Specified by:
messageReceivedin 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:LifecycleMBeanBaseMethod implemented by sub-classes to identify the domain in which MBeans should be registered.- Specified by:
getDomainInternalin classLifecycleMBeanBase- Returns:
- The name of the domain to use to register MBeans.
-
getObjectNameKeyProperties
Description copied from class:LifecycleMBeanBaseAllow sub-classes to specify the key properties component of theObjectNamethat will be used to register this component.- Specified by:
getObjectNameKeyPropertiesin classLifecycleMBeanBase- Returns:
- The string representation of the key properties component of the
desired
ObjectName
-