Enum Class BackoffStrategy
- All Implemented Interfaces:
Serializable, Comparable<BackoffStrategy>, Constable
Backoff Strategy - Enumeration of retry backoff strategies
退避策略 - 重试退避策略枚举
Defines different strategies for calculating delay between retry attempts.
定义计算重试尝试之间延迟的不同策略。
Strategies | 策略:
- FIXED - Fixed interval between retries - 固定间隔重试
- LINEAR - Linear growth of delay - 延迟线性增长
- EXPONENTIAL - Exponential growth of delay - 延迟指数增长
- RANDOM - Random delay within bounds - 边界内随机延迟
- EXPONENTIAL_JITTER - Exponential with full jitter - 带完全抖动的指数退避
Features | 主要功能:
- Fixed interval backoff - 固定间隔退避
- Linear growth backoff - 线性增长退避
- Exponential backoff - 指数退避
- Exponential with jitter - 带抖动的指数退避
- Random delay backoff - 随机延迟退避
Usage Examples | 使用示例:
Duration delay = BackoffStrategy.EXPONENTIAL.calculateDelay(
3, Duration.ofMillis(100), Duration.ofSeconds(10), 2.0);
Security | 安全性:
- Thread-safe: Yes (immutable enum) - 线程安全: 是(不可变枚举)
- Null-safe: Yes - 空值安全: 是
- Since:
- JDK 25, opencode-base-cache V1.0.0
- Author:
- Leon Soo www.LeonSoo.com
- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from class Enum
Enum.EnumDesc<E> -
Enum Constant Summary
Enum ConstantsEnum ConstantDescriptionExponential delay strategy | 指数延迟策略Exponential delay with jitter strategy | 带抖动的指数延迟策略Fixed delay strategy | 固定延迟策略Linear delay strategy | 线性延迟策略Random delay strategy | 随机延迟策略 -
Method Summary
Modifier and TypeMethodDescriptionabstract DurationcalculateDelay(int attempt, Duration initialDelay, Duration maxDelay, double multiplier) Calculates the delay for the given attempt 计算给定尝试的延迟static BackoffStrategyReturns the enum constant of this class with the specified name.static BackoffStrategy[]values()Returns an array containing the constants of this enum class, in the order they are declared.
-
Enum Constant Details
-
FIXED
Fixed delay strategy | 固定延迟策略 -
LINEAR
Linear delay strategy | 线性延迟策略 -
EXPONENTIAL
Exponential delay strategy | 指数延迟策略 -
RANDOM
Random delay strategy | 随机延迟策略 -
EXPONENTIAL_JITTER
Exponential delay with jitter strategy | 带抖动的指数延迟策略
-
-
Method Details
-
values
Returns an array containing the constants of this enum class, in the order they are declared.- Returns:
- an array containing the constants of this enum class, in the order they are declared
-
valueOf
Returns the enum constant of this class with the specified name. The string must match exactly an identifier used to declare an enum constant in this class. (Extraneous whitespace characters are not permitted.)- Parameters:
name- the name of the enum constant to be returned.- Returns:
- the enum constant with the specified name
- Throws:
IllegalArgumentException- if this enum class has no constant with the specified nameNullPointerException- if the argument is null
-
calculateDelay
public abstract Duration calculateDelay(int attempt, Duration initialDelay, Duration maxDelay, double multiplier) Calculates the delay for the given attempt 计算给定尝试的延迟- Parameters:
attempt- the current attempt number (1-based) | 当前尝试次数(从1开始)initialDelay- the initial delay | 初始延迟maxDelay- the maximum delay | 最大延迟multiplier- the multiplier for exponential backoff | 指数退避的倍数- Returns:
- the calculated delay | 计算的延迟
-