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:
  • Constructor Details

    • LockConfig

      public LockConfig(Duration defaultTimeout, boolean fair, boolean reentrant, int spinCount, boolean enableMetrics, LockType lockType)
      Creates an instance of a LockConfig record class.
      Parameters:
      defaultTimeout - the value for the defaultTimeout record component
      fair - the value for the fair record component
      reentrant - the value for the reentrant record component
      spinCount - the value for the spinCount record component
      enableMetrics - the value for the enableMetrics record component
      lockType - the value for the lockType record component
  • Method Details

    • builder

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

      public static LockConfig 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

      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.
    • defaultTimeout

      public Duration defaultTimeout()
      Returns the value of the defaultTimeout record component.
      Returns:
      the value of the defaultTimeout record component
    • fair

      public boolean fair()
      Returns the value of the fair record component.
      Returns:
      the value of the fair record component
    • reentrant

      public boolean reentrant()
      Returns the value of the reentrant record component.
      Returns:
      the value of the reentrant record component
    • spinCount

      public int spinCount()
      Returns the value of the spinCount record component.
      Returns:
      the value of the spinCount record component
    • enableMetrics

      public boolean enableMetrics()
      Returns the value of the enableMetrics record component.
      Returns:
      the value of the enableMetrics record component
    • lockType

      public LockType lockType()
      Returns the value of the lockType record component.
      Returns:
      the value of the lockType record component