Package com.framed.core.local
Class LocalEventBus
java.lang.Object
com.framed.core.local.LocalEventBus
- All Implemented Interfaces:
EventBus
A local implementation of the
EventBus interface for message-based communication
between components within the same JVM.
This implementation supports configurable local dispatch semantics via DispatchMode
and allows an optional per-handler override of the dispatch mode at registration time.
Dispatch modes
DispatchMode.SEQUENTIAL: handlers run inline on the calling thread (blocking).DispatchMode.PARALLEL: handlers run concurrently on a shared thread pool.DispatchMode.PER_HANDLER: each handler runs on a dedicated single-thread executor (FIFO per handler, concurrent across handlers).
Per-handler override
Handlers can optionally specify their own mode using
register(String, Consumer, DispatchMode). If the mode is null,
the bus-wide default mode is used.
Note: This differs from the original "one executor per address" model. Ordering is now defined by the chosen dispatch mode (e.g., PER_HANDLER orders per handler, not per address).
-
Constructor Summary
ConstructorsConstructorDescriptionCreates a LocalEventBus withDispatchMode.PER_HANDLERas default.LocalEventBus(DispatchMode defaultDispatchMode) Creates a LocalEventBus using the given default dispatch mode. -
Method Summary
Modifier and TypeMethodDescriptionvoidPublishes a message to all handlers registered for the given address (broadcast semantics).voidRegisters a handler for the specified address using the bus default dispatch mode.voidregister(String address, Consumer<Object> handler, DispatchMode perHandlerMode) Registers a handler for the specified address with an optional per-handler dispatch mode override.voidSends a message to a single handler registered for the given address.voidshutdown()Shuts down the event bus and releases resources.
-
Constructor Details
-
LocalEventBus
Creates a LocalEventBus using the given default dispatch mode.- Parameters:
defaultDispatchMode- bus-wide default mode used if a handler does not specify an override
-
LocalEventBus
public LocalEventBus()Creates a LocalEventBus withDispatchMode.PER_HANDLERas default.
-
-
Method Details
-
register
Registers a handler for the specified address using the bus default dispatch mode. -
register
Registers a handler for the specified address with an optional per-handler dispatch mode override.If
perHandlerModeis non-null, it will be used for local dispatch of this handler.If
perHandlerModeis null, the bus-wide default mode is used. -
send
Sends a message to a single handler registered for the given address. The first handler in the list is selected for delivery (point-to-point semantics). -
publish
Publishes a message to all handlers registered for the given address (broadcast semantics). -
shutdown
public void shutdown()Shuts down the event bus and releases resources.Stops the shared parallel pool and all per-handler executors.
-
