Class EventBus

java.lang.Object
io.jmix.flowui.kit.event.EventBus
All Implemented Interfaces:
Serializable

public class EventBus extends Object implements Serializable
An event bus for any object.

Handles adding and removing event listeners, and firing events of type any type.

See Also:
  • Field Details

    • EVENTS_MAP_EXPECTED_MAX_SIZE

      protected static final int EVENTS_MAP_EXPECTED_MAX_SIZE
      See Also:
    • EMPTY_LISTENERS_ARRAY

      protected static final Consumer[] EMPTY_LISTENERS_ARRAY
    • events

      protected Map<Class<?>,Consumer[]> events
  • Constructor Details

    • EventBus

      public EventBus()
  • Method Details

    • addListener

      public <E extends EventObject> com.vaadin.flow.shared.Registration addListener(Class<E> eventType, Consumer<E> listener)
      Adds a listener for the given event type.
      Type Parameters:
      E - the event type
      Parameters:
      eventType - the event type for which to call the listener
      listener - the listener to call when the event occurs
      Returns:
      an object which can be used to remove the event listener
    • hasListener

      public <E extends EventObject> boolean hasListener(Class<E> eventType)
      Checks if there is at least one listener registered for the given event type.
      Type Parameters:
      E - the event type
      Parameters:
      eventType - the component event type
      Returns:
      true if at least one listener is registered, false otherwise
    • fireEvent

      public <E extends EventObject> void fireEvent(E event)
      Dispatches the event to all listeners registered for the event type.
      Parameters:
      event - the event to fire
    • removeListener

      public <E extends EventObject> void removeListener(Class<E> eventType, Consumer<E> listener)
      Removes the given listener for the given event type.
      Type Parameters:
      E - the event type
      Parameters:
      eventType - the component event type
      listener - the listener to remove
    • removeListener

      public <E extends EventObject> void removeListener(Class<E> eventType)
      Removes all listeners for the given event type.
      Type Parameters:
      E - the event type
      Parameters:
      eventType - the component event type
    • newListenersArray

      protected Consumer[] newListenersArray(int length)