Interface RetryPolicy

All Known Implementing Classes:
JitterDelayRetryPolicy

public interface RetryPolicy
Defines a RetryPolicy for handling transient failures in Unity Catalog client operations.

Example usage:


 RetryPolicy policy = JitterDelayRetryPolicy.builder().build();
 for(int attempt = 1; policy.allowRetry(attempt); attempt +=1) {
   try {
     doSomeAction();
   } catch (Exception e) {
     if (isRetryable(e)){
       Thread.sleep(policy.sleepTime(attempt).toMillis());
     } else {
       throw e;
     }
   }
 }
 
  • Method Summary

    Modifier and Type
    Method
    Description
    boolean
    allowRetry(int attempt)
    Determines whether a retry should be allowed for the given attempt number.
    int
    Returns the maximum number of retry attempts allowed by this policy.
    sleepTime(int attempt)
    Calculates the sleep duration before the specified retry attempt.
  • Method Details

    • maxAttempts

      int maxAttempts()
      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.

      Returns:
      the maximum number of retry attempts, must be non-negative
    • sleepTime

      Duration sleepTime(int attempt)
      Calculates the sleep duration before the specified retry attempt.

      This method determines how long to wait before making the next retry attempt. Different implementations may use different strategies such as constant delay, linear backoff, or exponential backoff.

      Parameters:
      attempt - the current retry attempt number, starting from 1 for the first retry
      Returns:
      the duration to sleep before this retry attempt, must not be null or negative
      Throws:
      IllegalArgumentException - if attempt is less than 1 or greater than maxAttempts()
    • allowRetry

      boolean allowRetry(int attempt)
      Determines whether a retry should be allowed for the given attempt number.

      This method is invoked to check if another retry attempt should be made based on the current attempt number and the policy's configuration. Typically, returns false when the attempt number exceeds maxAttempts().

      Parameters:
      attempt - the current retry attempt number, starting from 1 for the first retry
      Returns:
      true if a retry is allowed for this attempt, false otherwise