Interface EventBus
-
- All Known Implementing Classes:
LocalEventBus
public interface EventBusSimple event bus concept that supports both synchronous and asynchronous subscribers that are registered and listening for events published
Usage example:
If you wish to colocate multiple related Event handling methods inside the same class and use it together with theLocalEventBus localEventBus = new LocalEventBus("TestBus", 3, (failingSubscriber, event, exception) -> log.error("....")); localEventBus.addAsyncSubscriber(orderEvent -> { ... }); localEventBus.addSyncSubscriber(orderEvent -> { ... }); localEventBus.publish(new OrderCreatedEvent());LocalEventBusthen you can extend theAnnotatedEventHandlerclass:
{@code public class OrderEventsHandler extends AnnotatedEventHandler {- See Also:
LocalEventBus,AnnotatedEventHandler
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description EventBusaddAsyncSubscriber(EventHandler subscriber)Add an asynchronous subscriber/consumerEventBusaddSyncSubscriber(EventHandler subscriber)Add a synchronous subscriber/consumerbooleanhasAsyncSubscriber(EventHandler subscriber)booleanhasSyncSubscriber(EventHandler subscriber)EventBuspublish(Object event)Publish the event to all subscribers/consumer
First we call all asynchronous subscribers, after which we will call all synchronous subscribers on the calling thread (i.e.EventBusremoveAsyncSubscriber(EventHandler subscriber)Remove an asynchronous subscriber/consumerEventBusremoveSyncSubscriber(EventHandler subscriber)Remove a synchronous subscriber/consumer
-
-
-
Method Detail
-
publish
EventBus publish(Object event)
Publish the event to all subscribers/consumer
First we call all asynchronous subscribers, after which we will call all synchronous subscribers on the calling thread (i.e. on the same thread that the publish method is called on)- Parameters:
event- the event to publish- Returns:
- this bus instance
-
addAsyncSubscriber
EventBus addAsyncSubscriber(EventHandler subscriber)
Add an asynchronous subscriber/consumer- Parameters:
subscriber- the subscriber to add- Returns:
- this bus instance
-
removeAsyncSubscriber
EventBus removeAsyncSubscriber(EventHandler subscriber)
Remove an asynchronous subscriber/consumer- Parameters:
subscriber- the subscriber to remove- Returns:
- this bus instance
-
addSyncSubscriber
EventBus addSyncSubscriber(EventHandler subscriber)
Add a synchronous subscriber/consumer- Parameters:
subscriber- the subscriber to add- Returns:
- this bus instance
-
removeSyncSubscriber
EventBus removeSyncSubscriber(EventHandler subscriber)
Remove a synchronous subscriber/consumer- Parameters:
subscriber- the subscriber to remove- Returns:
- this bus instance
-
hasSyncSubscriber
boolean hasSyncSubscriber(EventHandler subscriber)
-
hasAsyncSubscriber
boolean hasAsyncSubscriber(EventHandler subscriber)
-
-