Package dev.langchain4j.internal
Class RetryUtils.RetryPolicy.Builder
-
- All Implemented Interfaces:
public final class RetryUtils.RetryPolicy.Builder
This class encapsulates a retry policy builder.
-
-
Constructor Summary
Constructors Constructor Description RetryUtils.RetryPolicy.Builder()
Construct a RetryPolicy.Builder.
-
Method Summary
Modifier and Type Method Description RetryUtils.RetryPolicy.Builder
maxAttempts(int maxAttempts)
Sets the default maximum number of attempts. RetryUtils.RetryPolicy.Builder
delayMillis(int delayMillis)
Sets the base delay in milliseconds. RetryUtils.RetryPolicy.Builder
jitterScale(double jitterScale)
Sets the jitter scale. RetryUtils.RetryPolicy.Builder
backoffExp(double backoffExp)
Sets the backoff exponent. RetryUtils.RetryPolicy
build()
Builds a RetryPolicy. -
-
Method Detail
-
maxAttempts
RetryUtils.RetryPolicy.Builder maxAttempts(int maxAttempts)
Sets the default maximum number of attempts.
- Parameters:
maxAttempts
- The maximum number of attempts.- Returns:
this
-
delayMillis
RetryUtils.RetryPolicy.Builder delayMillis(int delayMillis)
Sets the base delay in milliseconds.
The delay is calculated as follows:
- Calculate the raw delay in milliseconds as
delayMillis * Math.pow(backoffExp, attempt - 1)
. - Calculate the jitter delay in milliseconds as
rawDelayMs + rand.nextInt((int) (rawDelayMs * jitterScale))
. - Sleep for the jitter delay in milliseconds.
- Parameters:
delayMillis
- The delay in milliseconds.- Returns:
this
- Calculate the raw delay in milliseconds as
-
jitterScale
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
RetryUtils.RetryPolicy.Builder backoffExp(double backoffExp)
Sets the backoff exponent.
- Parameters:
backoffExp
- The backoff exponent.- Returns:
this
-
build
RetryUtils.RetryPolicy build()
Builds a RetryPolicy.
- Returns:
A RetryPolicy.
-
-
-
-