Class RetryUtils.RetryPolicy.Builder

java.lang.Object
dev.langchain4j.internal.RetryUtils.RetryPolicy.Builder
Enclosing class:
RetryUtils.RetryPolicy

public static final class RetryUtils.RetryPolicy.Builder extends Object
This class encapsulates a retry policy builder.
  • Constructor Details

    • Builder

      public Builder()
      Construct a RetryPolicy.Builder.
  • Method Details

    • maxAttempts

      public RetryUtils.RetryPolicy.Builder maxAttempts(int maxAttempts)
      Sets the default maximum number of attempts.
      Parameters:
      maxAttempts - The maximum number of attempts.
      Returns:
      this
    • delayMillis

      public RetryUtils.RetryPolicy.Builder delayMillis(int delayMillis)
      Sets the base delay in milliseconds.

      The delay is calculated as follows:

      1. Calculate the raw delay in milliseconds as delayMillis * Math.pow(backoffExp, attempt - 1).
      2. Calculate the jitter delay in milliseconds as rawDelayMs + rand.nextInt((int) (rawDelayMs * jitterScale)).
      3. Sleep for the jitter delay in milliseconds.
      Parameters:
      delayMillis - The delay in milliseconds.
      Returns:
      this
    • jitterScale

      public RetryUtils.RetryPolicy.Builder jitterScale(double jitterScale)
      Sets the jitter scale.

      The jitter delay in milliseconds is calculated as rawDelayMs + rand.nextInt((int) (rawDelayMs * jitterScale)).

      Parameters:
      jitterScale - The jitter scale.
      Returns:
      this
    • backoffExp

      public RetryUtils.RetryPolicy.Builder backoffExp(double backoffExp)
      Sets the backoff exponent.
      Parameters:
      backoffExp - The backoff exponent.
      Returns:
      this
    • build

      public RetryUtils.RetryPolicy build()
      Builds a RetryPolicy.
      Returns:
      A RetryPolicy.