## org.apache.hadoop.io.retry
Class RetryPolicies

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

    public class RetryPolicies

extends Object

A collection of useful implementations of `RetryPolicy`.

Nested Class Summary
`static class` `RetryPolicies.MultipleLinearRandomRetry` Given pairs of number of retries and sleep time (n0, t0), (n1, t1), ..., the first n0 retries sleep t0 milliseconds on average, the following n1 retries sleep t1 milliseconds on average, and so on.

Field Summary
`static RetryPolicy` `RETRY_FOREVER` Keep trying forever.
`static RetryPolicy` `TRY_ONCE_DONT_FAIL` Try once, and fail silently for `void` methods, or by re-throwing the exception for non-`void` methods.
`static RetryPolicy` `TRY_ONCE_THEN_FAIL` Try once, and fail by re-throwing the exception.

Constructor Summary
`RetryPolicies()`

Method Summary
`static 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.
`static RetryPolicy` `retryByException(RetryPolicy defaultPolicy, Map<Class<? extends Exception>,RetryPolicy> exceptionToPolicyMap)` Set a default policy with some explicit handlers for specific exceptions.
`static 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.
`static 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.
`static 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.
`static 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.

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Field Detail

### 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.

### TRY_ONCE_DONT_FAIL

    public static final RetryPolicy TRY_ONCE_DONT_FAIL

  Try once, and fail silently for `void` methods, or by re-throwing the exception for non-`void` methods.

### RETRY_FOREVER

    public static final RetryPolicy RETRY_FOREVER

  Keep trying forever.

Constructor Detail

### RetryPolicies

    public RetryPolicies()

Method Detail

### 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.

### 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.

### 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.

### 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)

### 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.

### 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.

Copyright © 2009 The Apache Software Foundation