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
Constructors -
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.maxRetries(int maxRetries) Sets the default maximum number of retries.
-
Constructor Details
-
Builder
public Builder()Construct a RetryPolicy.Builder.
-
-
Method Details
-
maxRetries
Sets the default maximum number of retries.- Parameters:
maxRetries- The maximum number of retries. The action can be executed up tomaxRetries + 1times.- 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, retry). - 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
-