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:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classDistributed Lock Configuration Builder 分布式锁配置构建器 -
Constructor Summary
ConstructorsConstructorDescriptionDistributedLockConfig(Duration lockTimeout, Duration leaseTime, Duration renewInterval, boolean autoRenew, int retryCount, Duration retryInterval, boolean enableFencing) Creates an instance of aDistributedLockConfigrecord class. -
Method Summary
Modifier and TypeMethodDescriptionbooleanReturns the value of theautoRenewrecord component.builder()Creates a new configuration builder 创建新的配置构建器static DistributedLockConfigdefaults()Gets the default configuration with reasonable defaults 获取具有合理默认值的默认配置booleanReturns the value of theenableFencingrecord component.final booleanIndicates whether some other object is "equal to" this one.final inthashCode()Returns a hash code value for this object.Returns the value of theleaseTimerecord component.Returns the value of thelockTimeoutrecord component.Returns the value of therenewIntervalrecord component.intReturns the value of theretryCountrecord component.Returns the value of theretryIntervalrecord component.final StringtoString()Returns a string representation of this record class.
-
Constructor Details
-
DistributedLockConfig
public DistributedLockConfig(Duration lockTimeout, Duration leaseTime, Duration renewInterval, boolean autoRenew, int retryCount, Duration retryInterval, boolean enableFencing) Creates an instance of aDistributedLockConfigrecord class.- Parameters:
lockTimeout- the value for thelockTimeoutrecord componentleaseTime- the value for theleaseTimerecord componentrenewInterval- the value for therenewIntervalrecord componentautoRenew- the value for theautoRenewrecord componentretryCount- the value for theretryCountrecord componentretryInterval- the value for theretryIntervalrecord componentenableFencing- the value for theenableFencingrecord component
-
-
Method Details
-
builder
Creates a new configuration builder 创建新的配置构建器- Returns:
- a new builder instance | 新的构建器实例
-
defaults
Gets the default configuration with reasonable defaults 获取具有合理默认值的默认配置- Returns:
- default configuration | 默认配置
-
toString
-
hashCode
-
equals
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 withObjects::equals(Object,Object); primitive components are compared with thecomparemethod from their corresponding wrapper classes. -
lockTimeout
Returns the value of thelockTimeoutrecord component.- Returns:
- the value of the
lockTimeoutrecord component
-
leaseTime
-
renewInterval
Returns the value of therenewIntervalrecord component.- Returns:
- the value of the
renewIntervalrecord component
-
autoRenew
-
retryCount
public int retryCount()Returns the value of theretryCountrecord component.- Returns:
- the value of the
retryCountrecord component
-
retryInterval
Returns the value of theretryIntervalrecord component.- Returns:
- the value of the
retryIntervalrecord component
-
enableFencing
public boolean enableFencing()Returns the value of theenableFencingrecord component.- Returns:
- the value of the
enableFencingrecord component
-