Class JitterDelayRetryPolicy

java.lang.Object
io.unitycatalog.client.retry.JitterDelayRetryPolicy
All Implemented Interfaces:
RetryPolicy

public class JitterDelayRetryPolicy extends Object implements RetryPolicy
A retry policy implementation that uses exponential backoff with configurable jitter.

This policy implements the RetryPolicy interface and provides exponential backoff with jitter for retrying failed HTTP requests.

The delay for each retry attempt is calculated as: initialDelayMs * multiplier ^ (attempt - 1) * (1 ± jitterFactor)

Jitter helps prevent the "thundering herd" problem where many clients retry simultaneously. The jitter factor randomizes the delay within the range [baseDelay * (1 - jitterFactor), baseDelay * (1 + jitterFactor)].

Default configuration:

Example usage:


 RetryPolicy policy = JitterDelayRetryPolicy.builder()
     .maxAttempts(5)
     .initDelayMs(100L)
     .delayMultiplier(2.0)
     .delayJitterFactor(0.2)
     .build();
 
See Also:
  • Field Details

    • DEFAULT_MAX_ATTEMPTS

      public static final int DEFAULT_MAX_ATTEMPTS
      See Also:
    • DEFAULT_INITIAL_DELAY_MS

      public static final long DEFAULT_INITIAL_DELAY_MS
      See Also:
    • DEFAULT_DELAY_MULTIPLIER

      public static final double DEFAULT_DELAY_MULTIPLIER
      See Also:
    • DEFAULT_DELAY_JITTER_FACTOR

      public static final double DEFAULT_DELAY_JITTER_FACTOR
      See Also:
  • Method Details

    • maxAttempts

      public int maxAttempts()
      Description copied from interface: RetryPolicy
      Returns the maximum number of retry attempts allowed by this policy.

      This value determines the upper bound on retry attempts. A return value of 0 means no retries will be attempted (only the initial attempt), while a positive value indicates the maximum number of additional attempts after the initial failure.

      Specified by:
      maxAttempts in interface RetryPolicy
      Returns:
      the maximum number of retry attempts, must be non-negative
    • sleepTime

      public Duration sleepTime(int attempt)
      Calculates the sleep time before the next retry attempt using exponential backoff with jitter.
      Specified by:
      sleepTime in interface RetryPolicy
      Parameters:
      attempt - the current attempt number (1-indexed)
      Returns:
      the duration to sleep before retrying
    • allowRetry

      public boolean allowRetry(int attempt)
      Determines whether a retry should be attempted based on the current attempt number.
      Specified by:
      allowRetry in interface RetryPolicy
      Parameters:
      attempt - the current attempt number (1-indexed)
      Returns:
      true if retry is allowed, false otherwise
    • builder

      public static JitterDelayRetryPolicy.Builder builder()
      Creates a new builder for constructing a JitterDelayRetryPolicy.
      Returns:
      a new builder instance with default values