Record Class DistributedLockConfig

java.lang.Object
java.lang.Record
cloud.opencode.base.lock.distributed.DistributedLockConfig
Record Components:
lockTimeout - timeout for acquiring the lock | 获取锁的超时
leaseTime - maximum time to hold the lock (TTL) | 持有锁的最大时间(TTL)
renewInterval - interval for auto-renewal | 自动续期间隔
autoRenew - whether to enable auto-renewal | 是否启用自动续期
retryCount - number of retries on failure | 失败重试次数
retryInterval - interval between retries | 重试间隔
enableFencing - whether to enable fencing token | 是否启用防护令牌

public record DistributedLockConfig(Duration lockTimeout, Duration leaseTime, Duration renewInterval, boolean autoRenew, int retryCount, Duration retryInterval, boolean enableFencing) extends Record
Distributed Lock Configuration Record 分布式锁配置记录

Immutable configuration for distributed lock behavior including timeout, lease time, auto-renewal, and fencing token support.

分布式锁行为的不可变配置,包括超时、租约时间、自动续期和防护令牌支持。

Features | 主要功能:

  • Lock acquisition timeout - 锁获取超时
  • Lease time (TTL) configuration - 租约时间(TTL)配置
  • Auto-renewal with configurable interval - 可配置间隔的自动续期
  • Retry mechanism - 重试机制
  • Fencing token support - 防护令牌支持

Usage Examples | 使用示例:

// Create custom configuration | 创建自定义配置
DistributedLockConfig config = DistributedLockConfig.builder()
    .lockTimeout(Duration.ofSeconds(30))
    .leaseTime(Duration.ofSeconds(30))
    .autoRenew(true)
    .renewInterval(Duration.ofSeconds(10))
    .retryCount(3)
    .enableFencing(true)
    .build();

// Use default configuration | 使用默认配置
DistributedLockConfig defaultConfig = DistributedLockConfig.defaults();

Security | 安全性:

  • Thread-safe: Yes (immutable) - 线程安全: 是(不可变)
Since:
JDK 25, opencode-base-lock V1.0.0
Author:
Leon Soo www.LeonSoo.com
See Also:
  • Constructor Details

    • DistributedLockConfig

      public DistributedLockConfig(Duration lockTimeout, Duration leaseTime, Duration renewInterval, boolean autoRenew, int retryCount, Duration retryInterval, boolean enableFencing)
      Creates an instance of a DistributedLockConfig record class.
      Parameters:
      lockTimeout - the value for the lockTimeout record component
      leaseTime - the value for the leaseTime record component
      renewInterval - the value for the renewInterval record component
      autoRenew - the value for the autoRenew record component
      retryCount - the value for the retryCount record component
      retryInterval - the value for the retryInterval record component
      enableFencing - the value for the enableFencing record component
  • Method Details

    • builder

      public static DistributedLockConfig.Builder builder()
      Creates a new configuration builder 创建新的配置构建器
      Returns:
      a new builder instance | 新的构建器实例
    • defaults

      public static DistributedLockConfig defaults()
      Gets the default configuration with reasonable defaults 获取具有合理默认值的默认配置
      Returns:
      default configuration | 默认配置
    • 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.
    • lockTimeout

      public Duration lockTimeout()
      Returns the value of the lockTimeout record component.
      Returns:
      the value of the lockTimeout record component
    • leaseTime

      public Duration leaseTime()
      Returns the value of the leaseTime record component.
      Returns:
      the value of the leaseTime record component
    • renewInterval

      public Duration renewInterval()
      Returns the value of the renewInterval record component.
      Returns:
      the value of the renewInterval record component
    • autoRenew

      public boolean autoRenew()
      Returns the value of the autoRenew record component.
      Returns:
      the value of the autoRenew record component
    • retryCount

      public int retryCount()
      Returns the value of the retryCount record component.
      Returns:
      the value of the retryCount record component
    • retryInterval

      public Duration retryInterval()
      Returns the value of the retryInterval record component.
      Returns:
      the value of the retryInterval record component
    • enableFencing

      public boolean enableFencing()
      Returns the value of the enableFencing record component.
      Returns:
      the value of the enableFencing record component