Package com.dianxin.tori.base.concurrent
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 ClassesModifier and TypeInterfaceDescriptionstatic interfaceEncapsulates runtime contextual metadata associated with the current retry iteration. -
Method Summary
Modifier and TypeMethodDescriptiondoBeforeRetry(Consumer<Retry.RetryContext> action) Registers a listener to be invoked before each retry execution is dispatched.Specifies a condition to filter which exceptions are eligible for retry attempts.static RetryfixedDelay(long maxAttempts, Duration delay) Creates a retry strategy that retries up to the given maximum attempts with a fixed backoff delay between attempts.getDelay()Retrieves the delay duration configured between retry attempts.Retrieves the predicate used to evaluate whether an exception qualifies for a retry attempt.longRetrieves the maximum number of retry attempts configured for this strategy.@Nullable Consumer<Retry.RetryContext> Retrieves the configured listener callback executed prior to every retry invocation.static Retrymax(long maxAttempts) Creates a retry strategy that immediately retries up to the given maximum attempts with zero delay.
-
Method Details
-
max
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
Retrystrategy instance.
-
fixedDelay
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
Retrystrategy 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
Retrieves the configured listener callback executed prior to every retry invocation.- Returns:
- The retry consumer callback, or
nullif none was registered.
-
getFilter
Retrieves the predicate used to evaluate whether an exception qualifies for a retry attempt.- Returns:
- The error evaluation predicate, or
nullif all exceptions are eligible.
-
doBeforeRetry
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 activeRetry.RetryContext.- Returns:
- The current
Retryinstance for method chaining.
-
filter
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.
-