Record Class LockConfig
java.lang.Object
java.lang.Record
cloud.opencode.base.lock.LockConfig
- Record Components:
defaultTimeout- default timeout for lock acquisition | 锁获取的默认超时fair- whether the lock should be fair | 锁是否应该是公平的reentrant- whether the lock should be reentrant | 锁是否应该是可重入的spinCount- maximum spin count for spin locks | 自旋锁的最大自旋次数enableMetrics- whether to enable metrics collection | 是否启用指标收集lockType- the type of lock | 锁类型
public record LockConfig(Duration defaultTimeout, boolean fair, boolean reentrant, int spinCount, boolean enableMetrics, LockType lockType)
extends Record
Lock Configuration Record - Immutable Lock Settings
锁配置记录 - 不可变锁设置
Provides immutable configuration for lock behavior with builder pattern support.
提供带有构建器模式支持的不可变锁行为配置。
Features | 主要功能:
- Default timeout configuration - 默认超时配置
- Fair/unfair lock selection - 公平/非公平锁选择
- Reentrant option - 可重入选项
- Spin count for spin locks - 自旋锁的自旋次数
- Metrics collection toggle - 指标收集开关
Usage Examples | 使用示例:
// Create custom configuration | 创建自定义配置
LockConfig config = LockConfig.builder()
.timeout(Duration.ofSeconds(10))
.fair(true)
.enableMetrics(true)
.build();
// Use with lock | 与锁一起使用
Lock<Long> lock = OpenLock.lock(config);
// Use defaults | 使用默认值
LockConfig defaultConfig = LockConfig.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 classLock Configuration Builder 锁配置构建器 -
Constructor Summary
ConstructorsConstructorDescriptionLockConfig(Duration defaultTimeout, boolean fair, boolean reentrant, int spinCount, boolean enableMetrics, LockType lockType) Creates an instance of aLockConfigrecord class. -
Method Summary
Modifier and TypeMethodDescriptionstatic LockConfig.Builderbuilder()Creates a new configuration builder 创建新的配置构建器static LockConfigdefaults()Gets default configuration with reasonable defaults 获取具有合理默认值的默认配置Returns the value of thedefaultTimeoutrecord component.booleanReturns the value of theenableMetricsrecord component.final booleanIndicates whether some other object is "equal to" this one.booleanfair()Returns the value of thefairrecord component.final inthashCode()Returns a hash code value for this object.lockType()Returns the value of thelockTyperecord component.booleanReturns the value of thereentrantrecord component.intReturns the value of thespinCountrecord component.final StringtoString()Returns a string representation of this record class.
-
Constructor Details
-
LockConfig
public LockConfig(Duration defaultTimeout, boolean fair, boolean reentrant, int spinCount, boolean enableMetrics, LockType lockType) Creates an instance of aLockConfigrecord class.- Parameters:
defaultTimeout- the value for thedefaultTimeoutrecord componentfair- the value for thefairrecord componentreentrant- the value for thereentrantrecord componentspinCount- the value for thespinCountrecord componentenableMetrics- the value for theenableMetricsrecord componentlockType- the value for thelockTyperecord component
-
-
Method Details
-
builder
Creates a new configuration builder 创建新的配置构建器- Returns:
- a new builder instance | 新的构建器实例
-
defaults
Gets default configuration with reasonable defaults 获取具有合理默认值的默认配置Default values: timeout=30s, fair=false, reentrant=true, spinCount=1000, metrics=false, type=REENTRANT
默认值:超时=30秒,公平=false,可重入=true, 自旋次数=1000,指标=false,类型=REENTRANT
- Returns:
- default configuration (shared singleton) | 默认配置(共享单例)
-
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. -
defaultTimeout
Returns the value of thedefaultTimeoutrecord component.- Returns:
- the value of the
defaultTimeoutrecord component
-
fair
-
reentrant
-
spinCount
-
enableMetrics
public boolean enableMetrics()Returns the value of theenableMetricsrecord component.- Returns:
- the value of the
enableMetricsrecord component
-
lockType
-