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. FIXME wrote testcases- Author:
- Remy Maucherat, Peter Rossbach
 
- 
- 
Nested Class Summary- 
Nested classes/interfaces inherited from interface org.apache.catalina.LifecycleLifecycle.SingleUse
 
- 
 - 
Field SummaryFields 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.LifecycleMBeanBasemserver
 - 
Fields inherited from interface org.apache.catalina.LifecycleAFTER_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 SummaryConstructors Constructor Description SimpleTcpCluster()
 - 
Method SummaryAll 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 Cluster Valves are only add to container when cluster is started!voidbackgroundProcess()Execute a periodic task, such as reloading, etc.protected voidcheckDefaults()ManagercreateManager(java.lang.String name)Create new Manager without add to cluster (comes with start the manager)protected voiddestroyInternal()Sub-classes wishing to perform additional clean-up should override this method, ensuring that super.destroyInternal() is the last call in the overriding method.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 the Container associated with our Clusterprotected java.lang.StringgetDomainInternal()Method implemented by sub-classes to identify the domain in which MBeans should be registered.MembergetLocalMember()Return the member that represents this node.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()Get all current cluster membersprotected java.lang.StringgetObjectNameKeyProperties()Allow sub-classes to specify the key properties component of theObjectNamethat will be used to register this component.Valve[]getValves()get all cluster valvesbooleanhasMembers()protected voidinitInternal()Sub-classes wishing to perform additional initialization should override this method, ensuring that super.initInternal() is the first call in the overriding method.booleanisHeartbeatBackgroundEnabled()Return heartbeat enable flag (default false)booleanisNotifyLifecycleListenerOnFailure()voidmemberAdded(Member member)New cluster member is registeredvoidmemberDisappeared(Member member)Cluster member is gonevoidmessageReceived(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)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(java.lang.String channelSendOptions)voidsetChannelStartOptions(int channelStartOptions)voidsetClusterDeployer(ClusterDeployer clusterDeployer)set a new Deployer, must be set before 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 the Container associated with our ClustervoidsetHeartbeatBackgroundEnabled(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()Return a String rendering of this object.protected voidunregisterClusterValve()unregister all cluster valve to host or engine- 
Methods inherited from class org.apache.catalina.util.LifecycleMBeanBasegetDomain, getObjectName, postDeregister, postRegister, preDeregister, preRegister, register, setDomain, unregister, unregister
 - 
Methods inherited from class org.apache.catalina.util.LifecycleBaseaddLifecycleListener, destroy, findLifecycleListeners, fireLifecycleEvent, getState, getStateName, getThrowOnFailure, init, removeLifecycleListener, setState, setState, setThrowOnFailure, start, stop
 - 
Methods inherited from class java.lang.Objectclone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 - 
Methods inherited from interface org.apache.catalina.tribes.ChannelListenerequals, hashCode
 
- 
 
- 
- 
- 
Field Detail- 
logpublic static final Log log 
 - 
BEFORE_MEMBERREGISTER_EVENTpublic static final java.lang.String BEFORE_MEMBERREGISTER_EVENT - See Also:
- Constant Field Values
 
 - 
AFTER_MEMBERREGISTER_EVENTpublic static final java.lang.String AFTER_MEMBERREGISTER_EVENT - See Also:
- Constant Field Values
 
 - 
BEFORE_MANAGERREGISTER_EVENTpublic static final java.lang.String BEFORE_MANAGERREGISTER_EVENT - See Also:
- Constant Field Values
 
 - 
AFTER_MANAGERREGISTER_EVENTpublic static final java.lang.String AFTER_MANAGERREGISTER_EVENT - See Also:
- Constant Field Values
 
 - 
BEFORE_MANAGERUNREGISTER_EVENTpublic static final java.lang.String BEFORE_MANAGERUNREGISTER_EVENT - See Also:
- Constant Field Values
 
 - 
AFTER_MANAGERUNREGISTER_EVENTpublic static final java.lang.String AFTER_MANAGERUNREGISTER_EVENT - See Also:
- Constant Field Values
 
 - 
BEFORE_MEMBERUNREGISTER_EVENTpublic static final java.lang.String BEFORE_MEMBERUNREGISTER_EVENT - See Also:
- Constant Field Values
 
 - 
AFTER_MEMBERUNREGISTER_EVENTpublic static final java.lang.String AFTER_MEMBERUNREGISTER_EVENT - See Also:
- Constant Field Values
 
 - 
SEND_MESSAGE_FAILURE_EVENTpublic static final java.lang.String SEND_MESSAGE_FAILURE_EVENT - See Also:
- Constant Field Values
 
 - 
RECEIVE_MESSAGE_FAILURE_EVENTpublic static final java.lang.String RECEIVE_MESSAGE_FAILURE_EVENT - See Also:
- Constant Field Values
 
 - 
channelprotected Channel channel Group channel.
 - 
smprotected static final StringManager sm The string manager for this package.
 - 
clusterNameprotected java.lang.String clusterName The cluster name to join
 - 
heartbeatBackgroundEnabledprotected boolean heartbeatBackgroundEnabled call Channel.heartbeat() at container background thread- See Also:
- GroupChannel.heartbeat()
 
 - 
containerprotected Container container The Container associated with this Cluster.
 - 
supportprotected final java.beans.PropertyChangeSupport support The property change support for this component.
 - 
managersprotected final java.util.Map<java.lang.String,ClusterManager> managers The context name <-> manager association for distributed contexts.
 - 
managerTemplateprotected ClusterManager managerTemplate 
 - 
clusterListenersprotected final java.util.List<ClusterListener> clusterListeners Listeners of messages
 - 
hasMembersprotected boolean hasMembers has members
 
- 
 - 
Method Detail- 
isHeartbeatBackgroundEnabledpublic boolean isHeartbeatBackgroundEnabled() Return heartbeat enable flag (default false)- Returns:
- the heartbeatBackgroundEnabled
 
 - 
setHeartbeatBackgroundEnabledpublic void setHeartbeatBackgroundEnabled(boolean heartbeatBackgroundEnabled) enabled that container backgroundThread call heartbeat at channel- Parameters:
- heartbeatBackgroundEnabled- the heartbeatBackgroundEnabled to set
 
 - 
setClusterNamepublic void setClusterName(java.lang.String clusterName) Set the name of the cluster to join, if no cluster with this name is present create one.- Specified by:
- setClusterNamein interface- Cluster
- Parameters:
- clusterName- The clustername to join
 
 - 
getClusterNamepublic java.lang.String getClusterName() Return the name of the cluster that this Server is currently configured to operate within.- Specified by:
- getClusterNamein interface- Cluster
- Returns:
- The name of the cluster associated with this server
 
 - 
setContainerpublic void setContainer(Container container) Set the Container associated with our Cluster- Specified by:
- setContainerin interface- Contained
- Parameters:
- container- The Container to use
 
 - 
getContainerpublic Container getContainer() Get the Container associated with our Cluster- Specified by:
- getContainerin interface- Contained
- Returns:
- The Container associated with our Cluster
 
 - 
isNotifyLifecycleListenerOnFailurepublic boolean isNotifyLifecycleListenerOnFailure() - Returns:
- Returns the notifyLifecycleListenerOnFailure.
 
 - 
setNotifyLifecycleListenerOnFailurepublic void setNotifyLifecycleListenerOnFailure(boolean notifyListenerOnFailure) - Parameters:
- notifyListenerOnFailure- The notifyLifecycleListenerOnFailure to set.
 
 - 
addValvepublic void addValve(Valve valve) Add cluster valve Cluster Valves are only add to container when cluster is started!- Specified by:
- addValvein interface- CatalinaCluster
- Parameters:
- valve- The new cluster Valve.
 
 - 
getValvespublic Valve[] getValves() get all cluster valves- Specified by:
- getValvesin interface- CatalinaCluster
- Returns:
- current cluster valves
 
 - 
findClusterListenerspublic 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
 
 - 
addClusterListenerpublic void addClusterListener(ClusterListener listener) Add cluster message listener and register cluster to this listener.- Specified by:
- addClusterListenerin interface- CatalinaCluster
- Parameters:
- listener- The new listener
- See Also:
- CatalinaCluster.addClusterListener(org.apache.catalina.ha.ClusterListener)
 
 - 
removeClusterListenerpublic void removeClusterListener(ClusterListener listener) Remove message listener and deregister Cluster from listener.- Specified by:
- removeClusterListenerin interface- CatalinaCluster
- Parameters:
- listener- The listener to remove
- See Also:
- CatalinaCluster.removeClusterListener(org.apache.catalina.ha.ClusterListener)
 
 - 
getClusterDeployerpublic ClusterDeployer getClusterDeployer() - Specified by:
- getClusterDeployerin interface- CatalinaCluster
- Returns:
- the current Deployer
 
 - 
setClusterDeployerpublic void setClusterDeployer(ClusterDeployer clusterDeployer) set a new Deployer, must be set before cluster started!- Specified by:
- setClusterDeployerin interface- CatalinaCluster
- Parameters:
- clusterDeployer- The associated deployer
 
 - 
setChannelpublic void setChannel(Channel channel) - Specified by:
- setChannelin interface- CatalinaCluster
 
 - 
setManagerTemplatepublic void setManagerTemplate(ClusterManager managerTemplate) 
 - 
setChannelSendOptionspublic void setChannelSendOptions(int channelSendOptions) 
 - 
setChannelSendOptionspublic void setChannelSendOptions(java.lang.String channelSendOptions) 
 - 
hasMemberspublic boolean hasMembers() - Specified by:
- hasMembersin interface- CatalinaCluster
- Returns:
- trueif the cluster has members.
 
 - 
getMemberspublic Member[] getMembers() Get all current cluster members- Specified by:
- getMembersin interface- CatalinaCluster
- Returns:
- all members or empty array
 
 - 
getLocalMemberpublic Member getLocalMember() Return the member that represents this node.- Specified by:
- getLocalMemberin interface- CatalinaCluster
- Returns:
- Member
 
 - 
getManagerspublic java.util.Map<java.lang.String,ClusterManager> getManagers() - Specified by:
- getManagersin interface- CatalinaCluster
- Returns:
- Returns the managers.
 
 - 
getChannelpublic Channel getChannel() - Specified by:
- getChannelin interface- CatalinaCluster
 
 - 
getManagerTemplatepublic ClusterManager getManagerTemplate() 
 - 
getChannelSendOptionspublic int getChannelSendOptions() 
 - 
getChannelSendOptionsNamepublic 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
 
 - 
createManagerpublic Manager createManager(java.lang.String name) Create new Manager without add to cluster (comes with start the manager)- Specified by:
- createManagerin interface- Cluster
- Parameters:
- name- Context Name of this manager
- Returns:
- The newly created Manager instance
- See Also:
- Cluster.createManager(java.lang.String),- LifecycleBase.start()
 
 - 
registerManagerpublic 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 interface- Cluster
- Parameters:
- manager- Manager
 
 - 
removeManagerpublic void removeManager(Manager manager) Remove an application from cluster replication bus.- Specified by:
- removeManagerin interface- Cluster
- Parameters:
- manager- The manager
- See Also:
- Cluster.removeManager(Manager)
 
 - 
getManagerNamepublic 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 interface- CatalinaCluster
- Parameters:
- name- Override name (optional)
- manager- The manager
- Returns:
- the manager name in the cluster
 
 - 
getManagerpublic Manager getManager(java.lang.String name) Description copied from interface:CatalinaClusterGet Manager- Specified by:
- getManagerin interface- CatalinaCluster
- Parameters:
- name- The manager name
- Returns:
- The manager
 
 - 
backgroundProcesspublic 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 interface- Cluster
- See Also:
- FarmWarDeployer.backgroundProcess(),- GroupChannel.heartbeat()
 
 - 
initInternalprotected void initInternal() throws LifecycleExceptionDescription 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 class- LifecycleMBeanBase
- Throws:
- LifecycleException- If the initialisation fails
 
 - 
startInternalprotected void startInternal() throws LifecycleExceptionStart Cluster and implement the requirements ofLifecycleBase.startInternal().- Specified by:
- startInternalin class- LifecycleBase
- Throws:
- LifecycleException- if this component detects a fatal error that prevents this component from being used
 
 - 
checkDefaultsprotected void checkDefaults() 
 - 
registerClusterValveprotected void registerClusterValve() register all cluster valve to host or engine
 - 
unregisterClusterValveprotected void unregisterClusterValve() unregister all cluster valve to host or engine
 - 
stopInternalprotected void stopInternal() throws LifecycleExceptionStop Cluster and implement the requirements ofLifecycleBase.stopInternal().- Specified by:
- stopInternalin class- LifecycleBase
- Throws:
- LifecycleException- if this component detects a fatal error that prevents this component from being used
 
 - 
destroyInternalprotected void destroyInternal() throws LifecycleExceptionDescription 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 class- LifecycleMBeanBase
- Throws:
- LifecycleException- If the destruction fails
 
 - 
toStringpublic java.lang.String toString() Return a String rendering of this object.- Overrides:
- toStringin class- java.lang.Object
 
 - 
sendpublic void send(ClusterMessage msg) send message to all cluster members- Specified by:
- sendin interface- CatalinaCluster
- Parameters:
- msg- message to transfer
- See Also:
- CatalinaCluster.send(org.apache.catalina.ha.ClusterMessage)
 
 - 
sendpublic void send(ClusterMessage msg, Member dest) send a cluster message to one member- Specified by:
- sendin interface- CatalinaCluster
- Parameters:
- msg- message to transfer
- dest- Receiver member
- See Also:
- CatalinaCluster.send(org.apache.catalina.ha.ClusterMessage, org.apache.catalina.tribes.Member)
 
 - 
sendpublic 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 interface- CatalinaCluster
- Parameters:
- msg- ClusterMessage
- dest- Member
- sendOptions- sendOptions
 
 - 
memberAddedpublic void memberAdded(Member member) New cluster member is registered- Specified by:
- memberAddedin interface- MembershipListener
- Parameters:
- member- Member - the member that was added
- See Also:
- MembershipListener.memberAdded(org.apache.catalina.tribes.Member)
 
 - 
memberDisappearedpublic void memberDisappeared(Member member) Cluster member is gone- Specified by:
- memberDisappearedin interface- MembershipListener
- Parameters:
- member- Member
- See Also:
- MembershipListener.memberDisappeared(org.apache.catalina.tribes.Member)
 
 - 
acceptpublic 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 interface- ChannelListener
- Parameters:
- msg- received Message
- sender- Member
- Returns:
- boolean
 
 - 
messageReceivedpublic void messageReceived(java.io.Serializable message, Member sender)Description copied from interface:ChannelListenerReceive a message from the channel- Specified by:
- messageReceivedin interface- ChannelListener
- Parameters:
- message- Serializable
- sender- - the source of the message
 
 - 
messageReceivedpublic void messageReceived(ClusterMessage message) 
 - 
getChannelStartOptionspublic int getChannelStartOptions() 
 - 
setChannelStartOptionspublic void setChannelStartOptions(int channelStartOptions) 
 - 
getDomainInternalprotected java.lang.String getDomainInternal() Description copied from class:LifecycleMBeanBaseMethod implemented by sub-classes to identify the domain in which MBeans should be registered.- Specified by:
- getDomainInternalin class- LifecycleMBeanBase
- Returns:
- The name of the domain to use to register MBeans.
 
 - 
getObjectNameKeyPropertiesprotected java.lang.String 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 class- LifecycleMBeanBase
- Returns:
- The string representation of the key properties component of the
          desired ObjectName
 
 
- 
 
-