Class Event
java.lang.Object
cloud.opencode.base.event.Event
- Direct Known Subclasses:
DataEvent, DeadEvent, SignedEvent, WaitableEvent
Event Base Class
事件基类
Base class for all events in the event-driven architecture.
事件驱动架构中所有事件的基类。
Features | 主要功能:
- Unique event ID - 唯一事件ID
- Timestamp tracking - 时间戳跟踪
- Event source identification - 事件来源标识
- Cancellation support - 取消支持
Usage Examples | 使用示例:
// Define custom event
public class UserRegisteredEvent extends Event {
private final Long userId;
private final String email;
public UserRegisteredEvent(Long userId, String email) {
this.userId = userId;
this.email = email;
}
}
// Publish event
OpenEvent.getDefault().publish(new UserRegisteredEvent(1L, "user@example.com"));
Security | 安全性:
- Thread-safe: Yes (immutable properties, volatile cancelled) - 线程安全: 是
- Since:
- JDK 25, opencode-base-event V1.0.0
- Author:
- Leon Soo www.LeonSoo.com
- See Also:
-
Constructor Summary
Constructors -
Method Summary
-
Constructor Details
-
Event
protected Event()Create event with no source 创建无来源的事件 -
Event
Create event with source 创建带来源的事件- Parameters:
source- the event source identifier | 事件来源标识
-
-
Method Details
-
getId
-
getTimestamp
-
getSource
-
isCancelled
public boolean isCancelled()Check if event is cancelled 检查事件是否已取消- Returns:
- true if cancelled | 已取消返回true
-
cancel
public void cancel()Cancel the event to stop further processing 取消事件以停止后续处理 -
toString
-