Class RetryPolicy

java.lang.Object
codes.grow.packages.skywalking.core.RetryPolicy

public final class RetryPolicy extends Object
Retry settings with full-jitter exponential backoff (SPEC section 2.3).

Backoff before retry n (0-based) is a uniform random value in [0, min(maxBackoff, initialBackoff * multiplier^n)).

  • Field Details

    • DEFAULT_MAX_RETRIES

      public static final int DEFAULT_MAX_RETRIES
      Default maximum number of retries (so up to 4 attempts).
      See Also:
  • Method Details

    • defaults

      public static RetryPolicy defaults()
      Returns the default policy: 3 retries, 100 ms initial, 10 s max, multiplier 2, Retry-After up to 60 s.
      Returns:
      the default policy
    • none

      public static RetryPolicy none()
      Returns a policy that never retries.
      Returns:
      a policy with maxRetries = 0
    • builder

      public static RetryPolicy.Builder builder()
      Starts a builder with the defaults.
      Returns:
      a new builder
    • toBuilder

      public RetryPolicy.Builder toBuilder()
      Returns a builder initialised from this policy.
      Returns:
      a new builder
    • maxRetries

      public int maxRetries()
      Returns the maximum number of retries after the first attempt.
      Returns:
      retries, >= 0
    • initialBackoff

      public Duration initialBackoff()
      Returns the backoff cap for the first retry.
      Returns:
      the initial backoff
    • maxBackoff

      public Duration maxBackoff()
      Returns the upper bound of any backoff.
      Returns:
      the maximum backoff
    • multiplier

      public double multiplier()
      Returns the exponential growth factor.
      Returns:
      the multiplier
    • maxRetryAfter

      public Duration maxRetryAfter()
      Returns the longest Retry-After wait the client accepts.
      Returns:
      the maximum Retry-After
    • backoffCap

      public Duration backoffCap(int retry)
      Returns the upper bound of the jitter window for retry n.
      Parameters:
      retry - 0-based retry number
      Returns:
      min(maxBackoff, initialBackoff * multiplier^retry)
    • backoff

      public Duration backoff(int retry)
      Computes the full-jitter backoff for retry n.
      Parameters:
      retry - 0-based retry number
      Returns:
      a uniform random duration in [0, backoffCap(retry))
    • parseRetryAfter

      public static Optional<Duration> parseRetryAfter(String value, Instant now)
      Parses a Retry-After header: delay seconds or an HTTP-date.
      Parameters:
      value - header value, may be null
      now - current time, used for HTTP-dates
      Returns:
      the wait (never negative), or empty when absent or unparseable
    • parseRateLimitReset

      public static Optional<Duration> parseRateLimitReset(String value, Instant now)
      Parses a vendor rate-limit reset header such as X-RateLimit-Reset: delay seconds (decimals allowed), Unix epoch seconds (values of at least 1000000000) or an HTTP-date.
      Parameters:
      value - header value, may be null
      now - current time, used for epoch seconds and HTTP-dates
      Returns:
      the wait (never negative), or empty when absent or unparseable
    • toString

      public String toString()
      Overrides:
      toString in class Object