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 | 发起线程IDtimestamp- 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:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enumLock Event Type Enumeration 锁事件类型枚举 -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic LockEventCreates an ACQUIRED event with wait time 创建带等待时间的ACQUIRED事件final booleanIndicates whether some other object is "equal to" this one.static LockEventCreates an ERROR event 创建ERROR事件final inthashCode()Returns a hash code value for this object.lockName()Returns the value of thelockNamerecord component.static LockEventCreates a RELEASED event 创建RELEASED事件longthreadId()Returns the value of thethreadIdrecord component.Returns the value of thethreadNamerecord component.static LockEventCreates a TIMEOUT event with wait time 创建带等待时间的TIMEOUT事件Returns the value of thetimestamprecord component.final StringtoString()Returns a string representation of this record class.type()Returns the value of thetyperecord component.waitTime()Returns the value of thewaitTimerecord component.
-
Constructor Details
-
LockEvent
public LockEvent(LockEvent.EventType type, String lockName, String threadName, long threadId, Instant timestamp, Duration waitTime) Compact constructor with validation and default values 紧凑构造器,包含验证和默认值- Throws:
IllegalArgumentException- if type is null | 如果type为null则抛出
-
-
Method Details
-
acquired
-
released
-
timeout
-
error
-
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. -
type
-
lockName
-
threadName
Returns the value of thethreadNamerecord component.- Returns:
- the value of the
threadNamerecord component
-
threadId
-
timestamp
-
waitTime
-