Class ExponentialBackoffTimeoutStrategy

  • All Implemented Interfaces:
    TimeoutStrategy

    public class ExponentialBackoffTimeoutStrategy
    extends Object
    implements TimeoutStrategy
    Strategy which incorporates retriable network operation, handling of totalTimeout logic. It increases startTimeout based on exponential backoff algorithm. If failure detection is enabled it relies on totalTimeout otherwise implements exponential backoff totalTimeout logic based on startTimeout, maxTimeout and retryCnt.
    • Constructor Detail

      • ExponentialBackoffTimeoutStrategy

        public ExponentialBackoffTimeoutStrategy​(long totalTimeout,
                                                 long startTimeout,
                                                 long maxTimeout)
        Parameters:
        totalTimeout - Total startTimeout.
        startTimeout - Initial connection timeout.
        maxTimeout - Max connection Timeout.
    • Method Detail

      • totalBackoffTimeout

        public static long totalBackoffTimeout​(long initTimeout,
                                               long maxTimeout,
                                               long reconCnt)
        Compute expected max backoff timeout based on initTimeout, maxTimeout and reconCnt and backoff coefficient.
        Parameters:
        initTimeout - Initial timeout.
        maxTimeout - Max Timeout per retry.
        reconCnt - Reconnection count.
        Returns:
        Calculated total backoff timeout.
      • backoffTimeout

        public static long backoffTimeout​(long timeout,
                                          long maxTimeout)
        Parameters:
        timeout - Timeout.
        maxTimeout - Maximum startTimeout for backoff function.
        Returns:
        Next exponential backoff timeout.
      • checkTimeout

        public boolean checkTimeout​(long timeInFut)
        Check if total timeout will be reached in now() + timeInFut. If timeInFut is 0, will check that timeout already reached.
        Specified by:
        checkTimeout in interface TimeoutStrategy
        Parameters:
        timeInFut - Some millis in future.
        Returns:
        True if total timeout will be reached.