Class Event

java.lang.Object
cloud.opencode.base.event.Event
Direct Known Subclasses:
DataEvent, DeadEvent, SignedEvent, WaitableEvent

public abstract class Event extends Object
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
    Modifier
    Constructor
    Description
    protected
    Create event with no source 创建无来源的事件
    protected
    Event(String source)
    Create event with source 创建带来源的事件
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Cancel the event to stop further processing 取消事件以停止后续处理
    Get unique event ID 获取唯一事件ID
    Get event source 获取事件来源
    Get event timestamp 获取事件时间戳
    boolean
    Check if event is cancelled 检查事件是否已取消
     

    Methods inherited from class Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
  • Constructor Details

    • Event

      protected Event()
      Create event with no source 创建无来源的事件
    • Event

      protected Event(String source)
      Create event with source 创建带来源的事件
      Parameters:
      source - the event source identifier | 事件来源标识
  • Method Details

    • getId

      public String getId()
      Get unique event ID 获取唯一事件ID
      Returns:
      the event ID | 事件ID
    • getTimestamp

      public Instant getTimestamp()
      Get event timestamp 获取事件时间戳
      Returns:
      the timestamp | 时间戳
    • getSource

      public String getSource()
      Get event source 获取事件来源
      Returns:
      the source or null | 来源或null
    • 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

      public String toString()
      Overrides:
      toString in class Object