Class EventHub

java.lang.Object
io.jmix.core.common.event.EventHub

public class EventHub extends Object
EventHub class implementing the event listening model with concrete event classes.

This class is not thread-safe and should not be accessed concurrently from multiple threads without proper synchronization. * This class is not thread-safe and should not be accessed concurrently from multiple threads without proper synchronization.

  • 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

    • EventHub

      public EventHub()
  • Method Details

    • subscribe

      public <E> Subscription subscribe(Class<E> eventType, Consumer<E> listener)
      Add an event listener for event with type E.
      Type Parameters:
      E - type of event
      Parameters:
      eventType - event class
      listener - listener
      Returns:
      subscription object
    • unsubscribe

      public <E> boolean unsubscribe(Class<E> eventType, Consumer<E> listener)
      Remove an event listener for event with type E.
      Type Parameters:
      E - type of event
      Parameters:
      eventType - event class
      listener - listener
      Returns:
      true if listener has been removed
    • unsubscribe

      public void unsubscribe(Class<?> eventType)
      Remove all listeners with the specified event type.
      Parameters:
      eventType - event type
    • hasSubscriptions

      public <E> boolean hasSubscriptions(Class<E> eventType)
      Check if there are listeners for event type E.
      Type Parameters:
      E - type of event
      Parameters:
      eventType - event class
      Returns:
      true if there are one or more listeners for type E
    • publish

      public <E> void publish(Class<E> eventType, E event)
      Fire listeners for event type E.
      Type Parameters:
      E - type of event
      Parameters:
      eventType - event class
      event - event object
    • newListenersArray

      protected Consumer[] newListenersArray(int length)