Class WaitableEvent

java.lang.Object
cloud.opencode.base.event.Event
cloud.opencode.base.event.WaitableEvent

public class WaitableEvent extends Event
Waitable Event Wrapper 可等待事件包装器

Event wrapper that supports waiting for processing completion.

支持等待处理完成的事件包装器。

Features | 主要功能:

  • Wait for event processing - 等待事件处理完成
  • Timeout support - 超时支持
  • Wraps any event type - 包装任意事件类型

Usage Examples | 使用示例:

// Publish and wait
Event event = new UserRegisteredEvent(1L, "user@example.com");
OpenEvent.getDefault().publishAndWait(event, Duration.ofSeconds(5));

Security | 安全性:

  • Thread-safe: Yes - 线程安全: 是
Since:
JDK 25, opencode-base-event V1.0.0
Author:
Leon Soo www.LeonSoo.com
See Also:
  • Constructor Details

    • WaitableEvent

      public WaitableEvent(Event event, CountDownLatch latch)
      Create waitable event wrapper 创建可等待事件包装器
      Parameters:
      event - the event to wrap | 要包装的事件
      latch - the countdown latch | 倒计时锁存器
    • WaitableEvent

      public WaitableEvent(Event event)
      Create waitable event with new latch 创建带新锁存器的可等待事件
      Parameters:
      event - the event to wrap | 要包装的事件
  • Method Details

    • getWrappedEvent

      public Event getWrappedEvent()
      Get the wrapped event 获取被包装的事件
      Returns:
      the wrapped event | 被包装的事件
    • getLatch

      public CountDownLatch getLatch()
      Get the countdown latch 获取倒计时锁存器
      Returns:
      the latch | 锁存器
    • complete

      public void complete()
      Signal that event processing is complete 通知事件处理完成
    • await

      public boolean await(long timeout) throws InterruptedException
      Wait for event processing to complete 等待事件处理完成
      Parameters:
      timeout - timeout in milliseconds | 超时时间(毫秒)
      Returns:
      true if completed before timeout | 超时前完成返回true
      Throws:
      InterruptedException - if interrupted | 被中断时抛出
    • await

      public void await() throws InterruptedException
      Wait for event processing to complete indefinitely 无限期等待事件处理完成
      Throws:
      InterruptedException - if interrupted | 被中断时抛出
    • isCancelled

      public boolean isCancelled()
      Description copied from class: Event
      Check if event is cancelled 检查事件是否已取消
      Overrides:
      isCancelled in class Event
      Returns:
      true if cancelled | 已取消返回true
    • cancel

      public void cancel()
      Description copied from class: Event
      Cancel the event to stop further processing 取消事件以停止后续处理
      Overrides:
      cancel in class Event
    • toString

      public String toString()
      Overrides:
      toString in class Event