类 RetryUtils.RetryPolicy
java.lang.Object
dev.langchain4j.internal.RetryUtils.RetryPolicy
- 封闭类:
- RetryUtils
This class encapsulates a retry policy.
-
嵌套类概要
嵌套类修饰符和类型类说明static final classThis class encapsulates a retry policy builder. -
构造器概要
构造器构造器说明RetryPolicy(int maxAttempts, int delayMillis, double jitterScale, double backoffExp) Construct a RetryPolicy. -
方法概要
修饰符和类型方法说明intjitterDelayMillis(int attempt) This method returns the jitter delay in milliseconds for a given attempt.doublerawDelayMs(int attempt) This method returns the raw delay in milliseconds for a given attempt.voidsleep(int attempt) This method sleeps for a given attempt.<T> TThis method attempts to execute a given action up to a specified number of times with a 1-second delay.<T> TThis method attempts to execute a given action up to a specified number of times with a 1-second delay.
-
构造器详细资料
-
RetryPolicy
public RetryPolicy(int maxAttempts, int delayMillis, double jitterScale, double backoffExp) Construct a RetryPolicy.- 参数:
maxAttempts- The maximum number of attempts.delayMillis- The delay in milliseconds.jitterScale- The jitter scale.backoffExp- The backoff exponent.
-
-
方法详细资料
-
rawDelayMs
public double rawDelayMs(int attempt) This method returns the raw delay in milliseconds for a given attempt.- 参数:
attempt- The attempt number.- 返回:
- The raw delay in milliseconds.
-
jitterDelayMillis
public int jitterDelayMillis(int attempt) This method returns the jitter delay in milliseconds for a given attempt.- 参数:
attempt- The attempt number.- 返回:
- The jitter delay in milliseconds.
-
sleep
public void sleep(int attempt) This method sleeps for a given attempt.- 参数:
attempt- The attempt number.
-
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.- 类型参数:
T- The type of the result of the action.- 参数:
action- The action to be executed.- 返回:
- The result of the action if it is successful.
- 抛出:
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.- 类型参数:
T- The type of the result of the action.- 参数:
action- The action to be executed.maxAttempts- The maximum number of attempts to execute the action.- 返回:
- The result of the action if it is successful.
- 抛出:
RuntimeException- if the action fails on all attempts.
-