Interface EventBus

  • All Known Implementing Classes:
    LocalEventBus

    public interface EventBus
    Simple event bus concept that supports both synchronous and asynchronous subscribers that are registered and listening for events published

    Usage example:
    
      LocalEventBus localEventBus    = new LocalEventBus("TestBus", 3, (failingSubscriber, event, exception) -> log.error("...."));
    
       localEventBus.addAsyncSubscriber(orderEvent -> {
                 ...
             });
    
       localEventBus.addSyncSubscriber(orderEvent -> {
                   ...
             });
    
       localEventBus.publish(new OrderCreatedEvent());
     
    If you wish to colocate multiple related Event handling methods inside the same class and use it together with the LocalEventBus then you can extend the AnnotatedEventHandler class:
    {@code
     public class OrderEventsHandler extends AnnotatedEventHandler {
    See Also:
    LocalEventBus, AnnotatedEventHandler
    • 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)