Class Retry<T>

java.lang.Object
com.atlassian.jira.user.anonymize.Retry<T>
Type Parameters:
T - return type

@Internal public class Retry<T> extends Object
Captures exceptions thrown in a given closure and allows retrying.
  • Method Details

    • from

      public static <T> Retry<T> from(Supplier<T> supplier)
    • from

      public static Retry<com.atlassian.jira.user.anonymize.Retry.NullReturn> from(Runnable runnable)
    • onException

      public Retry<T> onException(Consumer<Exception> exceptionHandler)
      Sets the handler function that will be called every time the closure throws an exception -- passing that exception as an argument -- even if there're retries left. There can be only one handler of this type at one time. Any subsequent call to this function will override the previous value.
      Parameters:
      exceptionHandler - handler function or null to remove the previous handler
      Returns:
      a fresh object with new configuration
    • onFail

      public Retry<T> onFail(Consumer<Exception> failureHandler)
      Sets the the handler function that will be called after execution of the closure had failed and the number of retries is exhausted. The argument passed to the handler is the last exception returned from the closure. There can be only one handler of this type at one time. Any subsequent call to this function will override the previous value.
      Parameters:
      failureHandler - handler function or null to remove the previous handler
      Returns:
      a fresh object with new configuration
    • onSuccess

      public Retry<T> onSuccess(Consumer<Integer> successHandler)
      Sets the function called after successful execution of the closure. Number of retries necessary to achieve success is passed as an argument. There can be only one handler of this type at one time. Any subsequent call to this function will override the previous value.
      Parameters:
      successHandler - handler function or null to remove the previous handler
      Returns:
      a fresh object with new configuration
    • rethrowOnFail

      public Retry rethrowOnFail()
    • executeOnce

      public io.atlassian.fugue.Either<Exception,T> executeOnce()
      Run the closure once and don't retry
      Returns:
      return value of the closure, null if there was an exception
    • executeTimes

      public io.atlassian.fugue.Either<Exception,T> executeTimes(int times)
      Run the closure once and then retry the given number of times.
      Parameters:
      times - number of retires. "0" causes the closure to be called only once
      Returns:
      return value of the last call to the closure, null if all retires were unsuccessful