Enum Class BackoffStrategy

java.lang.Object
java.lang.Enum<BackoffStrategy>
cloud.opencode.base.cache.protection.BackoffStrategy
All Implemented Interfaces:
Serializable, Comparable<BackoffStrategy>, Constable

public enum BackoffStrategy extends Enum<BackoffStrategy>
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:
  • Enum Constant Details

    • FIXED

      public static final BackoffStrategy FIXED
      Fixed delay strategy | 固定延迟策略
    • LINEAR

      public static final BackoffStrategy LINEAR
      Linear delay strategy | 线性延迟策略
    • EXPONENTIAL

      public static final BackoffStrategy EXPONENTIAL
      Exponential delay strategy | 指数延迟策略
    • RANDOM

      public static final BackoffStrategy RANDOM
      Random delay strategy | 随机延迟策略
    • EXPONENTIAL_JITTER

      public static final BackoffStrategy EXPONENTIAL_JITTER
      Exponential delay with jitter strategy | 带抖动的指数延迟策略
  • Method Details

    • values

      public static BackoffStrategy[] 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

      public static BackoffStrategy valueOf(String name)
      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 name
      NullPointerException - 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 | 计算的延迟