Class AsyncRetrier


  • public final class AsyncRetrier
    extends java.lang.Object
    A helper for retrying asynchronous calls.

    It implements retries up to a specified limit with a constant delay between each retry.

    • Constructor Summary

      Constructors 
      Modifier Constructor Description
      private AsyncRetrier​(java.util.concurrent.ScheduledExecutorService executorService)  
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      static AsyncRetrier create​(java.util.concurrent.ScheduledExecutorService sleeper)  
      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)  
      <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)
      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, java.util.concurrent.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 Detail

      • executorService

        private final java.util.concurrent.ScheduledExecutorService executorService
    • Constructor Detail

      • AsyncRetrier

        private AsyncRetrier​(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)
        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,
                                    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)