Class TcpFailureDetector

java.lang.Object
org.apache.catalina.tribes.group.ChannelInterceptorBase
org.apache.catalina.tribes.group.interceptors.TcpFailureDetector
All Implemented Interfaces:
ChannelInterceptor, TcpFailureDetectorMBean, Heartbeat, MembershipListener

public class TcpFailureDetector extends ChannelInterceptorBase implements TcpFailureDetectorMBean
The TcpFailureDetector is a useful interceptor that adds reliability to the membership layer.

If the network is busy, or the system is busy so that the membership receiver thread is not getting enough time to update its table, members can be "timed out" This failure detector will intercept the memberDisappeared message(unless its a true shutdown message) and connect to the member using TCP.

The TcpFailureDetector works in two ways:

  1. It intercepts memberDisappeared events
  2. It catches send errors
  • Field Details

    • sm

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

      protected static final byte[] TCP_FAIL_DETECT
      Test payload sent during member liveness checks.
    • connectTimeout

      protected long connectTimeout
      Connection timeout in milliseconds for member checks.
    • performSendTest

      protected boolean performSendTest
      Whether to perform TCP send tests during member checks.
    • performReadTest

      protected boolean performReadTest
      Whether to perform TCP read tests during member checks.
    • readTestTimeout

      protected long readTestTimeout
      Read test timeout in milliseconds.
    • membership

      protected Membership membership
      The membership tracker.
    • removeSuspects

      protected final HashMap<Member,Long> removeSuspects
      Map of members suspected of being dead and their detection time.
    • addSuspects

      protected final HashMap<Member,Long> addSuspects
      Map of members suspected of rejoining and their detection time.
    • removeSuspectsTimeout

      protected int removeSuspectsTimeout
      Timeout in seconds for removing suspected dead members.
  • Constructor Details

    • TcpFailureDetector

      public TcpFailureDetector()
      Constructs a new TcpFailureDetector.
  • Method Details

    • sendMessage

      public void sendMessage(Member[] destination, ChannelMessage msg, InterceptorPayload payload) throws ChannelException
      Description copied from interface: ChannelInterceptor
      The sendMessage method is called when a message is being sent to one more destinations. The interceptor can modify any of the parameters and then pass on the message down the stack by invoking getNext().sendMessage(destination,msg,payload).

      Alternatively the interceptor can stop the message from being sent by not invoking getNext().sendMessage(destination,msg,payload).

      If the message is to be sent asynchronous the application can be notified of completion and errors by passing in an error handler attached to a payload object.

      The ChannelMessage.getAddress contains Channel.getLocalMember, and can be overwritten to simulate a message sent from another node.

      Specified by:
      sendMessage in interface ChannelInterceptor
      Overrides:
      sendMessage in class ChannelInterceptorBase
      Parameters:
      destination - Member[] - the destination for this message
      msg - ChannelMessage - the message to be sent
      payload - InterceptorPayload - the payload, carrying an error handler and future useful data, can be null
      Throws:
      ChannelException - if a serialization error happens.
      See Also:
    • messageReceived

      public void messageReceived(ChannelMessage msg)
      Description copied from interface: ChannelInterceptor
      The messageReceived is invoked when a message is received. ChannelMessage.getAddress() is the sender, or the reply-to address if it has been overwritten.
      Specified by:
      messageReceived in interface ChannelInterceptor
      Overrides:
      messageReceived in class ChannelInterceptorBase
      Parameters:
      msg - ChannelMessage
    • memberAdded

      public void memberAdded(Member member)
      Description copied from interface: MembershipListener
      A member was added to the group
      Specified by:
      memberAdded in interface MembershipListener
      Overrides:
      memberAdded in class ChannelInterceptorBase
      Parameters:
      member - Member - the member that was added
    • forgetMember

      public void forgetMember(Member member)
      Forgets a member that is represented by another member from now on, for example a statically configured member whose node has been discovered dynamically. Unlike memberDisappeared(Member), the member is not kept as a suspect, so it is not added again by the member checks. If the member was a member of this detector, the interceptors above are told that it disappeared.
      Parameters:
      member - the member to forget
    • memberDisappeared

      public void memberDisappeared(Member member)
      Description copied from interface: MembershipListener
      A member was removed from the group
      If the member left voluntarily, the Member.getCommand will contain the Member.SHUTDOWN_PAYLOAD data
      Specified by:
      memberDisappeared in interface MembershipListener
      Overrides:
      memberDisappeared in class ChannelInterceptorBase
      Parameters:
      member - Member
      See Also:
    • hasMembers

      public boolean hasMembers()
      Description copied from interface: ChannelInterceptor
      Intercepts the Channel.hasMembers() method
      Specified by:
      hasMembers in interface ChannelInterceptor
      Overrides:
      hasMembers in class ChannelInterceptorBase
      Returns:
      boolean - if the channel has members in its membership group
      See Also:
    • getMembers

      public Member[] getMembers()
      Description copied from interface: ChannelInterceptor
      Intercepts the Channel.getMembers() method
      Specified by:
      getMembers in interface ChannelInterceptor
      Overrides:
      getMembers in class ChannelInterceptorBase
      Returns:
      the members
      See Also:
    • getMember

      public Member getMember(Member mbr)
      Description copied from interface: ChannelInterceptor
      Intercepts the Channel.getMember(Member) method
      Specified by:
      getMember in interface ChannelInterceptor
      Overrides:
      getMember in class ChannelInterceptorBase
      Parameters:
      mbr - Member
      Returns:
      Member - the actual member information, including stay alive
      See Also:
    • getLocalMember

      public Member getLocalMember(boolean incAlive)
      Description copied from interface: ChannelInterceptor
      Intercepts the Channel.getLocalMember(boolean) method
      Specified by:
      getLocalMember in interface ChannelInterceptor
      Overrides:
      getLocalMember in class ChannelInterceptorBase
      Parameters:
      incAlive - boolean
      Returns:
      the member that represents this node
      See Also:
    • heartbeat

      public void heartbeat()
      Description copied from interface: ChannelInterceptor
      The heartbeat() method gets invoked periodically to allow interceptors to clean up resources, time out object and perform actions that are unrelated to sending/receiving data.
      Specified by:
      heartbeat in interface ChannelInterceptor
      Specified by:
      heartbeat in interface Heartbeat
      Overrides:
      heartbeat in class ChannelInterceptorBase
    • checkMembers

      public void checkMembers(boolean checkAll)
      Description copied from interface: TcpFailureDetectorMBean
      Checks the status of cluster members.
      Specified by:
      checkMembers in interface TcpFailureDetectorMBean
      Parameters:
      checkAll - true to check all members, false to check only suspects
    • performForcedCheck

      protected void performForcedCheck()
      Performs a forced check of all cluster members. The TCP liveness checks run outside the membership monitor and the results are only applied after re-acquiring the monitor and re-checking that the current state still matches the decision.
    • performBasicCheck

      protected void performBasicCheck()
      Performs a basic check of suspected members. The TCP liveness checks run outside the membership monitor and the results are only applied after re-acquiring the monitor and re-checking that the current state still matches the decision.
    • expireRemoveSuspect

      protected void expireRemoveSuspect(Member m)
      Removes the member from the remove suspects map if it has been suspect for longer than the configured timeout. Must be called while holding the membership monitor.
      Parameters:
      m - the member to expire
    • setupMembership

      protected void setupMembership()
      Initializes the membership tracker if not already set up.
    • memberAlive

      protected boolean memberAlive(Member mbr)
      Checks whether the given member is alive using the default test parameters.
      Parameters:
      mbr - the member to check
      Returns:
      true if the member is alive
    • memberAlive

      protected boolean memberAlive(Member mbr, byte[] msgData, boolean sendTest, boolean readTest, long readTimeout, long conTimeout, int optionFlag)
      Checks whether the given member is alive using the specified test parameters.
      Parameters:
      mbr - the member to check
      msgData - the test message data
      sendTest - whether to perform a send test
      readTest - whether to perform a read test
      readTimeout - the read timeout in milliseconds
      conTimeout - the connection timeout in milliseconds
      optionFlag - the socket option flag
      Returns:
      true if the member is alive
    • getReadTestTimeout

      public long getReadTestTimeout()
      Description copied from interface: TcpFailureDetectorMBean
      Returns the read test timeout in milliseconds.
      Specified by:
      getReadTestTimeout in interface TcpFailureDetectorMBean
      Returns:
      the read test timeout
    • getPerformSendTest

      public boolean getPerformSendTest()
      Description copied from interface: TcpFailureDetectorMBean
      Returns whether send tests are performed.
      Specified by:
      getPerformSendTest in interface TcpFailureDetectorMBean
      Returns:
      true if send tests are enabled
    • getPerformReadTest

      public boolean getPerformReadTest()
      Description copied from interface: TcpFailureDetectorMBean
      Returns whether read tests are performed.
      Specified by:
      getPerformReadTest in interface TcpFailureDetectorMBean
      Returns:
      true if read tests are enabled
    • getConnectTimeout

      public long getConnectTimeout()
      Description copied from interface: TcpFailureDetectorMBean
      Returns the connection timeout in milliseconds.
      Specified by:
      getConnectTimeout in interface TcpFailureDetectorMBean
      Returns:
      the connection timeout
    • getRemoveSuspectsTimeout

      public int getRemoveSuspectsTimeout()
      Description copied from interface: TcpFailureDetectorMBean
      Returns the timeout for removing suspects.
      Specified by:
      getRemoveSuspectsTimeout in interface TcpFailureDetectorMBean
      Returns:
      the remove suspects timeout
    • setPerformReadTest

      public void setPerformReadTest(boolean performReadTest)
      Description copied from interface: TcpFailureDetectorMBean
      Sets whether read tests should be performed.
      Specified by:
      setPerformReadTest in interface TcpFailureDetectorMBean
      Parameters:
      performReadTest - true to enable read tests
    • setPerformSendTest

      public void setPerformSendTest(boolean performSendTest)
      Description copied from interface: TcpFailureDetectorMBean
      Sets whether send tests should be performed.
      Specified by:
      setPerformSendTest in interface TcpFailureDetectorMBean
      Parameters:
      performSendTest - true to enable send tests
    • setReadTestTimeout

      public void setReadTestTimeout(long readTestTimeout)
      Description copied from interface: TcpFailureDetectorMBean
      Sets the read test timeout in milliseconds.
      Specified by:
      setReadTestTimeout in interface TcpFailureDetectorMBean
      Parameters:
      readTestTimeout - the timeout value
    • setConnectTimeout

      public void setConnectTimeout(long connectTimeout)
      Description copied from interface: TcpFailureDetectorMBean
      Sets the connection timeout in milliseconds.
      Specified by:
      setConnectTimeout in interface TcpFailureDetectorMBean
      Parameters:
      connectTimeout - the timeout value
    • setRemoveSuspectsTimeout

      public void setRemoveSuspectsTimeout(int removeSuspectsTimeout)
      Description copied from interface: TcpFailureDetectorMBean
      Sets the timeout for removing suspects.
      Specified by:
      setRemoveSuspectsTimeout in interface TcpFailureDetectorMBean
      Parameters:
      removeSuspectsTimeout - the timeout value