Interface BackoffStrategy

All Known Implementing Classes:
BackoffStrategy.Exponential, BackoffStrategy.ExponentialWithJitter, BackoffStrategy.Fibonacci, BackoffStrategy.Fixed

BackoffStrategy - Defines delay calculation between retry attempts 退避策略 - 定义重试之间的延迟计算方式

Sealed interface with built-in implementations: Fixed, Exponential, ExponentialWithJitter, and Fibonacci.

密封接口,内置实现:固定延迟、指数退避、带抖动的指数退避、斐波那契退避。

Since:
JDK 25, opencode-base-core V1.0.3
Author:
Leon Soo www.LeonSoo.com
See Also:
  • Method Details

    • delay

      Duration delay(int attempt)
      Calculate the delay for the given attempt number. 计算给定重试次数的延迟。
      Parameters:
      attempt - attempt number, starting from 1 - 重试次数,从1开始
      Returns:
      the delay duration - 延迟时长
    • fixed

      static BackoffStrategy fixed(Duration delay)
      Create a fixed backoff strategy. 创建固定退避策略。
      Parameters:
      delay - the fixed delay between retries - 重试之间的固定延迟
      Returns:
      a fixed backoff strategy - 固定退避策略
    • exponential

      static BackoffStrategy exponential(Duration initialDelay, double multiplier)
      Create an exponential backoff strategy. 创建指数退避策略。
      Parameters:
      initialDelay - the initial delay - 初始延迟
      multiplier - the multiplier applied per attempt - 每次重试的乘数
      Returns:
      an exponential backoff strategy - 指数退避策略
    • exponentialWithJitter

      static BackoffStrategy exponentialWithJitter(Duration initialDelay, double multiplier, double jitterFactor)
      Create an exponential backoff strategy with jitter. 创建带抖动的指数退避策略。
      Parameters:
      initialDelay - the initial delay - 初始延迟
      multiplier - the multiplier applied per attempt - 每次重试的乘数
      jitterFactor - jitter factor in [0.0, 1.0] - 抖动因子,范围 [0.0, 1.0]
      Returns:
      an exponential-with-jitter backoff strategy - 带抖动的指数退避策略
    • fibonacci

      static BackoffStrategy fibonacci(Duration initialDelay)
      Create a Fibonacci backoff strategy. 创建斐波那契退避策略。
      Parameters:
      initialDelay - the initial delay (used as the first two Fibonacci values) - 初始延迟(作为前两个斐波那契值)
      Returns:
      a Fibonacci backoff strategy - 斐波那契退避策略