Package com.ultikits.ultitools.events
Class EventBus
java.lang.Object
com.ultikits.ultitools.events.EventBus
Central event bus for inter-module communication.
Supports sync and async dispatch, annotation and programmatic subscriptions.
模块间通信的中央事件总线。 支持同步和异步分发、注解和编程式订阅。
- Since:
- 6.2.2
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final ExecutorServiceprivate final Map<Class<? extends ModuleEvent>, CopyOnWriteArrayList<HandlerEntry>> private static final Logger -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate List<HandlerEntry> collectHandlers(Class<? extends ModuleEvent> eventType) Collect all handlers matching the event type (including superclass handlers), sorted by priority.private voidinvokeHandler(HandlerEntry entry, ModuleEvent event) voidpublish(ModuleEvent event) Publish an event synchronously.voidpublishAsync(ModuleEvent event) Publish an event asynchronously.voidregister(Class<? extends ModuleEvent> eventType, EventPriority priority, boolean ignoreCancelled, String ownerModule, Method method, Object instance) Register an annotation-based handler.voidshutdown()Shutdown the async thread pool.<T extends ModuleEvent>
Subscriptionsubscribe(Class<T> eventType, EventPriority priority, boolean ignoreCancelled, String ownerModule, Consumer<T> consumer) Register a programmatic handler with full options.<T extends ModuleEvent>
SubscriptionRegister a programmatic handler.voidunregisterAll(String moduleName) Unregister all handlers owned by a module.
-
Field Details
-
LOGGER
-
handlers
-
asyncPool
-
-
Constructor Details
-
EventBus
public EventBus()
-
-
Method Details
-
register
public void register(Class<? extends ModuleEvent> eventType, EventPriority priority, boolean ignoreCancelled, String ownerModule, Method method, Object instance) Register an annotation-based handler. -
subscribe
Register a programmatic handler. Returns a Subscription for manual unsubscribe. -
subscribe
public <T extends ModuleEvent> Subscription subscribe(Class<T> eventType, EventPriority priority, boolean ignoreCancelled, String ownerModule, Consumer<T> consumer) Register a programmatic handler with full options. -
unregisterAll
Unregister all handlers owned by a module. -
publish
Publish an event synchronously. Handlers run on the calling thread in priority order. -
publishAsync
Publish an event asynchronously. Handlers run on a worker thread. Cancellable events are rejected — cancellation is only meaningful for sync dispatch. -
shutdown
public void shutdown()Shutdown the async thread pool. Called on plugin disable. -
collectHandlers
Collect all handlers matching the event type (including superclass handlers), sorted by priority. -
invokeHandler
-