Record Class LockEvent

java.lang.Object
java.lang.Record
cloud.opencode.base.lock.event.LockEvent
Record Components:
type - the event type | 事件类型
lockName - the lock name | 锁名称
threadName - the originating thread name | 发起线程名称
threadId - the originating thread ID | 发起线程ID
timestamp - the event timestamp | 事件时间戳
waitTime - the wait duration (nullable, only for ACQUIRED/TIMEOUT events) | 等待时长(可为null,仅用于ACQUIRED/TIMEOUT事件)

public record LockEvent(LockEvent.EventType type, String lockName, String threadName, long threadId, Instant timestamp, Duration waitTime) extends Record
Lock Lifecycle Event Record 锁生命周期事件记录

An immutable record capturing lock lifecycle transitions such as acquisition, release, timeout, and error events. Each event includes the event type, lock name, originating thread information, and optional wait-time duration.

一个不可变记录,用于捕获锁生命周期转换,例如获取、释放、超时和错误事件。 每个事件包含事件类型、锁名称、发起线程信息以及可选的等待时间。

Features | 主要功能:

  • Immutable event record - 不可变事件记录
  • Factory methods for common events - 常见事件的工厂方法
  • Automatic thread and timestamp capture - 自动捕获线程和时间戳
  • Wait-time tracking for acquisition events - 获取事件的等待时间跟踪

Usage Examples | 使用示例:

// Create an acquired event with wait time | 创建带等待时间的获取事件
LockEvent acquired = LockEvent.acquired("myLock", Duration.ofMillis(50));

// Create a released event | 创建释放事件
LockEvent released = LockEvent.released("myLock");

// Create a timeout event | 创建超时事件
LockEvent timeout = LockEvent.timeout("myLock", Duration.ofSeconds(5));

// Create an error event | 创建错误事件
LockEvent error = LockEvent.error("myLock");

Security | 安全性:

  • Thread-safe: Yes (immutable record) - 线程安全: 是(不可变记录)
  • Null-safe: type must not be null - 空值安全: type不能为null
Since:
JDK 25, opencode-base-lock V1.0.3
Author:
Leon Soo www.LeonSoo.com
See Also:
  • Constructor Details

  • Method Details

    • acquired

      public static LockEvent acquired(String lockName, Duration waitTime)
      Creates an ACQUIRED event with wait time 创建带等待时间的ACQUIRED事件
      Parameters:
      lockName - the lock name | 锁名称
      waitTime - the time spent waiting to acquire the lock | 获取锁的等待时间
      Returns:
      an ACQUIRED lock event | ACQUIRED锁事件
    • released

      public static LockEvent released(String lockName)
      Creates a RELEASED event 创建RELEASED事件
      Parameters:
      lockName - the lock name | 锁名称
      Returns:
      a RELEASED lock event | RELEASED锁事件
    • timeout

      public static LockEvent timeout(String lockName, Duration waitTime)
      Creates a TIMEOUT event with wait time 创建带等待时间的TIMEOUT事件
      Parameters:
      lockName - the lock name | 锁名称
      waitTime - the time spent waiting before timeout | 超时前的等待时间
      Returns:
      a TIMEOUT lock event | TIMEOUT锁事件
    • error

      public static LockEvent error(String lockName)
      Creates an ERROR event 创建ERROR事件
      Parameters:
      lockName - the lock name | 锁名称
      Returns:
      an ERROR lock event | ERROR锁事件
    • 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.
    • type

      public LockEvent.EventType type()
      Returns the value of the type record component.
      Returns:
      the value of the type record component
    • lockName

      public String lockName()
      Returns the value of the lockName record component.
      Returns:
      the value of the lockName record component
    • threadName

      public String threadName()
      Returns the value of the threadName record component.
      Returns:
      the value of the threadName record component
    • threadId

      public long threadId()
      Returns the value of the threadId record component.
      Returns:
      the value of the threadId record component
    • timestamp

      public Instant timestamp()
      Returns the value of the timestamp record component.
      Returns:
      the value of the timestamp record component
    • waitTime

      public Duration waitTime()
      Returns the value of the waitTime record component.
      Returns:
      the value of the waitTime record component