Package com.cercalia.sdk.util
Class RetryUtil
java.lang.Object
com.cercalia.sdk.util.RetryUtil
Retry utility for Cercalia API calls.
Implements silent retry logic with exponential backoff.
-
Nested Class Summary
Nested Classes -
Method Summary
Modifier and TypeMethodDescriptionstatic RetryUtil.RetryOptionsoptions()Creates default retry options.static <T> TwithRetry(Callable<T> callable, RetryUtil.RetryOptions options) Execute a callable with automatic retries.static <T> TExecute a callable with automatic retries using default options.static <T> TwithRetryAlternatives(List<Supplier<T>> alternatives, RetryUtil.RetryOptions options) Execute multiple alternative suppliers until one succeeds.static <T> TwithRetryUnchecked(Supplier<T> supplier, RetryUtil.RetryOptions options) Execute a supplier with automatic retries (RuntimeException only).
-
Method Details
-
options
Creates default retry options.- Returns:
- a new
RetryUtil.RetryOptionsinstance.
-
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
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
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
nullif all fail.
-