Class RetryUtil

java.lang.Object
com.cercalia.sdk.util.RetryUtil

public final class RetryUtil extends Object
Retry utility for Cercalia API calls. Implements silent retry logic with exponential backoff.
  • Method Details

    • options

      public static RetryUtil.RetryOptions options()
      Creates default retry options.
      Returns:
      a new RetryUtil.RetryOptions instance.
    • withRetry

      public static <T> T withRetry(Callable<T> callable, RetryUtil.RetryOptions options) throws Exception
      Execute a callable with automatic retries.
      Type Parameters:
      T - the return type.
      Parameters:
      callable - the callable to execute.
      options - retry configuration options.
      Returns:
      the result of the callable if successful.
      Throws:
      Exception - the last exception if all attempts fail.
    • withRetry

      public static <T> T withRetry(Callable<T> callable, String operationName) throws Exception
      Execute a callable with automatic retries using default options.
      Type Parameters:
      T - the return type.
      Parameters:
      callable - the callable to execute.
      operationName - the operation name for logging.
      Returns:
      the result of the callable if successful.
      Throws:
      Exception - the last exception if all attempts fail.
    • withRetryUnchecked

      public static <T> T withRetryUnchecked(Supplier<T> supplier, RetryUtil.RetryOptions options)
      Execute a supplier with automatic retries (RuntimeException only).
      Type Parameters:
      T - the return type.
      Parameters:
      supplier - the supplier to execute.
      options - retry configuration options.
      Returns:
      the result of the supplier if successful.
      Throws:
      RuntimeException - the last exception if all attempts fail.
    • withRetryAlternatives

      public static <T> T withRetryAlternatives(List<Supplier<T>> alternatives, RetryUtil.RetryOptions options)
      Execute multiple alternative suppliers until one succeeds.
      Type Parameters:
      T - the return type.
      Parameters:
      alternatives - list of suppliers to try in order.
      options - retry configuration options.
      Returns:
      the result of the first successful supplier, or null if all fail.