Class RetryPolicy

java.lang.Object
com.pyranid.RetryPolicy

@ThreadSafe public final class RetryPolicy extends Object
Defines when and how 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
  • Method Details

    • ofMaxAttempts

      Creates a retry policy.

      maxAttempts is the total number of attempts, including the initial attempt. For example, 3 means one initial attempt plus up to two retries.

      Parameters:
      maxAttempts - total attempts, including the initial attempt
      backoff - determines how long to wait before the next retry
      condition - 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

      Gets the retry backoff.
      Returns:
      retry backoff
    • 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

      Overrides:
      toString in class Object