Interface Retry


@ReleasedSince("26.9.3") @NullMarked public interface Retry
Represents a retry strategy configuration for asynchronous execution units such as FutureAction.

Inspired by reactive backoff models, instances of this interface define attempt limits, delay intervals, conditional error filtering, and interception hooks for each retry attempt.

  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Interface
    Description
    static interface 
    Encapsulates runtime contextual metadata associated with the current retry iteration.
  • Method Summary

    Modifier and Type
    Method
    Description
    Registers a listener to be invoked before each retry execution is dispatched.
    filter(Predicate<? super Throwable> condition)
    Specifies a condition to filter which exceptions are eligible for retry attempts.
    static Retry
    fixedDelay(long maxAttempts, Duration delay)
    Creates a retry strategy that retries up to the given maximum attempts with a fixed backoff delay between attempts.
    Retrieves the delay duration configured between retry attempts.
    @Nullable Predicate<? super Throwable>
    Retrieves the predicate used to evaluate whether an exception qualifies for a retry attempt.
    long
    Retrieves the maximum number of retry attempts configured for this strategy.
    Retrieves the configured listener callback executed prior to every retry invocation.
    static Retry
    max(long maxAttempts)
    Creates a retry strategy that immediately retries up to the given maximum attempts with zero delay.
  • Method Details

    • max

      @CheckReturnValue static Retry max(long maxAttempts)
      Creates a retry strategy that immediately retries up to the given maximum attempts with zero delay.
      Parameters:
      maxAttempts - The maximum number of retry attempts. Must be non-negative.
      Returns:
      A new Retry strategy instance.
    • fixedDelay

      @CheckReturnValue static Retry fixedDelay(long maxAttempts, Duration delay)
      Creates a retry strategy that retries up to the given maximum attempts with a fixed backoff delay between attempts.
      Parameters:
      maxAttempts - The maximum number of retry attempts. Must be non-negative.
      delay - The fixed duration to wait before triggering the next retry attempt.
      Returns:
      A new Retry strategy instance.
    • getMaxAttempts

      long getMaxAttempts()
      Retrieves the maximum number of retry attempts configured for this strategy.
      Returns:
      The maximum retry count.
    • getDelay

      Duration getDelay()
      Retrieves the delay duration configured between retry attempts.
      Returns:
      The backoff Duration.
    • getRetryListener

      @Nullable @Nullable Consumer<Retry.RetryContext> getRetryListener()
      Retrieves the configured listener callback executed prior to every retry invocation.
      Returns:
      The retry consumer callback, or null if none was registered.
    • getFilter

      @Nullable @Nullable Predicate<? super Throwable> getFilter()
      Retrieves the predicate used to evaluate whether an exception qualifies for a retry attempt.
      Returns:
      The error evaluation predicate, or null if all exceptions are eligible.
    • doBeforeRetry

      @CheckReturnValue Retry doBeforeRetry(Consumer<Retry.RetryContext> action)
      Registers a listener to be invoked before each retry execution is dispatched.

      Typically used for tracking metrics, debugging, or logging contextual retry details.

      Parameters:
      action - A consumer accepting the active Retry.RetryContext.
      Returns:
      The current Retry instance for method chaining.
    • filter

      @CheckReturnValue Retry filter(Predicate<? super Throwable> condition)
      Specifies a condition to filter which exceptions are eligible for retry attempts. If an exception does not satisfy this predicate, the failure propagates immediately without further retries.
      Parameters:
      condition - A predicate evaluating the encountered Throwable.
      Returns:
      The current Retry instance for method chaining.