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. 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.
      Parameters:
      target - Either a Class instance or an arbitrary object, for scanning and event listener creation
    • 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
    • addGenericListener

      @Deprecated(forRemoval=true) <T extends Event & IGenericEvent<? extends F>, F> void addGenericListener(Class<F> genericClassFilter, Consumer<T> consumer)
      Deprecated, for removal: This API element is subject to removal in a future version.
      Use non-generic events instead, or another system.
      Add a consumer listener for a GenericEvent subclass, filtered to only be called for the specified filter Class.
      Type Parameters:
      T - The GenericEvent subclass to listen for
      F - The Class to filter the GenericEvent for
      Parameters:
      genericClassFilter - A Class which the GenericEvent should be filtered for
      consumer - Callback to invoke when a matching event is received
    • addGenericListener

      @Deprecated(forRemoval=true) <T extends Event & IGenericEvent<? extends F>, F> void addGenericListener(Class<F> genericClassFilter, EventPriority priority, Consumer<T> consumer)
      Deprecated, for removal: This API element is subject to removal in a future version.
      Use non-generic events instead, or another system.
      Add a consumer listener with the specified EventPriority and not receiving canceled events, for a GenericEvent subclass, filtered to only be called for the specified filter Class.
      Type Parameters:
      T - The GenericEvent subclass to listen for
      F - The Class to filter the GenericEvent for
      Parameters:
      genericClassFilter - A Class which the GenericEvent should be filtered for
      priority - EventPriority for this listener
      consumer - Callback to invoke when a matching event is received
    • addGenericListener

      @Deprecated(forRemoval=true) <T extends Event & IGenericEvent<? extends F>, F> void addGenericListener(Class<F> genericClassFilter, EventPriority priority, boolean receiveCanceled, Consumer<T> consumer)
      Deprecated, for removal: This API element is subject to removal in a future version.
      Use non-generic events instead, or another system.
      Add a consumer listener with the specified EventPriority and potentially canceled events, for a GenericEvent subclass, filtered to only be called for the specified filter Class.
      Type Parameters:
      T - The GenericEvent subclass to listen for
      F - The Class to filter the GenericEvent for
      Parameters:
      genericClassFilter - A Class which the GenericEvent should be filtered for
      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
    • addGenericListener

      @Deprecated(forRemoval=true) <T extends Event & IGenericEvent<? extends F>, F> void addGenericListener(Class<F> genericClassFilter, EventPriority priority, boolean receiveCanceled, Class<T> eventType, Consumer<T> consumer)
      Deprecated, for removal: This API element is subject to removal in a future version.
      Use non-generic events instead, or another system.
      Add a consumer listener with the specified EventPriority and potentially canceled events, for a GenericEvent subclass, filtered to only be called for the specified filter Class. Use this method when one of the other methods fails to determine the concrete GenericEvent subclass that is intended to be subscribed to.
      Type Parameters:
      T - The GenericEvent subclass to listen for
      F - The Class to filter the GenericEvent for
      Parameters:
      genericClassFilter - A Class which the GenericEvent should be filtered for
      priority - EventPriority for this listener
      receiveCanceled - Indicate if this listener should receive events that have been ICancellableEvent canceled
      eventType - The concrete GenericEvent 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 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:
      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()