Package dev.langchain4j.internal
Class RetryUtils.RetryPolicy.Builder
java.lang.Object
dev.langchain4j.internal.RetryUtils.RetryPolicy.Builder
- Enclosing class:
RetryUtils.RetryPolicy
This class encapsulates a retry policy builder.
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionbackoffExp
(double backoffExp) Sets the backoff exponent.build()
Builds a RetryPolicy.delayMillis
(int delayMillis) Sets the base delay in milliseconds.jitterScale
(double jitterScale) Sets the jitter scale.maxAttempts
(int maxAttempts) Sets the default maximum number of attempts.
-
Constructor Details
-
Builder
public Builder()Construct a RetryPolicy.Builder.
-
-
Method Details
-
maxAttempts
Sets the default maximum number of attempts.- Parameters:
maxAttempts
- The maximum number of attempts.- Returns:
this
-
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
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
Sets the backoff exponent.- Parameters:
backoffExp
- The backoff exponent.- Returns:
this
-
build
Builds a RetryPolicy.- Returns:
- A RetryPolicy.
-