Class 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
  • Field Details

    • log

      public static final Log log
    • BEFORE_MEMBERREGISTER_EVENT

      public static final String BEFORE_MEMBERREGISTER_EVENT
      See Also:
    • AFTER_MEMBERREGISTER_EVENT

      public static final String AFTER_MEMBERREGISTER_EVENT
      See Also:
    • BEFORE_MANAGERREGISTER_EVENT

      public static final String BEFORE_MANAGERREGISTER_EVENT
      See Also:
    • AFTER_MANAGERREGISTER_EVENT

      public static final String AFTER_MANAGERREGISTER_EVENT
      See Also:
    • BEFORE_MANAGERUNREGISTER_EVENT

      public static final String BEFORE_MANAGERUNREGISTER_EVENT
      See Also:
    • AFTER_MANAGERUNREGISTER_EVENT

      public static final String AFTER_MANAGERUNREGISTER_EVENT
      See Also:
    • BEFORE_MEMBERUNREGISTER_EVENT

      public static final String BEFORE_MEMBERUNREGISTER_EVENT
      See Also:
    • AFTER_MEMBERUNREGISTER_EVENT

      public static final String AFTER_MEMBERUNREGISTER_EVENT
      See Also:
    • SEND_MESSAGE_FAILURE_EVENT

      public static final String SEND_MESSAGE_FAILURE_EVENT
      See Also:
    • RECEIVE_MESSAGE_FAILURE_EVENT

      public static final String RECEIVE_MESSAGE_FAILURE_EVENT
      See Also:
    • channel

      protected Channel channel
      Group channel.
    • sm

      protected static final StringManager sm
      The string manager for this package.
    • clusterName

      protected String clusterName
      The cluster name to join
    • heartbeatBackgroundEnabled

      protected boolean heartbeatBackgroundEnabled
      call Channel.heartbeat() at container background thread
      See Also:
    • container

      protected Container container
      The Container associated with this Cluster.
    • support

      protected final PropertyChangeSupport support
      The property change support for this component.
    • managers

      protected final Map<String,ClusterManager> managers
      The context name <-> manager association for distributed contexts.
    • managerTemplate

      protected ClusterManager managerTemplate
    • clusterListeners

      protected final List<ClusterListener> clusterListeners
      Listeners of messages
    • hasMembers

      protected boolean hasMembers
      has 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

      public void setClusterName(String clusterName)
      Set the name of the cluster to join, if no cluster with this name is present create one.
      Specified by:
      setClusterName in interface Cluster
      Parameters:
      clusterName - The clustername to join
    • getClusterName

      public String getClusterName()
      Return the name of the cluster that this Server is currently configured to operate within.
      Specified by:
      getClusterName in interface Cluster
      Returns:
      The name of the cluster associated with this server
    • setContainer

      public void setContainer(Container container)
      Set the Container associated with our Cluster
      Specified by:
      setContainer in interface Contained
      Parameters:
      container - The Container to use
    • getContainer

      public Container getContainer()
      Get the Container associated with our Cluster
      Specified by:
      getContainer in interface Contained
      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

      public void addValve(Valve valve)
      Add cluster valve Cluster Valves are only add to container when cluster is started!
      Specified by:
      addValve in interface CatalinaCluster
      Parameters:
      valve - The new cluster Valve.
    • getValves

      public Valve[] getValves()
      get all cluster valves
      Specified by:
      getValves in interface CatalinaCluster
      Returns:
      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)
      Add cluster message listener and register cluster to this listener.
      Specified by:
      addClusterListener in interface CatalinaCluster
      Parameters:
      listener - The new listener
      See Also:
    • removeClusterListener

      public void removeClusterListener(ClusterListener listener)
      Remove message listener and deregister Cluster from listener.
      Specified by:
      removeClusterListener in interface CatalinaCluster
      Parameters:
      listener - The listener to remove
      See Also:
    • getClusterDeployer

      public ClusterDeployer getClusterDeployer()
      Specified by:
      getClusterDeployer in interface CatalinaCluster
      Returns:
      the current Deployer
    • setClusterDeployer

      public void setClusterDeployer(ClusterDeployer clusterDeployer)
      set a new Deployer, must be set before cluster started!
      Specified by:
      setClusterDeployer in interface CatalinaCluster
      Parameters:
      clusterDeployer - The associated deployer
    • setChannel

      public void setChannel(Channel channel)
      Specified by:
      setChannel in interface CatalinaCluster
    • setManagerTemplate

      public void setManagerTemplate(ClusterManager managerTemplate)
    • setChannelSendOptions

      public void setChannelSendOptions(int channelSendOptions)
    • setChannelSendOptions

      public void setChannelSendOptions(String channelSendOptions)
    • hasMembers

      public boolean hasMembers()
      Specified by:
      hasMembers in interface CatalinaCluster
      Returns:
      true if the cluster has members.
    • getMembers

      public Member[] getMembers()
      Get all current cluster members
      Specified by:
      getMembers in interface CatalinaCluster
      Returns:
      all members or empty array
    • getLocalMember

      public Member getLocalMember()
      Return the member that represents this node.
      Specified by:
      getLocalMember in interface CatalinaCluster
      Returns:
      Member
    • getManagers

      public Map<String,ClusterManager> getManagers()
      Specified by:
      getManagers in interface CatalinaCluster
      Returns:
      Returns the managers.
    • getChannel

      public Channel getChannel()
      Specified by:
      getChannel in interface CatalinaCluster
    • getManagerTemplate

      public ClusterManager getManagerTemplate()
    • getChannelSendOptions

      public int getChannelSendOptions()
    • getChannelSendOptionsName

      public 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(String name)
      Create new Manager without add to cluster (comes with start the manager)
      Specified by:
      createManager in interface Cluster
      Parameters:
      name - Context Name of this manager
      Returns:
      The newly created Manager instance
      See Also:
    • registerManager

      public void registerManager(Manager manager)
      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 interface Cluster
      Parameters:
      manager - Manager
    • removeManager

      public void removeManager(Manager manager)
      Remove an application from cluster replication bus.
      Specified by:
      removeManager in interface Cluster
      Parameters:
      manager - The manager
      See Also:
    • getManagerName

      public String getManagerName(String name, Manager manager)
      Description copied from interface: CatalinaCluster
      Get a new cluster name for a manager.
      Specified by:
      getManagerName in interface CatalinaCluster
      Parameters:
      name - Override name (optional)
      manager - The manager
      Returns:
      the manager name in the cluster
    • getManager

      public Manager getManager(String name)
      Description copied from interface: CatalinaCluster
      Get Manager
      Specified by:
      getManager in interface CatalinaCluster
      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:
      backgroundProcess in interface Cluster
      See Also:
    • initInternal

      protected void initInternal() throws LifecycleException
      Description copied from class: LifecycleMBeanBase
      Sub-classes wishing to perform additional initialization should override this method, ensuring that super.initInternal() is the first call in the overriding method.
      Overrides:
      initInternal in class LifecycleMBeanBase
      Throws:
      LifecycleException - If the initialisation fails
    • startInternal

      protected void startInternal() throws LifecycleException
      Start Cluster and implement the requirements of LifecycleBase.startInternal().
      Specified by:
      startInternal in class LifecycleBase
      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 LifecycleException
      Stop Cluster and implement the requirements of LifecycleBase.stopInternal().
      Specified by:
      stopInternal in class LifecycleBase
      Throws:
      LifecycleException - if this component detects a fatal error that prevents this component from being used
    • destroyInternal

      protected void destroyInternal() throws LifecycleException
      Description copied from class: LifecycleMBeanBase
      Sub-classes wishing to perform additional clean-up should override this method, ensuring that super.destroyInternal() is the last call in the overriding method.
      Overrides:
      destroyInternal in class LifecycleMBeanBase
      Throws:
      LifecycleException - If the destruction fails
    • toString

      public String toString()
      Return a String rendering of this object.
      Overrides:
      toString in class Object
    • send

      public void send(ClusterMessage msg)
      send message to all cluster members
      Specified by:
      send in interface CatalinaCluster
      Parameters:
      msg - message to transfer
      See Also:
    • send

      public void send(ClusterMessage msg, Member dest)
      send a cluster message to one member
      Specified by:
      send in interface CatalinaCluster
      Parameters:
      msg - message to transfer
      dest - Receiver member
      See Also:
    • send

      public void send(ClusterMessage msg, Member dest, int sendOptions)
      Description copied from interface: CatalinaCluster
      Sends a message with the specified sendOptions to a specific member in the cluster.
      Specified by:
      send in interface CatalinaCluster
      Parameters:
      msg - ClusterMessage
      dest - Member
      sendOptions - sendOptions
    • memberAdded

      public void memberAdded(Member member)
      New cluster member is registered
      Specified by:
      memberAdded in interface MembershipListener
      Parameters:
      member - Member - the member that was added
      See Also:
    • memberDisappeared

      public void memberDisappeared(Member member)
      Cluster member is gone
      Specified by:
      memberDisappeared in interface MembershipListener
      Parameters:
      member - Member
      See Also:
    • accept

      public boolean accept(Serializable msg, Member sender)
      notify all listeners from receiving a new message is not ClusterMessage emit Failure Event to LifecycleListener
      Specified by:
      accept in interface ChannelListener
      Parameters:
      msg - received Message
      sender - Member
      Returns:
      boolean
    • messageReceived

      public void messageReceived(Serializable message, Member sender)
      Description copied from interface: ChannelListener
      Receive a message from the channel
      Specified by:
      messageReceived in interface ChannelListener
      Parameters:
      message - Serializable
      sender - - the source of the message
    • messageReceived

      public void messageReceived(ClusterMessage message)
    • getChannelStartOptions

      public int getChannelStartOptions()
    • setChannelStartOptions

      public void setChannelStartOptions(int channelStartOptions)
    • getDomainInternal

      protected String 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 class LifecycleMBeanBase
      Returns:
      The name of the domain to use to register MBeans.
    • getObjectNameKeyProperties

      protected String getObjectNameKeyProperties()
      Description copied from class: LifecycleMBeanBase
      Allow sub-classes to specify the key properties component of the ObjectName that will be used to register this component.
      Specified by:
      getObjectNameKeyProperties in class LifecycleMBeanBase
      Returns:
      The string representation of the key properties component of the desired ObjectName