Class EventHub

java.lang.Object
technology.sola.engine.event.EventHub

@NullMarked public class EventHub extends Object
EventHub handles distribution of Events that are emitted to their respective EventListeners that have been added.
  • Constructor Details

    • EventHub

      public EventHub()
  • Method Details

    • add

      public <T extends Event> void add(Class<T> eventClass, EventListener<T> eventListener)
      Adds an EventListener that listens to events of desired type.
      Type Parameters:
      T - the type of the event
      Parameters:
      eventClass - the class of the type of events to listen to
      eventListener - the EventListener
    • remove

      public <T extends Event> void remove(Class<T> eventClass, EventListener<T> eventListener)
      Removes an EventListener that is listening to events of desired type.
      Type Parameters:
      T - the type of the event
      Parameters:
      eventClass - the class of the type of events to remove a listener from
      eventListener - the EventListener
    • off

      public <T extends Event> void off(Class<T> eventClass)
      Removes all EventListener for an event type.
      Type Parameters:
      T - the type of the event
      Parameters:
      eventClass - the class of the type of events to remove a listener from
    • emit

      public <T extends Event> void emit(T event)
      Sends an Event to all EventListeners that have been added for that event type.
      Type Parameters:
      T - the type of the event
      Parameters:
      event - the Event to send