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 class provides asynchronous message delivery using a dedicated
ExecutorService per address to ensure ordered message handling.
It supports both point-to-point messaging via send(String, Object)
and broadcasting via publish(String, Object).
Features:
- Thread-safe handler registration and message dispatching.
- Single-threaded executors per address for sequential message processing.
- Automatic cleanup of executors when all handlers for an address are removed.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidPublishes a message to all handlers registered for the given address.voidRegisters a handler for the specified address.voidSends a message to a single handler registered for the given address.voidshutdown()Stops all executors that were added to theexecutorsmap.
-
Constructor Details
-
LocalEventBus
public LocalEventBus()
-
-
Method Details
-
register
Registers a handler for the specified address. Creates a new single-threaded executor for the address if it does not exist. -
send
Sends a message to a single handler registered for the given address. The first handler in the list is selected for delivery. -
publish
Publishes a message to all handlers registered for the given address. -
shutdown
public void shutdown()Stops all executors that were added to theexecutorsmap.
-