Interface EventManager

All Known Implementing Classes:
QueueDrivenEventManager

public interface EventManager
Manages subscriptions to and delivery of events. Each event type is defined by its class. Each listener is subscribed to events of one type of event class. All event delivery will happen on-queue (see Session.queue()). Subscriptions and un-subscriptions may happen on or off-queue.
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Interface
    Description
    static interface 
    Handler that will be called in a listener throws any Throwable while receiving an event.
    static interface 
    Represents a subscription of a listener that has been subscribed to an event.
  • Method Summary

    Modifier and Type
    Method
    Description
    <E> void
    post(E event)
    Post an event to all subscribers of the given event type.
    <E> void
    post(Class<E> type, E event)
    Post an event object and specify the precise type of listeners to deliver to.
    subscribe(Class<E> eventType, Consumer<E> eventConsumer)
    Create a subscription for the given event type.
  • Method Details

    • post

      <E> void post(@Nonnull E event)
      Post an event to all subscribers of the given event type. Subscribers will receive notification on-queue. If the calling thread is already executing on-queue, then delivery will happen synchronously, otherwise, this call will return immediately and notification will happen asynchronously on the execution queue.
      Parameters:
      event - The event to post. The type of this object will determine which listeners are notified.
    • post

      <E> void post(@Nonnull Class<E> type, @Nonnull E event)
      Post an event object and specify the precise type of listeners to deliver to. Useful for when you are posting a subclass or implementation of the type being listened to
    • subscribe

      <E> EventManager.Subscription subscribe(@Nonnull Class<E> eventType, @Nonnull Consumer<E> eventConsumer)
      Create a subscription for the given event type. Events of this type will be delivered to the given consumer until the EventManager.Subscription.unsubscribe() method is called.
      Parameters:
      eventType - The type of event to subscribe to.
      eventConsumer - The listener which will be invoked with any events of the given type that are posted to this event manager. Consumer will always be invoked on the session's queue.
      Returns:
      A Subscription object that serves as an un-subscribe callback method.