Class RetryFactory

java.lang.Object
io.atlassian.fugue.retry.RetryFactory

public class RetryFactory extends Object
Provides factory methods for RetryFunction, RetryTask, and RetrySupplier. These classes can be used when a task is known to fail on occasion and no other workaround is known. This class is not instantiable.
  • Constructor Summary

    Constructors
    Modifier
    Constructor
    Description
    private
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static Runnable
    create(Runnable task, int tries)
    Decorates a runnable so that it retries a number of times before being allowed to fail.
    static Runnable
    create(Runnable task, int tries, ExceptionHandler handler)
    Decorates a runnable so that it retries a number of times before being allowed to fail.
    static Runnable
    create(Runnable task, int tries, ExceptionHandler handler, long backoff)
    Decorates a runnable so that it retries a number of times before being allowed to fail, backing off exponentially in time.
    static <A, B> Function<A,B>
    create(Function<A,B> function, int tries)
    Decorates a function so that it retries a number of times before being allowed to fail.
    static <A, B> Function<A,B>
    create(Function<A,B> function, int tries, ExceptionHandler handler)
    Decorates a function so that it retries a number of times before being allowed to fail.
    static <A, B> Function<A,B>
    create(Function<A,B> function, int tries, ExceptionHandler handler, long backoff)
    Decorates a function so that it retries a number of times before being allowed to fail.
    static <A> Supplier<A>
    create(Supplier<A> supplier, int tries)
    Decorates a supplier so that it retries a number of times before being allowed to fail.
    static <A> Supplier<A>
    create(Supplier<A> supplier, int tries, ExceptionHandler handler)
    Decorates a supplier so that it retries a number of times before being allowed to fail.
    static <A> Supplier<A>
    create(Supplier<A> supplier, int tries, ExceptionHandler handler, long backoff)
    Decorates a supplier so that it retries a number of times before being allowed to fail, backing-off in time exponentially.

    Methods inherited from class java.lang.Object

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

    • RetryFactory

      private RetryFactory()
  • Method Details

    • create

      public static Runnable create(Runnable task, int tries)
      Decorates a runnable so that it retries a number of times before being allowed to fail.
      Parameters:
      task - which will be wrapped for retrial. It should be idempotent on failure.
      tries - the number of times to re-attempt the call
      Returns:
      a runnable which can be used to call another runnable multiple times when that runnable may fail sporadically
    • create

      public static Runnable create(Runnable task, int tries, ExceptionHandler handler)
      Decorates a runnable so that it retries a number of times before being allowed to fail.
      Parameters:
      task - which will be wrapped for retrial. It should be idempotent on failure.
      tries - the number of times to re-attempt the call
      handler - passed any exceptions that are encountered
      Returns:
      a runnable which can be used to call another runnable multiple times when that runnable may fail sporadically
    • create

      public static Runnable create(Runnable task, int tries, ExceptionHandler handler, long backoff)
      Decorates a runnable so that it retries a number of times before being allowed to fail, backing off exponentially in time.
      Parameters:
      task - which will be wrapped for retrial. It should be idempotent on failure.
      tries - the number of times to re-attempt the call
      handler - which acts on exceptions thrown by the wrapped supplier
      backoff - time to wait in millis each time
      Returns:
      a runnable which can be used to call another runnable multiple times when that runnable may fail sporadically
    • create

      public static <A> Supplier<A> create(Supplier<A> supplier, int tries)
      Decorates a supplier so that it retries a number of times before being allowed to fail.
      Type Parameters:
      A - The type of the object returned by supplier
      Parameters:
      supplier - which will be wrapped for retrial. It should be idempotent on failure.
      tries - the number of times to re-attempt the call
      Returns:
      a supplier which can be used to call another supplier multiple times when that supplier may fail sporadically
    • create

      public static <A> Supplier<A> create(Supplier<A> supplier, int tries, ExceptionHandler handler)
      Decorates a supplier so that it retries a number of times before being allowed to fail.
      Type Parameters:
      A - The type of the object returned by supplier
      Parameters:
      supplier - which will be wrapped for retrial. It should be idempotent on failure.
      tries - the number of times to re-attempt the call
      handler - which acts on exceptions thrown by the wrapped supplier
      Returns:
      a supplier which can be used to call another supplier multiple times when that supplier may fail sporadically
    • create

      public static <A> Supplier<A> create(Supplier<A> supplier, int tries, ExceptionHandler handler, long backoff)
      Decorates a supplier so that it retries a number of times before being allowed to fail, backing-off in time exponentially.
      Type Parameters:
      A - The type of the object returned by supplier
      Parameters:
      supplier - which will be wrapped for retrial. It should be idempotent on failure.
      tries - the number of times to re-attempt the call
      handler - which acts on exceptions thrown by the wrapped supplier
      backoff - time to wait in millis each time
      Returns:
      a supplier which can be used to call another supplier multiple times when that supplier may fail sporadically
    • create

      public static <A, B> Function<A,B> create(Function<A,B> function, int tries)
      Decorates a function so that it retries a number of times before being allowed to fail.
      Type Parameters:
      A - the type of the parameter the function accepts
      B - the type of the result of the function's apply method
      Parameters:
      function - which will be wrapped for retrial. It should be idempotent on failure.
      tries - the number of times to re-attempt the call
      Returns:
      a function which can be used to invoke another function multiple times when that function may fail sporadically
    • create

      public static <A, B> Function<A,B> create(Function<A,B> function, int tries, ExceptionHandler handler)
      Decorates a function so that it retries a number of times before being allowed to fail.
      Type Parameters:
      A - the type of the parameter the function accepts
      B - the type of the result of the function's apply method
      Parameters:
      function - which will be wrapped for retrial. It should be idempotent on failure.
      tries - the number of times to re-attempt the call
      handler - which acts on exceptions thrown by the wrapped supplier
      Returns:
      a function which can be used to invoke another function multiple times when that function may fail sporadically
    • create

      public static <A, B> Function<A,B> create(Function<A,B> function, int tries, ExceptionHandler handler, long backoff)
      Decorates a function so that it retries a number of times before being allowed to fail.
      Type Parameters:
      A - the type of the parameter the function accepts
      B - the type of the result of the function's apply method
      Parameters:
      function - which will be wrapped for retrial. It should be idempotent on failure.
      tries - the number of times to re-attempt the call
      handler - which acts on exceptions thrown by the wrapped supplier
      backoff - time to wait in millis each time
      Returns:
      a function which can be used to invoke another function multiple times when that function may fail sporadically