Class BackoffPolicy

  • All Implemented Interfaces:
    java.lang.Iterable<TimeValue>

    public abstract class BackoffPolicy
    extends java.lang.Object
    implements java.lang.Iterable<TimeValue>
    Provides a backoff policy for bulk requests. Whenever a bulk request is rejected due to resource constraints (i.e. the client's internal thread pool is full), the backoff policy decides how long the bulk processor will wait before the operation is retried internally. Notes for implementing custom subclasses: The underlying mathematical principle of BackoffPolicy are progressions which can be either finite or infinite although the latter should not be used for retrying. A progression can be mapped to a java.util.Iterator with the following semantics:
    • #hasNext() determines whether the progression has more elements. Return true for infinite progressions
    • #next() determines the next element in the progression, i.e. the next wait time period
    Note that backoff policies are exposed as Iterables in order to be consumed multiple times.
    • Constructor Summary

      Constructors 
      Constructor Description
      BackoffPolicy()  
    • Method Summary

      Modifier and Type Method Description
      static BackoffPolicy constantBackoff​(TimeValue delay, int maxNumberOfRetries)
      Creates an new constant backoff policy with the provided configuration.
      static BackoffPolicy exponentialBackoff()
      Creates an new exponential backoff policy with a default configuration of 50 ms initial wait period and 8 retries taking roughly 5.1 seconds in total.
      static BackoffPolicy exponentialBackoff​(TimeValue initialDelay, int maxNumberOfRetries)
      Creates an new exponential backoff policy with the provided configuration.
      static BackoffPolicy noBackoff()
      Creates a backoff policy that will not allow any backoff, i.e.
      static BackoffPolicy wrap​(BackoffPolicy delegate, java.lang.Runnable onBackoff)
      Wraps the backoff policy in one that calls a method every time a new backoff is taken from the policy.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
      • Methods inherited from interface java.lang.Iterable

        forEach, iterator, spliterator
    • Constructor Detail

      • BackoffPolicy

        public BackoffPolicy()
    • Method Detail

      • noBackoff

        public static BackoffPolicy noBackoff()
        Creates a backoff policy that will not allow any backoff, i.e. an operation will fail after the first attempt.
        Returns:
        A backoff policy without any backoff period. The returned instance is thread safe.
      • constantBackoff

        public static BackoffPolicy constantBackoff​(TimeValue delay,
                                                    int maxNumberOfRetries)
        Creates an new constant backoff policy with the provided configuration.
        Parameters:
        delay - The delay defines how long to wait between retry attempts. Must not be null. Must be <= Integer.MAX_VALUE ms.
        maxNumberOfRetries - The maximum number of retries. Must be a non-negative number.
        Returns:
        A backoff policy with a constant wait time between retries. The returned instance is thread safe but each iterator created from it should only be used by a single thread.
      • exponentialBackoff

        public static BackoffPolicy exponentialBackoff()
        Creates an new exponential backoff policy with a default configuration of 50 ms initial wait period and 8 retries taking roughly 5.1 seconds in total.
        Returns:
        A backoff policy with an exponential increase in wait time for retries. The returned instance is thread safe but each iterator created from it should only be used by a single thread.
      • exponentialBackoff

        public static BackoffPolicy exponentialBackoff​(TimeValue initialDelay,
                                                       int maxNumberOfRetries)
        Creates an new exponential backoff policy with the provided configuration.
        Parameters:
        initialDelay - The initial delay defines how long to wait for the first retry attempt. Must not be null. Must be <= Integer.MAX_VALUE ms.
        maxNumberOfRetries - The maximum number of retries. Must be a non-negative number.
        Returns:
        A backoff policy with an exponential increase in wait time for retries. The returned instance is thread safe but each iterator created from it should only be used by a single thread.
      • wrap

        public static BackoffPolicy wrap​(BackoffPolicy delegate,
                                         java.lang.Runnable onBackoff)
        Wraps the backoff policy in one that calls a method every time a new backoff is taken from the policy.