Interface EventBusDriver
public interface EventBusDriver
A low-level complement to a
In the driver, events need not implement
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 Summary
Modifier and TypeMethodDescriptionvoiddebugEntireDriverState(Appendable output) Generates an extensive debug report for the entire driverdebugRegisteredListeners(Class<?> eventClass) Generates brief debug report for an event class.voiddebugRegisteredListeners(Class<?> eventClass, Appendable output) Generates brief debug report for an event class.voidFires an event, with the normal restriction that the event implementEventrelaxed.intgetRegisteredListenerCount(Class<?> eventClass) Gets the amount of registered listeners which would be called if an instance of the specified event class is fired.registerListener(Class<E> eventClass, byte priority, Consumer<? super E> eventConsumer) Registers a listener, with the normal restriction that the event implementEventrelaxed.
-
Method Details
-
fireEvent
Fires an event, with the normal restriction that the event implementEventrelaxed.
In all other details, this is equivalent toEventBus.fireEvent(Event), including with the requirement that the event NOT be aAsyncEvent- Parameters:
event- the event to fire- Throws:
IllegalArgumentException- ifeventis anAsyncEvent
-
registerListener
<E> RegisteredListener registerListener(Class<E> eventClass, byte priority, Consumer<? super E> eventConsumer) Registers a listener, with the normal restriction that the event implementEventrelaxed.
In all other details, this is equivalent toEventBus.registerListener(Class, byte, EventConsumer)- Type Parameters:
E- the event type- Parameters:
eventClass- the event classpriority- the priority at which the listener is placedeventConsumer- the event consumer- Returns:
- a registered listener
- Throws:
IllegalArgumentException- if the event class is an array, a primitive, orObject
-
getRegisteredListenerCount
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
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
Generates brief debug report for an event class. Version ofdebugRegisteredListeners(Class)which sends the output to anAppendable. See such method for more information.- Parameters:
eventClass- the event classoutput- the appendable output- Throws:
IOException- ifoutputdid
-
debugEntireDriverState
Generates an extensive debug report for the entire driver- Parameters:
output- the appendable output- Throws:
IOException- ifoutputdid
-