Interface IEventBus

All Known Implementing Classes:
EventBus

public interface IEventBus
EventBus API.

Register for events and post events.

  • Method Details

    • register

      void register(Object target)
      Register an instance object or a Class, and add listeners for all SubscribeEvent annotated methods found there, or directly a Method annotated with SubscribeEvent. Depending on what is passed as an argument, different listener creation behaviour is performed.
      Object Instance
      Scanned for non-static methods annotated with SubscribeEvent and creates listeners for each method found.
      Class Instance
      Scanned for static methods annotated with SubscribeEvent and creates listeners for each method found.
      Method Instance
      Expects a static method annotated with SubscribeEvent which will be registered as a listener for the Event type it has as its sole parameter.
      Parameters:
      target - Either a Class instance or an arbitrary object, for scanning and event listener creation or a Method
    • addListener

      <T extends Event> void addListener(Consumer<T> consumer)
      Add a consumer listener with default EventPriority.NORMAL and not recieving canceled events.
      Type Parameters:
      T - The Event subclass to listen for
      Parameters:
      consumer - Callback to invoke when a matching event is received
    • addListener

      <T extends Event> void addListener(Class<T> eventType, Consumer<T> consumer)
      Add a consumer listener not receiving canceled events. Use this method when one of the other methods fails to determine the concrete Event subclass that is intended to be subscribed to.
      Type Parameters:
      T - The Event subclass to listen for
      Parameters:
      eventType - The concrete Event subclass to subscribe to
      consumer - Callback to invoke when a matching event is received
    • addListener

      <T extends Event> void addListener(EventPriority priority, Consumer<T> consumer)
      Add a consumer listener with the specified EventPriority and not receiving canceled events.
      Type Parameters:
      T - The Event subclass to listen for
      Parameters:
      priority - EventPriority for this listener
      consumer - Callback to invoke when a matching event is received
    • addListener

      <T extends Event> void addListener(EventPriority priority, Class<T> eventType, Consumer<T> consumer)
      Add a consumer listener with the specified EventPriority and not receiving canceled events. Use this method when one of the other methods fails to determine the concrete Event subclass that is intended to be subscribed to.
      Type Parameters:
      T - The Event subclass to listen for
      Parameters:
      priority - EventPriority for this listener
      eventType - The concrete Event subclass to subscribe to
      consumer - Callback to invoke when a matching event is received
    • addListener

      <T extends Event> void addListener(EventPriority priority, boolean receiveCanceled, Consumer<T> consumer)
      Add a consumer listener with the specified EventPriority and potentially canceled events.
      Type Parameters:
      T - The Event subclass to listen for
      Parameters:
      priority - EventPriority for this listener
      receiveCanceled - Indicate if this listener should receive events that have been ICancellableEvent canceled
      consumer - Callback to invoke when a matching event is received
    • addListener

      <T extends Event> void addListener(EventPriority priority, boolean receiveCanceled, Class<T> eventType, Consumer<T> consumer)
      Add a consumer listener with the specified EventPriority and potentially canceled events. Use this method when one of the other methods fails to determine the concrete Event subclass that is intended to be subscribed to.
      Type Parameters:
      T - The Event subclass to listen for
      Parameters:
      priority - EventPriority for this listener
      receiveCanceled - Indicate if this listener should receive events that have been ICancellableEvent canceled
      eventType - The concrete Event subclass to subscribe to
      consumer - Callback to invoke when a matching event is received
    • addListener

      <T extends Event> void addListener(boolean receiveCanceled, Consumer<T> consumer)
      Add a consumer listener receiving potentially canceled events.
      Type Parameters:
      T - The Event subclass to listen for
      Parameters:
      receiveCanceled - Indicate if this listener should receive events that have been ICancellableEvent canceled
      consumer - Callback to invoke when a matching event is received
    • addListener

      <T extends Event> void addListener(boolean receiveCanceled, Class<T> eventType, Consumer<T> consumer)
      Add a consumer listener receiving potentially canceled events. Use this method when one of the other methods fails to determine the concrete Event subclass that is intended to be subscribed to.
      Type Parameters:
      T - The Event subclass to listen for
      Parameters:
      receiveCanceled - Indicate if this listener should receive events that have been ICancellableEvent canceled
      eventType - The concrete Event subclass to subscribe to
      consumer - Callback to invoke when a matching event is received
    • unregister

      void unregister(Object object)
      Unregister the supplied listener from this EventBus. Removes all listeners from events. NOTE: Consumers can be stored in a variable if unregistration is required for the Consumer.
      Parameters:
      object - The object, Class, Method or Consumer to unsubscribe.
    • post

      <T extends Event> T post(T event)
      Submit the event for dispatch to appropriate listeners

      If this bus was not started yet, the event is returned without being dispatched.

      Parameters:
      event - The event to dispatch to listeners
      Returns:
      the event that was passed in
    • post

      <T extends Event> T post(EventPriority phase, T event)
      Submit the event for dispatch to listeners registered with a specific EventPriority.

      If this bus was not started yet, the event is returned without being dispatched.

      Manually posting events phase-by-phase through this method is less performant than dispatching to all phases through a post(Event) call. Prefer that method when per-phase dispatching is not needed.

      Parameters:
      phase - The priority phase to post this event for
      event - The event to dispatch to listeners
      Returns:
      the event that was passed in
      Throws:
      IllegalStateException - if the bus does not allow per-phase post
      See Also:
    • start

      void start()
      Start this bus (if it was created shut down), making it able to post events to listeners.