Package com.spotify.futures
Class AsyncRetrier
java.lang.Object
com.spotify.futures.AsyncRetrier
A helper for retrying asynchronous calls.
It implements retries up to a specified limit with a constant delay between each retry.
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic AsyncRetriercreate(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, TimeUnit timeUnit, com.google.common.base.Predicate<T> retryCondition, 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, 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, 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, TimeUnit timeUnit, com.google.common.base.Predicate<T> retryCondition)
-
Field Details
-
DEFAULT_DELAY_MILLIS
public static final long DEFAULT_DELAY_MILLIS- See Also:
-
executorService
-
-
Constructor Details
-
AsyncRetrier
-
-
Method Details
-
create
-
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, 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, 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, TimeUnit timeUnit, com.google.common.base.Predicate<T> retryCondition) -
handleFailure
-