Class FixedRetry

java.lang.Object
com.helixframework.retry.FixedRetry

public final class FixedRetry extends Object
Wrapper function that retries with fixed delay in the event of an exception.
  • Field Details

    • DEFAULT_MAX_RETRIES

      public static final int DEFAULT_MAX_RETRIES
      Default number of retries attempted by this function before throwing RetriesExhaustedException.
      See Also:
    • DEFAULT_INITIAL_DELAY

      public static final Duration DEFAULT_INITIAL_DELAY
      Default initial delay before retry is attempted. Defaults to 1 second.
    • DEFAULT_DELAY

      public static final Duration DEFAULT_DELAY
      Default delay between retry attempts. Defaults to 1 second.
  • Method Details

    • execute

      public static <T> T execute(RetryableFunction<T> fn) throws RetriesExhaustedException
      Executes a retryable function.
      Type Parameters:
      T - the return type of the retryable function
      Parameters:
      fn - the retryable function to execute
      Returns:
      the result of the retryable function
      Throws:
      RetriesExhaustedException - if the maximum number of retries is exhausted
    • execute

      public static <T> T execute(RetryableFunction<T> fn, int maxRetries) throws RetriesExhaustedException
      Executes a retryable function with a specified maximum number of retries.
      Type Parameters:
      T - the return type of the retryable function
      Parameters:
      fn - the retryable function to execute
      maxRetries - the maximum number of retries
      Returns:
      the result of the retryable function
      Throws:
      RetriesExhaustedException - if the maximum number of retries is exhausted
    • execute

      public static <T> T execute(RetryableFunction<T> fn, int maxRetries, Duration delay) throws RetriesExhaustedException
      Executes a retryable function with a specified maximum number of retries and delay duration.
      Type Parameters:
      T - the return type of the retryable function
      Parameters:
      fn - the retryable function to execute
      maxRetries - the maximum number of retries
      delay - the delay between retries
      Returns:
      the result of the retryable function
      Throws:
      RetriesExhaustedException - if the maximum number of retries is exhausted
    • execute

      public static <T> T execute(RetryableFunction<T> fn, int maxRetries, Duration delay, Duration initialDelay) throws RetriesExhaustedException
      Executes a retryable function with a specified maximum number of retries, delay, and initial delay.
      Type Parameters:
      T - the return type of the retryable function
      Parameters:
      fn - the retryable function to execute
      maxRetries - the maximum number of retries
      delay - the delay between retries
      initialDelay - the initial delay before the first retry
      Returns:
      the result of the retryable function
      Throws:
      RetriesExhaustedException - if the maximum number of retries is exhausted
    • execute

      public static <T> T execute(RetryableFunction<T> fn, Collection<Class<? extends Throwable>> expectedErrors) throws RetriesExhaustedException
      Executes a retryable function with a collection of expected errors that will not trigger a retry.
      Type Parameters:
      T - the return type of the retryable function
      Parameters:
      fn - the retryable function to execute
      expectedErrors - a collection of expected error classes that will not trigger a retry
      Returns:
      the result of the retryable function
      Throws:
      RetriesExhaustedException - if the maximum number of retries is exhausted
    • execute

      public static <T> T execute(RetryableFunction<T> fn, int maxRetries, Collection<Class<? extends Throwable>> expectedErrors) throws RetriesExhaustedException
      Executes a retryable function with a specified maximum number of retries, delay, initial delay, and expected errors that will not trigger a retry.
      Type Parameters:
      T - the return type of the retryable function
      Parameters:
      fn - the retryable function to execute
      maxRetries - the maximum number of retries
      expectedErrors - a collection of expected error classes that will not trigger a retry
      Returns:
      the result of the retryable function
      Throws:
      RetriesExhaustedException - if the maximum number of retries is exhausted
      IllegalArgumentException - if maxRetries is negative, delay or initialDelay is null or negative
    • execute

      public static <T> T execute(RetryableFunction<T> fn, int maxRetries, Duration delay, Collection<Class<? extends Throwable>> expectedErrors) throws RetriesExhaustedException
      Executes a retryable function with a specified maximum number of retries, delay, and expected errors that will not trigger a retry.
      Type Parameters:
      T - the return type of the retryable function
      Parameters:
      fn - the retryable function to execute
      maxRetries - the maximum number of retries
      delay - the delay between retries
      expectedErrors - a collection of expected error classes that will not trigger a retry
      Returns:
      the result of the retryable function
      Throws:
      RetriesExhaustedException - if the maximum number of retries is exhausted
      IllegalArgumentException - if maxRetries is negative, delay or initialDelay is null or negative
    • execute

      public static <T> T execute(RetryableFunction<T> fn, int maxRetries, Duration delay, Duration initialDelay, Collection<Class<? extends Throwable>> expectedErrors) throws RetriesExhaustedException
      Executes a retryable function with the specified parameters.
      Type Parameters:
      T - the return type of the retryable function
      Parameters:
      fn - the retryable function to execute
      maxRetries - the maximum number of retries
      delay - the delay between retries
      initialDelay - the initial delay before the first retry
      expectedErrors - a collection of expected error classes that will not trigger a retry
      Returns:
      the result of the retryable function
      Throws:
      RetriesExhaustedException - if the maximum number of retries is exhausted
      IllegalArgumentException - if maxRetries is negative, delay or initialDelay is null or negative, or expectedErrors is null
    • execute

      public static <T> T execute(RetryableFunction<T> fn, Supplier<T> fallback)
      Executes a function with retry logic to handle expected errors.
      Type Parameters:
      T - the return type of the retryable function
      Parameters:
      fn - the retryable function to execute
      fallback - the supplier that provides a fallback value
      Returns:
      the result of the retryable function or the fallback value
    • execute

      public static <T> T execute(RetryableFunction<T> fn, int maxRetries, Supplier<T> fallback)
      Executes a function with retry logic to handle expected errors.
      Type Parameters:
      T - the return type of the retryable function
      Parameters:
      fn - the retryable function to execute
      maxRetries - the maximum number of retries
      fallback - the supplier that provides a fallback value
      Returns:
      the result of the retryable function or the fallback value
    • execute

      public static <T> T execute(RetryableFunction<T> fn, int maxRetries, Duration delay, Supplier<T> fallback)
      Executes a function with retry logic to handle expected errors.
      Type Parameters:
      T - the return type of the retryable function
      Parameters:
      fn - the retryable function to execute
      maxRetries - the maximum number of retries
      delay - the delay between retries
      fallback - the supplier that provides a fallback value
      Returns:
      the result of the retryable function
    • execute

      public static <T> T execute(RetryableFunction<T> fn, int maxRetries, Duration delay, Duration initialDelay, Supplier<T> fallback)
      Executes a function with retry logic to handle expected errors.
      Type Parameters:
      T - the type of the value returned by the retryable function
      Parameters:
      fn - the retryable function to execute
      maxRetries - the maximum number of retries to attempt if the function fails (non-negative integer)
      delay - the delay between retries (positive duration)
      initialDelay - the initial delay before the first retry (non-negative duration)
      fallback - the supplier to provide a fallback value if all retries fail
      Returns:
      the value returned by the retryable function if it succeeds, or the fallback value if all retries fail
    • execute

      public static <T> T execute(RetryableFunction<T> fn, int maxRetries, Duration delay, Duration initialDelay, Supplier<T> fallback, Collection<Class<? extends Throwable>> expectedErrors)
      Executes a function with retry logic to handle expected errors.
      Type Parameters:
      T - The return type of the function.
      Parameters:
      fn - The retryable function to execute.
      maxRetries - The maximum number of retries allowed.
      delay - The delay between each retry attempt.
      initialDelay - The initial delay before the first retry attempt.
      fallback - The fallback supplier to be called when all retries are exhausted.
      expectedErrors - The collection of expected error classes that should trigger a retry.
      Returns:
      The result of the function execution