Class RetryPolicy
Database.transactionWithRetry(RetryPolicy, TransactionalOperation) retries a transaction.
A retry policy requires all retry-critical decisions to be explicit: total attempts, retry condition, and backoff.
- Since:
- 4.4.0
- Author:
- Mark Allen
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interfaceDetermines how long to wait before retrying after a failed attempt.static interfaceDetermines whether a failed transaction attempt should be retried. -
Method Summary
Modifier and TypeMethodDescriptionGets the retry backoff.Gets the retry condition.Gets the total number of attempts, including the initial attempt.Gets the elapsed retry budget, if any.static @NonNull RetryPolicyofMaxAttempts(@NonNull Integer maxAttempts, @NonNull RetryPolicy.Backoff backoff, @NonNull RetryPolicy.Condition condition) Creates a retry policy.toString()withMaxElapsedTime(@NonNull Duration limit) Copies this policy with a positive elapsed retry budget measured from the start of the first attempt.Copies this policy without an elapsed retry budget.
-
Method Details
-
ofMaxAttempts
public static @NonNull RetryPolicy ofMaxAttempts(@NonNull Integer maxAttempts, @NonNull RetryPolicy.Backoff backoff, @NonNull RetryPolicy.Condition condition) Creates a retry policy.maxAttemptsis the total number of attempts, including the initial attempt. For example,3means one initial attempt plus up to two retries.- Parameters:
maxAttempts- total attempts, including the initial attemptbackoff- determines how long to wait before the next retrycondition- determines whether a failed attempt is retryable- Returns:
- a retry policy
-
getMaxAttempts
Gets the total number of attempts, including the initial attempt.- Returns:
- total attempts
-
getCondition
Gets the retry condition.- Returns:
- retry condition
-
getBackoff
-
withMaxElapsedTime
Copies this policy with a positive elapsed retry budget measured from the start of the first attempt.Work, cleanup, completion observation, policy evaluation, and backoff all consume the budget. The initial attempt always runs. No later attempt starts once the budget is exhausted, and a delay that would exhaust the remaining budget is not slept. Exhaustion propagates the final original database failure, retaining earlier failures as suppressed exceptions. This is retry admission control, not a timeout: an in-flight attempt can succeed after the budget expires and is never cancelled by this setting.
- Parameters:
limit- strictly positive elapsed limit- Returns:
- a new policy with the elapsed limit
- Since:
- 4.8.0
-
withoutMaxElapsedTime
Copies this policy without an elapsed retry budget.- Returns:
- a new policy without an elapsed limit
- Since:
- 4.8.0
-
getMaxElapsedTime
Gets the elapsed retry budget, if any.- Returns:
- elapsed limit
- Since:
- 4.8.0
-
toString
-