Class RetryFunction<F,T>

java.lang.Object
io.atlassian.fugue.retry.RetryFunction<F,T>
Type Parameters:
F - The type of the parameter the Function accepts
T - The type of the result the Function yields upon application
All Implemented Interfaces:
Function<F,T>

public class RetryFunction<F,T> extends Object implements Function<F,T>
A Function which wraps the apply method of another Function 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

    • function

      private final Function<F,T> function
    • tries

      private final int tries
    • handler

      private final ExceptionHandler handler
    • beforeRetry

      private final Runnable beforeRetry
  • Constructor Details

    • RetryFunction

      public RetryFunction(Function<F,T> function, int tries)
      An instance that does nothing before retrying and ignores exceptions that occur.
      Parameters:
      function - which fetches the result, must not be null
      tries - the numbe rof times to attempt to get a result, must be positive
    • RetryFunction

      public RetryFunction(Function<F,T> function, int tries, ExceptionHandler handler)
      An instance that does nothing before retrying.
      Parameters:
      function - 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
    • RetryFunction

      public RetryFunction(Function<F,T> function, int tries, ExceptionHandler handler, Runnable beforeRetry)

      Constructor for RetryFunction.

      Parameters:
      function - 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 - an effect that is run before a retry attempt
  • Method Details

    • apply

      public T apply(F parameter)
      Attempt to apply parameter to the wrapped Function 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:
      apply in interface Function<F,T>