Class SyncDispatcher

java.lang.Object
cloud.opencode.base.event.dispatcher.SyncDispatcher
All Implemented Interfaces:
EventDispatcher

public class SyncDispatcher extends Object implements EventDispatcher
Synchronous Event Dispatcher 同步事件分发器

Dispatches events synchronously in the calling thread.

在调用线程中同步分发事件。

Features | 主要功能:

  • Sequential execution - 顺序执行
  • Priority ordering - 优先级排序
  • Cancellation support - 取消支持

Usage Examples | 使用示例:

SyncDispatcher dispatcher = new SyncDispatcher();
dispatcher.dispatch(event, listeners);

Security | 安全性:

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

    Constructors
    Constructor
    Description
    Create sync dispatcher with default settings 使用默认设置创建同步分发器
    SyncDispatcher(boolean stopOnError)
    Create sync dispatcher with error handling configuration 使用错误处理配置创建同步分发器
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    dispatch(Event event, List<Consumer<Event>> listeners)
    Dispatch event to listeners synchronously 同步将事件分发到监听器
    boolean
    Check if this dispatcher supports async dispatching 检查此分发器是否支持异步分发

    Methods inherited from class Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

    Methods inherited from interface EventDispatcher

    shutdown
  • Constructor Details

    • SyncDispatcher

      public SyncDispatcher()
      Create sync dispatcher with default settings 使用默认设置创建同步分发器
    • SyncDispatcher

      public SyncDispatcher(boolean stopOnError)
      Create sync dispatcher with error handling configuration 使用错误处理配置创建同步分发器
      Parameters:
      stopOnError - if true, stop dispatching on first error | 如果为true,遇到第一个错误时停止分发
  • Method Details

    • dispatch

      public void dispatch(Event event, List<Consumer<Event>> listeners)
      Dispatch event to listeners synchronously 同步将事件分发到监听器

      Listeners are invoked in order. If an event is cancelled, subsequent listeners will not be invoked.

      监听器按顺序调用。如果事件被取消,后续监听器将不会被调用。

      Specified by:
      dispatch in interface EventDispatcher
      Parameters:
      event - the event to dispatch | 要分发的事件
      listeners - the list of listener handlers | 监听器处理器列表
      Throws:
      EventListenerException - if stopOnError is true and a listener throws | 如果stopOnError为true且监听器抛出异常
    • isAsync

      public boolean isAsync()
      Description copied from interface: EventDispatcher
      Check if this dispatcher supports async dispatching 检查此分发器是否支持异步分发
      Specified by:
      isAsync in interface EventDispatcher
      Returns:
      true if supports async | 如果支持异步返回true