Interface Retry

All Superinterfaces:
FtHandler, RuntimeType.Api<RetryConfig>

public interface Retry extends FtHandler, RuntimeType.Api<RetryConfig>
Retry supports retry policies to be applied on an execution of asynchronous tasks.
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Interface
    Description
    static class 
    A retry policy that prolongs the delays between retries by a defined factor.
    static class 
    A retry policy that randomizes delays between execution using a "jitter" time.
    static interface 
    Retry policy to handle delays between retries.
    static interface 
    Strategy used to wait before another invocation attempt.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final String
    Counter for all the calls in a retry.
    static final String
    Counter for all retry calls, excluding the initial call.
  • Method Summary

    Modifier and Type
    Method
    Description
    Create a new retry fluent API builder.
    static Retry
    create(RetryConfig retryConfig)
    Create a new retry from its configuration.
    static Retry
    Create a new retry with customized configuration.
    default <T> T
    invoke(Function<RetryContext, ? extends T> function)
    Invoke a function with context for each attempt.
    default <T> T
    invoke(Function<RetryContext, ? extends T> function, Retry.WaitStrategy waitStrategy)
    Invoke a function with context for each attempt, using a caller-provided strategy to wait between attempts.
    long
    Number of times a method called has been retried.

    Methods inherited from interface FtHandler

    invoke, name
    Modifier and Type
    Method
    Description
    <T> T
    invoke(Supplier<? extends T> supplier)
    Invoke this fault tolerance handler on a supplier of result.
    A name assigned to a handler for debugging, error reporting or configuration purposes.

    Methods inherited from interface RuntimeType.Api

    prototype
    Modifier and Type
    Method
    Description
    The prototype as it was received when creating this runtime object instance.
  • Field Details

  • Method Details

    • create

      static Retry create(RetryConfig retryConfig)
      Create a new retry from its configuration.
      Parameters:
      retryConfig - configuration of the retry to create
      Returns:
      a new retry
    • create

      static Retry create(Consumer<RetryConfig.Builder> builderConsumer)
      Create a new retry with customized configuration.
      Parameters:
      builderConsumer - consumer of builder
      Returns:
      a new retry customized through builder
    • builder

      static RetryConfig.Builder builder()
      Create a new retry fluent API builder.
      Returns:
      a new builder
    • retryCounter

      long retryCounter()
      Number of times a method called has been retried. This is a monotonically increasing counter over the lifetime of the handler.
      Returns:
      number of times a method is retried
    • invoke

      default <T> T invoke(Function<RetryContext, ? extends T> function)
      Invoke a function with context for each attempt.

      Unlike FtHandler.invoke(Supplier), an invocation that does not complete successfully always throws a RetryException. The exception contains the retry outcome, including a termination reason.

      Type Parameters:
      T - type of result
      Parameters:
      function - function invoked for each attempt
      Returns:
      result obtained from the function
      Throws:
      RetryException - if the invocation does not complete successfully
      UnsupportedOperationException - if you use a custom retry implementation, and it does not implement this method
    • invoke

      default <T> T invoke(Function<RetryContext, ? extends T> function, Retry.WaitStrategy waitStrategy)
      Invoke a function with context for each attempt, using a caller-provided strategy to wait between attempts.

      The wait strategy can perform work needed to keep a resource alive while waiting, or terminate retries by returning false.

      Type Parameters:
      T - type of result
      Parameters:
      function - function invoked for each attempt
      waitStrategy - strategy that waits between attempts
      Returns:
      result obtained from the function
      Throws:
      RetryException - if the invocation does not complete successfully
      UnsupportedOperationException - if you use a custom retry implementation, and it does not implement this method