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:
javax.management.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 org.apache.catalina.Lifecycle
Lifecycle.SingleUse
-
-
Field Summary
Fields Modifier and Type Field Description static java.lang.StringAFTER_MANAGERREGISTER_EVENTstatic java.lang.StringAFTER_MANAGERUNREGISTER_EVENTstatic java.lang.StringAFTER_MEMBERREGISTER_EVENTstatic java.lang.StringAFTER_MEMBERUNREGISTER_EVENTstatic java.lang.StringBEFORE_MANAGERREGISTER_EVENTstatic java.lang.StringBEFORE_MANAGERUNREGISTER_EVENTstatic java.lang.StringBEFORE_MEMBERREGISTER_EVENTstatic java.lang.StringBEFORE_MEMBERUNREGISTER_EVENTprotected ChannelchannelGroup channel.protected java.util.List<ClusterListener>clusterListenersListeners of messagesprotected java.lang.StringclusterNameThe cluster name to joinprotected ContainercontainerThe Container associated with this Cluster.protected booleanhasMembershas membersprotected booleanheartbeatBackgroundEnabledcall Channel.heartbeat() at container background threadstatic Loglogprotected java.util.Map<java.lang.String,ClusterManager>managersThe context name <-> manager association for distributed contexts.protected ClusterManagermanagerTemplatestatic java.lang.StringRECEIVE_MESSAGE_FAILURE_EVENTstatic java.lang.StringSEND_MESSAGE_FAILURE_EVENTprotected static StringManagersmThe string manager for this package.protected java.beans.PropertyChangeSupportsupportThe 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 Description SimpleTcpCluster()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanaccept(java.io.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.voidaddValve(Valve valve)Add cluster valve.voidbackgroundProcess()Execute a periodic task, such as reloading, etc.protected voidcheckDefaults()ManagercreateManager(java.lang.String name)Create a new manager which will use this cluster to replicate its sessions.protected voiddestroyInternal()Subclasses implement this method to perform any instance destruction required.ClusterListener[]findClusterListeners()Get the cluster listeners associated with this cluster.ChannelgetChannel()intgetChannelSendOptions()java.lang.StringgetChannelSendOptionsName()returns the SendOptions as a comma separated list of names for use by JMXintgetChannelStartOptions()ClusterDeployergetClusterDeployer()java.lang.StringgetClusterName()Return the name of the cluster that this Server is currently configured to operate within.ContainergetContainer()Get theContainerwith which this instance is associated.protected java.lang.StringgetDomainInternal()Method implemented by subclasses to identify the domain in which MBeans should be registered.MembergetLocalMember()ManagergetManager(java.lang.String name)Get Managerjava.lang.StringgetManagerName(java.lang.String name, Manager manager)Get a new cluster name for a manager.java.util.Map<java.lang.String,ClusterManager>getManagers()ClusterManagergetManagerTemplate()Member[]getMembers()protected java.lang.StringgetObjectNameKeyProperties()Allow subclasses to specify the key properties component of theObjectNamethat will be used to register this component.Valve[]getValves()booleanhasMembers()protected voidinitInternal()Subclasses implement this method to perform any instance initialisation required.booleanisHeartbeatBackgroundEnabled()Return heartbeat enable flag (default false)booleanisNotifyLifecycleListenerOnFailure()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(java.io.Serializable message, Member sender)Receive a message from the channelvoidmessageReceived(ClusterMessage message)protected voidregisterClusterValve()register 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)voidsetChannelSendOptions(java.lang.String channelSendOptions)voidsetChannelStartOptions(int channelStartOptions)voidsetClusterDeployer(ClusterDeployer clusterDeployer)Set a new Deployer, must be set before the cluster started.voidsetClusterName(java.lang.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)enabled that container backgroundThread call heartbeat at channelvoidsetManagerTemplate(ClusterManager managerTemplate)voidsetNotifyLifecycleListenerOnFailure(boolean notifyListenerOnFailure)protected voidstartInternal()Start Cluster and implement the requirements ofLifecycleBase.startInternal().protected voidstopInternal()Stop Cluster and implement the requirements ofLifecycleBase.stopInternal().java.lang.StringtoString()protected voidunregisterClusterValve()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, 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 Detail
-
log
public static final Log log
-
BEFORE_MEMBERREGISTER_EVENT
public static final java.lang.String BEFORE_MEMBERREGISTER_EVENT
- See Also:
- Constant Field Values
-
AFTER_MEMBERREGISTER_EVENT
public static final java.lang.String AFTER_MEMBERREGISTER_EVENT
- See Also:
- Constant Field Values
-
BEFORE_MANAGERREGISTER_EVENT
public static final java.lang.String BEFORE_MANAGERREGISTER_EVENT
- See Also:
- Constant Field Values
-
AFTER_MANAGERREGISTER_EVENT
public static final java.lang.String AFTER_MANAGERREGISTER_EVENT
- See Also:
- Constant Field Values
-
BEFORE_MANAGERUNREGISTER_EVENT
public static final java.lang.String BEFORE_MANAGERUNREGISTER_EVENT
- See Also:
- Constant Field Values
-
AFTER_MANAGERUNREGISTER_EVENT
public static final java.lang.String AFTER_MANAGERUNREGISTER_EVENT
- See Also:
- Constant Field Values
-
BEFORE_MEMBERUNREGISTER_EVENT
public static final java.lang.String BEFORE_MEMBERUNREGISTER_EVENT
- See Also:
- Constant Field Values
-
AFTER_MEMBERUNREGISTER_EVENT
public static final java.lang.String AFTER_MEMBERUNREGISTER_EVENT
- See Also:
- Constant Field Values
-
SEND_MESSAGE_FAILURE_EVENT
public static final java.lang.String SEND_MESSAGE_FAILURE_EVENT
- See Also:
- Constant Field Values
-
RECEIVE_MESSAGE_FAILURE_EVENT
public static final java.lang.String RECEIVE_MESSAGE_FAILURE_EVENT
- See Also:
- Constant Field Values
-
channel
protected Channel channel
Group channel.
-
sm
protected static final StringManager sm
The string manager for this package.
-
clusterName
protected java.lang.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 final java.beans.PropertyChangeSupport support
The property change support for this component.
-
managers
protected final java.util.Map<java.lang.String,ClusterManager> managers
The context name <-> manager association for distributed contexts.
-
managerTemplate
protected ClusterManager managerTemplate
-
clusterListeners
protected final java.util.List<ClusterListener> clusterListeners
Listeners of messages
-
hasMembers
protected boolean hasMembers
has members
-
-
Method Detail
-
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(java.lang.String clusterName)
Description copied from interface:ClusterSet 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
public java.lang.String getClusterName()
Description copied from interface:ClusterReturn 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
public void setContainer(Container container)
Description copied from interface:ContainedSet 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
public Container getContainer()
Description copied from interface:ContainedGet 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()
- Returns:
- Returns the notifyLifecycleListenerOnFailure.
-
setNotifyLifecycleListenerOnFailure
public void setNotifyLifecycleListenerOnFailure(boolean notifyListenerOnFailure)
- Parameters:
notifyListenerOnFailure- The notifyLifecycleListenerOnFailure to set.
-
addValve
public void addValve(Valve valve)
Description copied from interface:CatalinaClusterAdd cluster valve. Cluster Valves are only add to container when cluster is started.- Specified by:
addValvein interfaceCatalinaCluster- Parameters:
valve- The new cluster Valve.
-
getValves
public Valve[] getValves()
- Specified by:
getValvesin interfaceCatalinaCluster- Returns:
- the 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.- Returns:
- the listener array
-
addClusterListener
public void addClusterListener(ClusterListener listener)
Description copied from interface:CatalinaClusterAdd cluster message listener and register cluster to this listener.- Specified by:
addClusterListenerin interfaceCatalinaCluster- Parameters:
listener- The new listener
-
removeClusterListener
public void removeClusterListener(ClusterListener listener)
Description copied from interface:CatalinaClusterRemove message listener and deregister Cluster from listener.- Specified by:
removeClusterListenerin interfaceCatalinaCluster- Parameters:
listener- The listener to remove
-
getClusterDeployer
public ClusterDeployer getClusterDeployer()
- Specified by:
getClusterDeployerin interfaceCatalinaCluster- Returns:
- the current Deployer
-
setClusterDeployer
public void setClusterDeployer(ClusterDeployer clusterDeployer)
Description copied from interface:CatalinaClusterSet a new Deployer, must be set before the cluster started.- Specified by:
setClusterDeployerin interfaceCatalinaCluster- Parameters:
clusterDeployer- The associated deployer
-
setChannel
public void setChannel(Channel channel)
Description copied from interface:CatalinaClusterSet the channel associated with the cluster.- Specified by:
setChannelin interfaceCatalinaCluster- Parameters:
channel- the channel
-
setManagerTemplate
public void setManagerTemplate(ClusterManager managerTemplate)
-
setChannelSendOptions
public void setChannelSendOptions(int channelSendOptions)
-
setChannelSendOptions
public void setChannelSendOptions(java.lang.String channelSendOptions)
-
hasMembers
public boolean hasMembers()
- Specified by:
hasMembersin interfaceCatalinaCluster- Returns:
trueif the cluster has members.
-
getMembers
public Member[] getMembers()
- Specified by:
getMembersin interfaceCatalinaCluster- Returns:
- an array containing all the members currently participating in the cluster.
-
getLocalMember
public Member getLocalMember()
- Specified by:
getLocalMemberin interfaceCatalinaCluster- Returns:
- the member that represents this node.
-
getManagers
public java.util.Map<java.lang.String,ClusterManager> getManagers()
- Specified by:
getManagersin interfaceCatalinaCluster- Returns:
- The map of managers
-
getChannel
public Channel getChannel()
- Specified by:
getChannelin interfaceCatalinaCluster- Returns:
- the channel associated with the cluster
-
getManagerTemplate
public ClusterManager getManagerTemplate()
-
getChannelSendOptions
public int getChannelSendOptions()
-
getChannelSendOptionsName
public java.lang.String 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
public Manager createManager(java.lang.String name)
Description copied from interface:ClusterCreate 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
public void registerManager(Manager manager)
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
public void removeManager(Manager manager)
Description copied from interface:ClusterRemoves a manager from the cluster- Specified by:
removeManagerin interfaceCluster- Parameters:
manager- Manager
-
getManagerName
public java.lang.String getManagerName(java.lang.String name, Manager manager)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
public Manager getManager(java.lang.String name)
Description copied from interface:CatalinaClusterGet Manager- Specified by:
getManagerin interfaceCatalinaCluster- Parameters:
name- The manager name- Returns:
- The manager
-
backgroundProcess
public void backgroundProcess()
Description copied from interface:ClusterExecute 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
protected void initInternal() throws LifecycleExceptionDescription copied from class:LifecycleBaseSubclasses implement this method to perform any instance initialisation required.- Overrides:
initInternalin classLifecycleMBeanBase- Throws:
LifecycleException- If the initialisation fails
-
startInternal
protected void startInternal() throws LifecycleExceptionStart 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
protected void stopInternal() throws LifecycleExceptionStop 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
protected void destroyInternal() throws LifecycleExceptionDescription copied from class:LifecycleBaseSubclasses implement this method to perform any instance destruction required.- Overrides:
destroyInternalin classLifecycleMBeanBase- Throws:
LifecycleException- If the destruction fails
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
send
public void send(ClusterMessage msg)
Description copied from interface:CatalinaClusterSends a message to all the members in the cluster- Specified by:
sendin interfaceCatalinaCluster- Parameters:
msg- ClusterMessage
-
send
public void send(ClusterMessage msg, Member dest)
Description copied from interface:CatalinaClusterSends a message to a specific member in the cluster.- Specified by:
sendin interfaceCatalinaCluster- Parameters:
msg- ClusterMessagedest- Member
-
send
public void send(ClusterMessage msg, Member dest, int sendOptions)
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
public void memberAdded(Member member)
Description copied from interface:MembershipListenerA member was added to the group- Specified by:
memberAddedin interfaceMembershipListener- Parameters:
member- Member - the member that was added
-
memberDisappeared
public void memberDisappeared(Member member)
Description copied from interface:MembershipListenerA 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:
Member.SHUTDOWN_PAYLOAD
-
accept
public boolean accept(java.io.Serializable msg, Member sender)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
public void messageReceived(java.io.Serializable message, Member sender)Description copied from interface:ChannelListenerReceive a message from the channel- Specified by:
messageReceivedin interfaceChannelListener- Parameters:
message- Serializablesender- - the source of the message
-
messageReceived
public void messageReceived(ClusterMessage message)
-
getChannelStartOptions
public int getChannelStartOptions()
-
setChannelStartOptions
public void setChannelStartOptions(int channelStartOptions)
-
getDomainInternal
protected java.lang.String getDomainInternal()
Description copied from class:LifecycleMBeanBaseMethod implemented by subclasses 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
protected java.lang.String getObjectNameKeyProperties()
Description copied from class:LifecycleMBeanBaseAllow subclasses 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
-
-