Class RetryPolicy
java.lang.Object
dev.ua.theroer.magicutils.http.RetryPolicy
Retry policy for HTTP requests with exponential backoff.
-
Method Summary
Modifier and TypeMethodDescriptionstatic RetryPolicydisabled()Returns a disabled retry policy.static RetryPolicyfromConfig(HttpClientConfig.RetrySettings settings) Creates a retry policy from configuration settings.booleanChecks whether retries are enabled.intReturns max attempts per request.longnextDelayMs(int attempt) Calculates the next retry delay in milliseconds.booleanshouldRetryStatus(int status) Checks whether a status code should be retried.booleanshouldRetryThrowable(Throwable throwable) Checks whether a throwable should be retried.
-
Method Details
-
fromConfig
Creates a retry policy from configuration settings.- Parameters:
settings- retry settings or null- Returns:
- retry policy instance
-
disabled
Returns a disabled retry policy.- Returns:
- disabled retry policy
-
isEnabled
public boolean isEnabled()Checks whether retries are enabled.- Returns:
- true when retries are enabled and max attempts > 1
-
maxAttempts
public int maxAttempts()Returns max attempts per request.- Returns:
- max attempts (including the first try)
-
shouldRetryStatus
public boolean shouldRetryStatus(int status) Checks whether a status code should be retried.- Parameters:
status- HTTP status code- Returns:
- true if retry should be attempted
-
shouldRetryThrowable
Checks whether a throwable should be retried.- Parameters:
throwable- error to evaluate- Returns:
- true if retry should be attempted
-
nextDelayMs
public long nextDelayMs(int attempt) Calculates the next retry delay in milliseconds.- Parameters:
attempt- current attempt (1-based)- Returns:
- delay in milliseconds
-