Interface IEventBus


public interface IEventBus

Event bud interface for dispatching and subscribing to events.
This class allows subscribing to one or more event sources at once as well as create publisher groups to share a publication channel (and resources) among several publishers.

  • Method Details

    • getPublisher

      IEventPublisher getPublisher(String sourceID)
      Create a new publisher or return the existing one for the given source ID
      Parameters:
      sourceID - ID of event source to obtain a publisher for
      Returns:
      the publisher instance that can be used to publish events and directly register subscribers
    • getPublisher

      IEventPublisher getPublisher(String groupID, String sourceID)
      Get a publisher that shares a channel with all other sources in the same group.

      All events published in the same group are delivered sequentially and their order is guaranteed globally among all publishers in the group. Events are dispatched in the same order they were received, even if they come from different sources

      Parameters:
      groupID - ID of publisher group
      sourceID - ID of event source to obtain a publisher for
      Returns:
      the publisher instance that can be used to publish events and directly register subscribers
    • newSubscription

      ISubscriptionBuilder<Event> newSubscription()
      Create a new subscription for events handled by this event bus
      Returns:
      the builder for the new subscription
    • newSubscription

      <E extends Event> ISubscriptionBuilder<E> newSubscription(Class<E> eventClass)
      Create a new subscription for events of a specific class handled by this event bus
      Parameters:
      eventClass - The event class to filter on
      Returns:
      the builder for the new subscription
    • getNumberOfSubscribers

      int getNumberOfSubscribers(String sourceID)
      Check how many subscribers are listening to events from a given source.

      Note: For instance, this can be used to pause the source when nothing is expecting data from it

      Parameters:
      sourceID -
      Returns:
      number of subscribers
    • shutdown

      void shutdown()