Class RetryPolicy

java.lang.Object
dev.ua.theroer.magicutils.http.RetryPolicy

public final class RetryPolicy extends Object
Retry policy for HTTP requests with exponential backoff.
  • Method Details

    • fromConfig

      public static RetryPolicy fromConfig(HttpClientConfig.RetrySettings settings)
      Creates a retry policy from configuration settings.
      Parameters:
      settings - retry settings or null
      Returns:
      retry policy instance
    • disabled

      public static RetryPolicy 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

      public boolean shouldRetryThrowable(Throwable throwable)
      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