Interface Retry

All Known Implementing Classes:
RetryImpl

public interface Retry
A Retry instance is thread-safe can be used to decorate multiple requests. A Retry.
  • Method Details

    • of

      static Retry of(String name, RetryConfig retryConfig)
      Creates a Retry with a custom Retry configuration.
      Parameters:
      name - the ID of the Retry
      retryConfig - a custom Retry configuration
      Returns:
      a Retry with a custom Retry configuration.
    • of

      static Retry of(String name, RetryConfig retryConfig, Map<String,String> tags)
      Creates a Retry with a custom Retry configuration.
      Parameters:
      name - the ID of the Retry
      retryConfig - a custom Retry configuration
      tags - tags to assign to the Retry
      Returns:
      a Retry with a custom Retry configuration.
    • of

      static Retry of(String name, Supplier<RetryConfig> retryConfigSupplier)
      Creates a Retry with a custom Retry configuration.
      Parameters:
      name - the ID of the Retry
      retryConfigSupplier - a supplier of a custom Retry configuration
      Returns:
      a Retry with a custom Retry configuration.
    • of

      static Retry of(String name, Supplier<RetryConfig> retryConfigSupplier, Map<String,String> tags)
      Creates a Retry with a custom Retry configuration.
      Parameters:
      name - the ID of the Retry
      retryConfigSupplier - a supplier of a custom Retry configuration
      tags - tags to assign to the Retry
      Returns:
      a Retry with a custom Retry configuration.
    • ofDefaults

      static Retry ofDefaults(String name)
      Creates a Retry with default configuration.
      Parameters:
      name - the ID of the Retry
      Returns:
      a Retry with default configuration
    • decorateCompletionStage

      static <T> Supplier<CompletionStage<T>> decorateCompletionStage(Retry retry, ScheduledExecutorService scheduler, Supplier<CompletionStage<T>> supplier)
      Decorates CompletionStageSupplier with Retry
      Type Parameters:
      T - type of completion stage result
      Parameters:
      retry - the retry context
      scheduler - execution service to use to schedule retries
      supplier - completion stage supplier
      Returns:
      decorated supplier
    • decorateCompletionStage

      default <T> Supplier<CompletionStage<T>> decorateCompletionStage(ScheduledExecutorService scheduler, Supplier<CompletionStage<T>> supplier)
      Decorates CompletionStageSupplier using current instance as context.
      Type Parameters:
      T - type of completion stage result
      Parameters:
      scheduler - execution service to use to schedule retries
      supplier - completion stage supplier
      Returns:
      decorated supplier
    • decorateCheckedSupplier

      static <T> io.github.resilience4j.core.functions.CheckedSupplier<T> decorateCheckedSupplier(Retry retry, io.github.resilience4j.core.functions.CheckedSupplier<T> supplier)
      Creates a retryable supplier.
      Type Parameters:
      T - the type of results supplied by this supplier
      Parameters:
      retry - the retry context
      supplier - the original function
      Returns:
      a retryable function
    • decorateCheckedSupplier

      default <T> io.github.resilience4j.core.functions.CheckedSupplier<T> decorateCheckedSupplier(io.github.resilience4j.core.functions.CheckedSupplier<T> supplier)
      Creates a retryable supplier using current instance as context.
      Type Parameters:
      T - the type of results supplied by this supplier
      Parameters:
      supplier - the original function
      Returns:
      a retryable function
    • decorateCheckedRunnable

      static io.github.resilience4j.core.functions.CheckedRunnable decorateCheckedRunnable(Retry retry, io.github.resilience4j.core.functions.CheckedRunnable runnable)
      Creates a retryable runnable.
      Parameters:
      retry - the retry context
      runnable - the original runnable
      Returns:
      a retryable runnable
    • decorateCheckedRunnable

      default io.github.resilience4j.core.functions.CheckedRunnable decorateCheckedRunnable(io.github.resilience4j.core.functions.CheckedRunnable runnable)
      Creates a retryable runnable using current instance as context.
      Parameters:
      runnable - the original runnable
      Returns:
      a retryable runnable
    • decorateCheckedFunction

      static <T, R> io.github.resilience4j.core.functions.CheckedFunction<T,R> decorateCheckedFunction(Retry retry, io.github.resilience4j.core.functions.CheckedFunction<T,R> function)
      Creates a retryable function.
      Type Parameters:
      T - the type of the input to the function
      R - the result type of the function
      Parameters:
      retry - the retry context
      function - the original function
      Returns:
      a retryable function
    • decorateCheckedFunction

      default <T, R> io.github.resilience4j.core.functions.CheckedFunction<T,R> decorateCheckedFunction(io.github.resilience4j.core.functions.CheckedFunction<T,R> function)
      Creates a retryable function using current instance as context.
      Type Parameters:
      T - the type of the input to the function
      R - the result type of the function
      Parameters:
      function - the original function
      Returns:
      a retryable function
    • decorateCheckedConsumer

      static <T> io.github.resilience4j.core.functions.CheckedConsumer<T> decorateCheckedConsumer(Retry retry, io.github.resilience4j.core.functions.CheckedConsumer<T> consumer)
      Creates a retryable consumer.
      Type Parameters:
      T - the type of the input to the consumer
      Parameters:
      retry - the retry context
      consumer - the original consumer
      Returns:
      a retryable consumer
    • decorateCheckedConsumer

      default <T> io.github.resilience4j.core.functions.CheckedConsumer<T> decorateCheckedConsumer(io.github.resilience4j.core.functions.CheckedConsumer<T> consumer)
      Creates a retryable consumer using current instance as context.
      Type Parameters:
      T - the type of the input to the consumer
      Parameters:
      consumer - the original consumer
      Returns:
      a retryable consumer
    • decorateSupplier

      static <T> Supplier<T> decorateSupplier(Retry retry, Supplier<T> supplier)
      Creates a retryable supplier.
      Type Parameters:
      T - the type of results supplied by this supplier
      Parameters:
      retry - the retry context
      supplier - the original function
      Returns:
      a retryable function
    • decorateSupplier

      default <T> Supplier<T> decorateSupplier(Supplier<T> supplier)
      Creates a retryable supplier using current instance as context.
      Type Parameters:
      T - the type of results supplied by this supplier
      Parameters:
      supplier - the original function
      Returns:
      a retryable function
    • decorateCallable

      static <T> Callable<T> decorateCallable(Retry retry, Callable<T> supplier)
      Creates a retryable callable.
      Type Parameters:
      T - the type of results supplied by this supplier
      Parameters:
      retry - the retry context
      supplier - the original function
      Returns:
      a retryable function
    • decorateCallable

      default <T> Callable<T> decorateCallable(Callable<T> supplier)
      Creates a retryable callable using current instance as context.
      Type Parameters:
      T - the type of results supplied by this supplier
      Parameters:
      supplier - the original function
      Returns:
      a retryable function
    • decorateRunnable

      static Runnable decorateRunnable(Retry retry, Runnable runnable)
      Creates a retryable runnable.
      Parameters:
      retry - the retry context
      runnable - the original runnable
      Returns:
      a retryable runnable
    • decorateRunnable

      default Runnable decorateRunnable(Runnable runnable)
      Creates a retryable runnable using current instance as context.
      Parameters:
      runnable - the original runnable
      Returns:
      a retryable runnable
    • decorateFunction

      static <T, R> Function<T,R> decorateFunction(Retry retry, Function<T,R> function)
      Creates a retryable function.
      Type Parameters:
      T - the type of the input to the function
      R - the result type of the function
      Parameters:
      retry - the retry context
      function - the original function
      Returns:
      a retryable function
    • decorateConsumer

      static <T> Consumer<T> decorateConsumer(Retry retry, Consumer<T> consumer)
      Creates a retryable consumer.
      Type Parameters:
      T - the type of the input to the consumer
      Parameters:
      retry - the retry context
      consumer - the original consumer
      Returns:
      a retryable consumer
    • decorateConsumer

      default <T> Consumer<T> decorateConsumer(Consumer<T> consumer)
      Creates a retryable consumer using current instance as context.
      Parameters:
      consumer - the original consumer
      Returns:
      a retryable consumer
    • getName

      String getName()
      Returns the ID of this Retry.
      Returns:
      the ID of this Retry
    • context

      <T> Retry.Context<T> context()
      Creates a retry Context.
      Returns:
      the retry Context
    • asyncContext

      <T> Retry.AsyncContext<T> asyncContext()
      Creates a async retry Context.
      Returns:
      the async retry Context
    • getRetryConfig

      RetryConfig getRetryConfig()
      Returns the RetryConfig of this Retry.
      Returns:
      the RetryConfig of this Retry
    • getTags

      Map<String,String> getTags()
      Returns an unmodifiable map with tags assigned to this Retry.
      Returns:
      the tags assigned to this Retry in an unmodifiable map
    • getEventPublisher

      Retry.EventPublisher getEventPublisher()
      Returns an EventPublisher can be used to register event consumers.
      Returns:
      an EventPublisher
    • executeCheckedSupplier

      default <T> T executeCheckedSupplier(io.github.resilience4j.core.functions.CheckedSupplier<T> checkedSupplier) throws Throwable
      Decorates and executes the decorated Supplier.
      Type Parameters:
      T - the type of results supplied by this supplier
      Parameters:
      checkedSupplier - the original Supplier
      Returns:
      the result of the decorated Supplier.
      Throws:
      Throwable - if something goes wrong applying this function to the given arguments
    • executeSupplier

      default <T> T executeSupplier(Supplier<T> supplier)
      Decorates and executes the decorated Supplier.
      Type Parameters:
      T - the type of results supplied by this supplier
      Parameters:
      supplier - the original Supplier
      Returns:
      the result of the decorated Supplier.
    • executeCallable

      default <T> T executeCallable(Callable<T> callable) throws Exception
      Decorates and executes the decorated Callable.
      Type Parameters:
      T - the result type of callable
      Parameters:
      callable - the original Callable
      Returns:
      the result of the decorated Callable.
      Throws:
      Exception - if unable to compute a result
    • executeRunnable

      default void executeRunnable(Runnable runnable)
      Decorates and executes the decorated Runnable.
      Parameters:
      runnable - the original Runnable
    • executeCompletionStage

      default <T> CompletionStage<T> executeCompletionStage(ScheduledExecutorService scheduler, Supplier<CompletionStage<T>> supplier)
      Decorates and executes the decorated CompletionStage.
      Type Parameters:
      T - the type of results supplied by this supplier
      Parameters:
      scheduler - execution service to use to schedule retries
      supplier - the original CompletionStage
      Returns:
      the decorated CompletionStage.
    • getMetrics

      Retry.Metrics getMetrics()
      Get the Metrics of this Retry instance.
      Returns:
      the Metrics of this Retry instance