Interface EventBusDriver


public interface EventBusDriver
A low-level complement to a EventBus.

In the driver, events need not implement Event strictly. This is done to enable compatibility with other event systems. Most users should refrain from using the driver and prefer the standard interface instead.
  • Method Details

    • fireEvent

      void fireEvent(Object event)
      Fires an event, with the normal restriction that the event implement Event relaxed.

      In all other details, this is equivalent to EventBus.fireEvent(Event), including with the requirement that the event NOT be a AsyncEvent
      Parameters:
      event - the event to fire
      Throws:
      IllegalArgumentException - if event is an AsyncEvent
    • registerListener

      <E> RegisteredListener registerListener(Class<E> eventClass, byte priority, Consumer<? super E> eventConsumer)
      Registers a listener, with the normal restriction that the event implement Event relaxed.

      In all other details, this is equivalent to EventBus.registerListener(Class, byte, EventConsumer)
      Type Parameters:
      E - the event type
      Parameters:
      eventClass - the event class
      priority - the priority at which the listener is placed
      eventConsumer - the event consumer
      Returns:
      a registered listener
      Throws:
      IllegalArgumentException - if the event class is an array, a primitive, or Object
    • getRegisteredListenerCount

      int getRegisteredListenerCount(Class<?> eventClass)
      Gets the amount of registered listeners which would be called if an instance of the specified event class is fired.

      This method is mainly designed for determining whether a concrete event would call any listeners. For example:
      
      // API
      public interface MyEvent extends Event {
          String details();
      }
      // Implementation
      record MyEventImpl(String details) implements MyEvent {
      }
      
      void runEventIfNecessary(EventBus eventBus, String details) {
          if (eventBus.getDriver().getRegisteredListenerCount(MyEventImpl.class) == 0) {
              return;
          }
          eventBus.fireEvent(new MyEventImpl(details));
      }
      
      
      Parameters:
      eventClass - the concrete event class, an instance of which would be fired
      Returns:
      the amount of listeners which would be called. Note that this value may change as listeners are concurrently registered and unregistered.
    • debugRegisteredListeners

      String debugRegisteredListeners(Class<?> eventClass)
      Generates brief debug report for an event class. May yield information about listeners registered for such event, cached listeners, etc.

      The driver is free to implement this method any which way. Note that some drivers may store registered listeners using different approaches.
      Parameters:
      eventClass - the event class
      Returns:
      a debug report
    • debugRegisteredListeners

      void debugRegisteredListeners(Class<?> eventClass, Appendable output) throws IOException
      Generates brief debug report for an event class. Version of debugRegisteredListeners(Class) which sends the output to an Appendable. See such method for more information.
      Parameters:
      eventClass - the event class
      output - the appendable output
      Throws:
      IOException - if output did
    • debugEntireDriverState

      void debugEntireDriverState(Appendable output) throws IOException
      Generates an extensive debug report for the entire driver
      Parameters:
      output - the appendable output
      Throws:
      IOException - if output did