- java.lang.Object
-
- com.spotify.futures.AsyncRetrier
-
public final class AsyncRetrier extends java.lang.ObjectA helper for retrying asynchronous calls.It implements retries up to a specified limit with a constant delay between each retry.
-
-
Field Summary
Fields Modifier and Type Field Description static longDEFAULT_DELAY_MILLISprivate java.util.concurrent.ScheduledExecutorServiceexecutorService
-
Constructor Summary
Constructors Modifier Constructor Description privateAsyncRetrier(java.util.concurrent.ScheduledExecutorService executorService)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static AsyncRetriercreate(java.util.concurrent.ScheduledExecutorService sleeper)private <T> voidhandleFailure(com.google.common.util.concurrent.SettableFuture<T> future, com.google.common.base.Supplier<com.google.common.util.concurrent.ListenableFuture<T>> code, int retries, long delay, java.util.concurrent.TimeUnit timeUnit, com.google.common.base.Predicate<T> retryCondition, java.lang.Throwable t)<T> com.google.common.util.concurrent.ListenableFuture<T>retry(com.google.common.base.Supplier<com.google.common.util.concurrent.ListenableFuture<T>> code, int retries)<T> com.google.common.util.concurrent.ListenableFuture<T>retry(com.google.common.base.Supplier<com.google.common.util.concurrent.ListenableFuture<T>> code, int retries, long delayMillis)<T> com.google.common.util.concurrent.ListenableFuture<T>retry(com.google.common.base.Supplier<com.google.common.util.concurrent.ListenableFuture<T>> code, int retries, long delay, java.util.concurrent.TimeUnit timeUnit)<T> com.google.common.util.concurrent.ListenableFuture<T>retry(com.google.common.base.Supplier<com.google.common.util.concurrent.ListenableFuture<T>> code, int retries, long delay, java.util.concurrent.TimeUnit timeUnit, com.google.common.base.Predicate<T> retryCondition)Retrycodeup toretriestimes.private <T> voidstartRetry(com.google.common.util.concurrent.SettableFuture<T> future, com.google.common.base.Supplier<com.google.common.util.concurrent.ListenableFuture<T>> code, int retries, long delay, java.util.concurrent.TimeUnit timeUnit, com.google.common.base.Predicate<T> retryCondition)
-
-
-
Field Detail
-
DEFAULT_DELAY_MILLIS
public static final long DEFAULT_DELAY_MILLIS
- See Also:
- Constant Field Values
-
executorService
private final java.util.concurrent.ScheduledExecutorService executorService
-
-
Method Detail
-
create
public static AsyncRetrier create(java.util.concurrent.ScheduledExecutorService sleeper)
-
retry
public <T> com.google.common.util.concurrent.ListenableFuture<T> retry(com.google.common.base.Supplier<com.google.common.util.concurrent.ListenableFuture<T>> code, int retries)
-
retry
public <T> com.google.common.util.concurrent.ListenableFuture<T> retry(com.google.common.base.Supplier<com.google.common.util.concurrent.ListenableFuture<T>> code, int retries, long delayMillis)
-
retry
public <T> com.google.common.util.concurrent.ListenableFuture<T> retry(com.google.common.base.Supplier<com.google.common.util.concurrent.ListenableFuture<T>> code, int retries, long delay, java.util.concurrent.TimeUnit timeUnit)
-
retry
public <T> com.google.common.util.concurrent.ListenableFuture<T> retry(com.google.common.base.Supplier<com.google.common.util.concurrent.ListenableFuture<T>> code, int retries, long delay, java.util.concurrent.TimeUnit timeUnit, com.google.common.base.Predicate<T> retryCondition)Retrycodeup toretriestimes.
-
startRetry
private <T> void startRetry(com.google.common.util.concurrent.SettableFuture<T> future, com.google.common.base.Supplier<com.google.common.util.concurrent.ListenableFuture<T>> code, int retries, long delay, java.util.concurrent.TimeUnit timeUnit, com.google.common.base.Predicate<T> retryCondition)
-
handleFailure
private <T> void handleFailure(com.google.common.util.concurrent.SettableFuture<T> future, com.google.common.base.Supplier<com.google.common.util.concurrent.ListenableFuture<T>> code, int retries, long delay, java.util.concurrent.TimeUnit timeUnit, com.google.common.base.Predicate<T> retryCondition, java.lang.Throwable t)
-
-