Class WaitableEvent
java.lang.Object
cloud.opencode.base.event.Event
cloud.opencode.base.event.WaitableEvent
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 Summary
ConstructorsConstructorDescriptionWaitableEvent(Event event) Create waitable event with new latch 创建带新锁存器的可等待事件WaitableEvent(Event event, CountDownLatch latch) Create waitable event wrapper 创建可等待事件包装器 -
Method Summary
Modifier and TypeMethodDescriptionvoidawait()Wait for event processing to complete indefinitely 无限期等待事件处理完成booleanawait(long timeout) Wait for event processing to complete 等待事件处理完成voidcancel()Cancel the event to stop further processing 取消事件以停止后续处理voidcomplete()Signal that event processing is complete 通知事件处理完成getLatch()Get the countdown latch 获取倒计时锁存器Get the wrapped event 获取被包装的事件booleanCheck if event is cancelled 检查事件是否已取消toString()Methods inherited from class Event
getId, getSource, getTimestamp
-
Constructor Details
-
WaitableEvent
Create waitable event wrapper 创建可等待事件包装器- Parameters:
event- the event to wrap | 要包装的事件latch- the countdown latch | 倒计时锁存器
-
WaitableEvent
Create waitable event with new latch 创建带新锁存器的可等待事件- Parameters:
event- the event to wrap | 要包装的事件
-
-
Method Details
-
getWrappedEvent
-
getLatch
-
complete
public void complete()Signal that event processing is complete 通知事件处理完成 -
await
Wait for event processing to complete 等待事件处理完成- Parameters:
timeout- timeout in milliseconds | 超时时间(毫秒)- Returns:
- true if completed before timeout | 超时前完成返回true
- Throws:
InterruptedException- if interrupted | 被中断时抛出
-
await
Wait for event processing to complete indefinitely 无限期等待事件处理完成- Throws:
InterruptedException- if interrupted | 被中断时抛出
-
isCancelled
public boolean isCancelled()Description copied from class:EventCheck if event is cancelled 检查事件是否已取消- Overrides:
isCancelledin classEvent- Returns:
- true if cancelled | 已取消返回true
-
cancel
-
toString
-