Class RetryPolicies

java.lang.Object
org.apache.hadoop.io.retry.RetryPolicies

public class RetryPolicies extends Object

A collection of useful implementations of RetryPolicy.

  • Field Details

    • LOG

      public static final org.slf4j.Logger LOG
    • TRY_ONCE_THEN_FAIL

      public static final RetryPolicy TRY_ONCE_THEN_FAIL

      Try once, and fail by re-throwing the exception. This corresponds to having no retry mechanism in place.

    • RETRY_FOREVER

      public static final RetryPolicy RETRY_FOREVER

      Keep trying forever.

  • Constructor Details

    • RetryPolicies

      public RetryPolicies()
  • Method Details

    • retryForeverWithFixedSleep

      public static final RetryPolicy retryForeverWithFixedSleep(long sleepTime, TimeUnit timeUnit)

      Keep trying forever with a fixed time between attempts.

      Parameters:
      sleepTime - sleepTime.
      timeUnit - timeUnit.
      Returns:
      RetryPolicy.
    • retryUpToMaximumCountWithFixedSleep

      public static final RetryPolicy retryUpToMaximumCountWithFixedSleep(int maxRetries, long sleepTime, TimeUnit timeUnit)

      Keep trying a limited number of times, waiting a fixed time between attempts, and then fail by re-throwing the exception.

      Parameters:
      maxRetries - maxRetries.
      sleepTime - sleepTime.
      timeUnit - timeUnit.
      Returns:
      RetryPolicy.
    • retryUpToMaximumTimeWithFixedSleep

      public static final RetryPolicy retryUpToMaximumTimeWithFixedSleep(long maxTime, long sleepTime, TimeUnit timeUnit)

      Keep trying for a maximum time, waiting a fixed time between attempts, and then fail by re-throwing the exception.

      Parameters:
      timeUnit - timeUnit.
      sleepTime - sleepTime.
      maxTime - maxTime.
      Returns:
      RetryPolicy.
    • retryUpToMaximumCountWithProportionalSleep

      public static final RetryPolicy retryUpToMaximumCountWithProportionalSleep(int maxRetries, long sleepTime, TimeUnit timeUnit)

      Keep trying a limited number of times, waiting a growing amount of time between attempts, and then fail by re-throwing the exception. The time between attempts is sleepTime mutliplied by the number of tries so far.

      Parameters:
      sleepTime - sleepTime.
      maxRetries - maxRetries.
      timeUnit - timeUnit.
      Returns:
      RetryPolicy.
    • exponentialBackoffRetry

      public static final RetryPolicy exponentialBackoffRetry(int maxRetries, long sleepTime, TimeUnit timeUnit)

      Keep trying a limited number of times, waiting a growing amount of time between attempts, and then fail by re-throwing the exception. The time between attempts is sleepTime mutliplied by a random number in the range of [0, 2 to the number of retries)

      Parameters:
      timeUnit - timeUnit.
      maxRetries - maxRetries.
      sleepTime - sleepTime.
      Returns:
      RetryPolicy.
    • retryByException

      public static final RetryPolicy retryByException(RetryPolicy defaultPolicy, Map<Class<? extends Exception>,RetryPolicy> exceptionToPolicyMap)

      Set a default policy with some explicit handlers for specific exceptions.

      Parameters:
      exceptionToPolicyMap - exceptionToPolicyMap.
      defaultPolicy - defaultPolicy.
      Returns:
      RetryPolicy.
    • retryByRemoteException

      public static final RetryPolicy retryByRemoteException(RetryPolicy defaultPolicy, Map<Class<? extends Exception>,RetryPolicy> exceptionToPolicyMap)

      A retry policy for RemoteException Set a default policy with some explicit handlers for specific exceptions.

      Parameters:
      defaultPolicy - defaultPolicy.
      exceptionToPolicyMap - exceptionToPolicyMap.
      Returns:
      RetryPolicy.
    • retryOtherThanRemoteAndSaslException

      public static final RetryPolicy retryOtherThanRemoteAndSaslException(RetryPolicy defaultPolicy, Map<Class<? extends Exception>,RetryPolicy> exceptionToPolicyMap)

      A retry policy where RemoteException and SaslException are not retried, other individual exception types can have RetryPolicy overrides, and any other exception type without an override is not retried.

      Parameters:
      defaultPolicy - defaultPolicy.
      exceptionToPolicyMap - exceptionToPolicyMap.
      Returns:
      RetryPolicy.
    • failoverOnNetworkException

      public static final RetryPolicy failoverOnNetworkException(int maxFailovers)
    • failoverOnNetworkException

      public static final RetryPolicy failoverOnNetworkException(RetryPolicy fallbackPolicy, int maxFailovers)
    • failoverOnNetworkException

      public static final RetryPolicy failoverOnNetworkException(RetryPolicy fallbackPolicy, int maxFailovers, long delayMillis, long maxDelayBase)
    • failoverOnNetworkException

      public static final RetryPolicy failoverOnNetworkException(RetryPolicy fallbackPolicy, int maxFailovers, int maxRetries, long delayMillis, long maxDelayBase)