Interface EventBus<T>

Type Parameters:
T - - root event type

public sealed interface EventBus<T>
An event bus which dispatches events to subscribed handlers.
  • Method Details

    • create

      static EventBus<Object> create()
    • create

      static <T> EventBus<T> create(Class<T> eventType)
    • create

      static <T> EventBus<T> create(Class<T> eventType, boolean hierarchicalDispatch)
    • create

      static <T> EventBus<T> create(Class<T> eventType, @Nullable @Nullable ClassHierarchyService hierarchyService)
    • publish

      default <E extends T> void publish(E event)
      Publishes an event.
      Type Parameters:
      E - - published event type
      Parameters:
      event - - event to publish
    • publishCancellable

      default <E extends T> boolean publishCancellable(E event)
      Publishes a cancellable event.
      Type Parameters:
      E - - published event type
      Parameters:
      event - - event to publish
      Returns:
      true if the event was cancelled
    • publish

      <E extends T> EventContext publish(E event, EventContext context)
    • eventType

      Class<T> eventType()
    • parent

      Optional<EventBus<? super T>> parent()
    • children

      Set<EventBus<? extends T>> children()
    • addChild

      <E extends T> EventBus<T> addChild(EventBus<E> child)
    • removeChild

      <E extends T> EventBus<T> removeChild(EventBus<E> child)
    • subscribeAnnotated

      EventBus<T> subscribeAnnotated(Object object)
      Subscribes all method annotated with Subscribe declared in the specified object. Passing a Class to this method will subscribe static methods, passing an instance will subscribe instance methods.
      Parameters:
      object - - an object instance or a class
      Returns:
      the event bus
    • unsubscribeAnnotated

      EventBus<T> unsubscribeAnnotated(Object object)
      Unsubscribes all methods annotated with Subscribe declared in the specified object. Passing a Class to this method will unsubscribe static methods, passing an instance will unsubscribe instance methods.
      Parameters:
      object - - an object instance or a class
      Returns:
      the event bus
    • subscribe

      default <E extends T> EventBus<T> subscribe(Class<E> eventType, Consumer<E> handler)
    • subscribe

      default <E extends T> EventBus<T> subscribe(Class<E> eventType, BiConsumer<E,EventContext> handler)
    • subscribe

      default <E extends T> EventBus<T> subscribe(Class<E> eventType, EventHandler<E> handler)
    • subscribe

      <E extends T> EventBus<T> subscribe(EventSubscriber<E> subscriber)
    • unsubscribe

      <E extends T> EventBus<T> unsubscribe(EventSubscriber<E> subscriber)