Package dev.langchain4j.internal
Class RetryUtils
java.lang.Object
dev.langchain4j.internal.RetryUtils
Utility class for retrying actions.
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic final class
This class encapsulates a retry policy. -
Field Summary
Modifier and TypeFieldDescriptionstatic final RetryUtils.RetryPolicy
Default retry policy used bywithRetry(Callable)
. -
Method Summary
Modifier and TypeMethodDescriptionThis method returns a RetryPolicy.Builder.static <T> T
This method attempts to execute a given action up to a specified number of times with a 1-second delay.static <T> T
This method attempts to execute a given action up to a specified number of times with a 1-second delay.
-
Field Details
-
DEFAULT_RETRY_POLICY
Default retry policy used bywithRetry(Callable)
.
-
-
Method Details
-
retryPolicyBuilder
This method returns a RetryPolicy.Builder.- Returns:
- A RetryPolicy.Builder.
-
withRetry
This method attempts to execute a given action up to a specified number of times with a 1-second delay. If the action fails on all attempts, it throws a RuntimeException.- Type Parameters:
T
- The type of the result of the action.- Parameters:
action
- The action to be executed.maxAttempts
- The maximum number of attempts to execute the action.- Returns:
- The result of the action if it is successful.
- Throws:
RuntimeException
- if the action fails on all attempts.
-
withRetry
This method attempts to execute a given action up to a specified number of times with a 1-second delay. If the action fails on all attempts, it throws a RuntimeException.- Type Parameters:
T
- The type of the result of the action.- Parameters:
action
- The action to be executed.- Returns:
- The result of the action if it is successful.
- Throws:
RuntimeException
- if the action fails on all attempts.
-