Class AsyncRetrier

java.lang.Object
com.spotify.futures.AsyncRetrier

public final class AsyncRetrier extends Object
A 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 final long
     
     
  • Constructor Summary

    Constructors
    Modifier
    Constructor
    Description
    private
     
  • Method Summary

    Modifier and Type
    Method
    Description
     
    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, 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)
    Retry code up to retries times.
    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)
     

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

  • Constructor Details

  • Method Details

    • create

      public static AsyncRetrier create(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, 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)
      Retry code up to retries times.
    • 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

      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, TimeUnit timeUnit, com.google.common.base.Predicate<T> retryCondition, Throwable t)