Class RetryPolicy
java.lang.Object
com.shaft.api.RetryPolicy
Opt-in retry policy for
RequestBuilder.perform().
Retries are limited to idempotent HTTP methods by default. Use
allowNonIdempotentRequests() only when retrying POST or PATCH is safe
for the target API.
-
Method Summary
Modifier and TypeMethodDescriptionAllows retries for POST and PATCH requests.exponentialBackoff(Duration initialDelay, Duration maxDelay) Doubles the delay after each failed attempt untilmaxDelay.fixedBackoff(Duration delay) Uses the same delay before each retry.jitteredBackoff(Duration initialDelay, Duration maxDelay) Uses exponential backoff with a random delay between zero and the current exponential delay.maxAttempts(int maxAttempts) Sets the total number of attempts, including the first request.static RetryPolicystatusCodes(int... statusCodes) Retries the supplied HTTP status codes.static RetryPolicyRetries transient network failures and common transient HTTP statuses: 408, 429, 500, 502, 503, and 504.
-
Method Details
-
transientFailures
Retries transient network failures and common transient HTTP statuses: 408, 429, 500, 502, 503, and 504.- Returns:
- a retry policy with safe transient defaults
-
statusCodes
Retries the supplied HTTP status codes.- Parameters:
statusCodes- HTTP statuses to retry- Returns:
- a retry policy for the supplied statuses
- Throws:
IllegalArgumentException- if no status codes are supplied or a code is outside 100-599
-
maxAttempts
Sets the total number of attempts, including the first request.- Parameters:
maxAttempts- total attempts; must be greater than zero- Returns:
- this retry policy
-
allowNonIdempotentRequests
Allows retries for POST and PATCH requests.- Returns:
- this retry policy
-
fixedBackoff
Uses the same delay before each retry.- Parameters:
delay- delay before the next attempt- Returns:
- this retry policy
-
exponentialBackoff
Doubles the delay after each failed attempt untilmaxDelay.- Parameters:
initialDelay- delay before the first retrymaxDelay- upper delay bound- Returns:
- this retry policy
-
jitteredBackoff
Uses exponential backoff with a random delay between zero and the current exponential delay.- Parameters:
initialDelay- maximum delay before the first retrymaxDelay- upper delay bound- Returns:
- this retry policy
-