Record Class RetryConfig

java.lang.Object
java.lang.Record
cloud.opencode.base.core.retry.RetryConfig

public record RetryConfig(int maxAttempts, BackoffStrategy backoff, @Nullable Duration maxDelay, @Nullable Duration timeout, Predicate<Throwable> retryOn, Predicate<Throwable> abortOn, Predicate<Object> retryOnResult, BiConsumer<Integer, Throwable> onRetry, Consumer<Object> onSuccess, Consumer<Throwable> onExhausted) extends Record
RetryConfig - Immutable retry configuration record 重试配置 - 不可变的重试配置记录

Encapsulates all retry parameters in an immutable record, suitable for sharing across multiple Retry invocations. Sharing is safe when all callback fields (retryOn, abortOn, onRetry, onSuccess, onExhausted, retryOnResult) are stateless.

将所有重试参数封装在不可变记录中,适合在多个 Retry 调用之间共享。 当所有回调字段(retryOn、abortOn、onRetry、onSuccess、onExhausted、retryOnResult)无状态时,共享是安全的。

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

    • DEFAULT

      public static final RetryConfig DEFAULT
      Default configuration: 3 attempts, 100ms fixed delay. 默认配置:3次尝试,100毫秒固定延迟。
  • Constructor Details

    • RetryConfig

      public RetryConfig(int maxAttempts, BackoffStrategy backoff, @Nullable Duration maxDelay, @Nullable Duration timeout, Predicate<Throwable> retryOn, Predicate<Throwable> abortOn, Predicate<Object> retryOnResult, BiConsumer<Integer, Throwable> onRetry, Consumer<Object> onSuccess, Consumer<Throwable> onExhausted)
      Creates an instance of a RetryConfig record class.
      Parameters:
      maxAttempts - the value for the maxAttempts record component
      backoff - the value for the backoff record component
      maxDelay - the value for the maxDelay record component
      timeout - the value for the timeout record component
      retryOn - the value for the retryOn record component
      abortOn - the value for the abortOn record component
      retryOnResult - the value for the retryOnResult record component
      onRetry - the value for the onRetry record component
      onSuccess - the value for the onSuccess record component
      onExhausted - the value for the onExhausted record component
    • RetryConfig

      public RetryConfig(int maxAttempts, BackoffStrategy backoff, @Nullable Duration maxDelay, Predicate<Throwable> retryOn, Predicate<Throwable> abortOn, BiConsumer<Integer, Throwable> onRetry)
      Backward-compatible constructor without timeout, retryOnResult, onSuccess, onExhausted. 向后兼容的构造函数,不含 timeout、retryOnResult、onSuccess、onExhausted。
  • Method Details

    • toString

      public final String toString()
      Returns a string representation of this record class. The representation contains the name of the class, followed by the name and value of each of the record components.
      Specified by:
      toString in class Record
      Returns:
      a string representation of this object
    • hashCode

      public final int hashCode()
      Returns a hash code value for this object. The value is derived from the hash code of each of the record components.
      Specified by:
      hashCode in class Record
      Returns:
      a hash code value for this object
    • equals

      public final boolean equals(Object o)
      Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. Reference components are compared with Objects::equals(Object,Object); primitive components are compared with the compare method from their corresponding wrapper classes.
      Specified by:
      equals in class Record
      Parameters:
      o - the object with which to compare
      Returns:
      true if this object is the same as the o argument; false otherwise.
    • maxAttempts

      public int maxAttempts()
      Returns the value of the maxAttempts record component.
      Returns:
      the value of the maxAttempts record component
    • backoff

      public BackoffStrategy backoff()
      Returns the value of the backoff record component.
      Returns:
      the value of the backoff record component
    • maxDelay

      public @Nullable Duration maxDelay()
      Returns the value of the maxDelay record component.
      Returns:
      the value of the maxDelay record component
    • timeout

      public @Nullable Duration timeout()
      Returns the value of the timeout record component.
      Returns:
      the value of the timeout record component
    • retryOn

      public Predicate<Throwable> retryOn()
      Returns the value of the retryOn record component.
      Returns:
      the value of the retryOn record component
    • abortOn

      public Predicate<Throwable> abortOn()
      Returns the value of the abortOn record component.
      Returns:
      the value of the abortOn record component
    • retryOnResult

      public Predicate<Object> retryOnResult()
      Returns the value of the retryOnResult record component.
      Returns:
      the value of the retryOnResult record component
    • onRetry

      public BiConsumer<Integer, Throwable> onRetry()
      Returns the value of the onRetry record component.
      Returns:
      the value of the onRetry record component
    • onSuccess

      public Consumer<Object> onSuccess()
      Returns the value of the onSuccess record component.
      Returns:
      the value of the onSuccess record component
    • onExhausted

      public Consumer<Throwable> onExhausted()
      Returns the value of the onExhausted record component.
      Returns:
      the value of the onExhausted record component