Class RetrySupplier<T>

java.lang.Object
io.atlassian.fugue.retry.RetrySupplier<T>
Type Parameters:
T - The type of the result the Supplier yields upon application
All Implemented Interfaces:
Supplier<T>

public class RetrySupplier<T> extends Object implements Supplier<T>
A Supplier which wraps the apply method of another Supplier and attempts it up to a fixed number of times. This class can be used when a task is known to be prone to occasional failure and other workarounds are not known.
See Also:
  • Field Details

    • supplier

      private final Supplier<T> supplier
    • tries

      private final int tries
    • handler

      private final ExceptionHandler handler
    • beforeRetry

      private final Runnable beforeRetry
  • Constructor Details

    • RetrySupplier

      public RetrySupplier(Supplier<T> supplier, int tries)
      An instance that does nothing before retrying and ignores exceptions that occur.
      Parameters:
      supplier - which fetches the result, must not be null
      tries - the number of times to attempt to get a result, must be positive
    • RetrySupplier

      public RetrySupplier(Supplier<T> supplier, int tries, ExceptionHandler handler)
      An instance that does nothing before retrying.
      Parameters:
      supplier - which fetches the result, must not be null
      tries - the number of times to attempt to get a result, must be positive
      handler - reacts to exceptions thrown by the supplier, must not be null
    • RetrySupplier

      public RetrySupplier(Supplier<T> supplier, int tries, ExceptionHandler handler, Runnable beforeRetry)

      Constructor for RetrySupplier.

      Parameters:
      supplier - which fetches the result, must not be null
      tries - the number of times to attempt to get a result, must be positive
      handler - reacts to exceptions thrown by the supplier, must not be null
      beforeRetry - a task which will run at the end of any
  • Method Details

    • get

      public T get()
      Attempt to get a result tries number of times. Any exceptions thrown will be ignored until the number of attempts is reached. If the number of attempts is reached without a successful result, the most recent exception to be thrown will be rethrown.
      Specified by:
      get in interface Supplier<T>