- All Known Implementing Classes:
EventBus
public interface IEventBus
EventBus API.
Register for events and post events.
-
Method Summary
Modifier and TypeMethodDescription<T extends Event>
voidaddListener(boolean receiveCanceled, Class<T> eventType, Consumer<T> consumer) Add a consumer listener receiving potentially canceled events.<T extends Event>
voidaddListener(boolean receiveCanceled, Consumer<T> consumer) Add a consumer listener receiving potentially canceled events.<T extends Event>
voidaddListener(Class<T> eventType, Consumer<T> consumer) Add a consumer listener not receiving canceled events.<T extends Event>
voidaddListener(Consumer<T> consumer) Add a consumer listener with defaultEventPriority.NORMALand not recieving canceled events.<T extends Event>
voidaddListener(EventPriority priority, boolean receiveCanceled, Class<T> eventType, Consumer<T> consumer) Add a consumer listener with the specifiedEventPriorityand potentially canceled events.<T extends Event>
voidaddListener(EventPriority priority, boolean receiveCanceled, Consumer<T> consumer) Add a consumer listener with the specifiedEventPriorityand potentially canceled events.<T extends Event>
voidaddListener(EventPriority priority, Class<T> eventType, Consumer<T> consumer) Add a consumer listener with the specifiedEventPriorityand not receiving canceled events.<T extends Event>
voidaddListener(EventPriority priority, Consumer<T> consumer) Add a consumer listener with the specifiedEventPriorityand not receiving canceled events.<T extends Event>
Tpost(EventPriority phase, T event) Submit the event for dispatch to listeners registered with a specificEventPriority.<T extends Event>
Tpost(T event) Submit the event for dispatch to appropriate listenersvoidRegister an instance object or a Class, and add listeners for allSubscribeEventannotated methods found there, or directly a Method annotated withSubscribeEvent.voidstart()Start this bus (if it was created shut down), making it able to post events to listeners.voidunregister(Object object) Unregister the supplied listener from this EventBus.
-
Method Details
-
register
Register an instance object or a Class, and add listeners for allSubscribeEventannotated methods found there, or directly a Method annotated withSubscribeEvent. Depending on what is passed as an argument, different listener creation behaviour is performed.- Object Instance
- Scanned for non-static methods annotated with
SubscribeEventand creates listeners for each method found. - Class Instance
- Scanned for static methods annotated with
SubscribeEventand creates listeners for each method found. - Method Instance
- Expects a static method annotated with
SubscribeEventwhich will be registered as a listener for the Event type it has as its sole parameter.
-
addListener
Add a consumer listener with defaultEventPriority.NORMALand not recieving canceled events.- Type Parameters:
T- TheEventsubclass to listen for- Parameters:
consumer- Callback to invoke when a matching event is received
-
addListener
Add a consumer listener not receiving canceled events. Use this method when one of the other methods fails to determine the concreteEventsubclass that is intended to be subscribed to. -
addListener
Add a consumer listener with the specifiedEventPriorityand not receiving canceled events.- Type Parameters:
T- TheEventsubclass to listen for- Parameters:
priority-EventPriorityfor this listenerconsumer- Callback to invoke when a matching event is received
-
addListener
<T extends Event> void addListener(EventPriority priority, Class<T> eventType, Consumer<T> consumer) Add a consumer listener with the specifiedEventPriorityand not receiving canceled events. Use this method when one of the other methods fails to determine the concreteEventsubclass that is intended to be subscribed to.- Type Parameters:
T- TheEventsubclass to listen for- Parameters:
priority-EventPriorityfor this listenereventType- The concreteEventsubclass to subscribe toconsumer- Callback to invoke when a matching event is received
-
addListener
<T extends Event> void addListener(EventPriority priority, boolean receiveCanceled, Consumer<T> consumer) Add a consumer listener with the specifiedEventPriorityand potentially canceled events.- Type Parameters:
T- TheEventsubclass to listen for- Parameters:
priority-EventPriorityfor this listenerreceiveCanceled- Indicate if this listener should receive events that have beenICancellableEventcanceledconsumer- Callback to invoke when a matching event is received
-
addListener
<T extends Event> void addListener(EventPriority priority, boolean receiveCanceled, Class<T> eventType, Consumer<T> consumer) Add a consumer listener with the specifiedEventPriorityand potentially canceled events. Use this method when one of the other methods fails to determine the concreteEventsubclass that is intended to be subscribed to.- Type Parameters:
T- TheEventsubclass to listen for- Parameters:
priority-EventPriorityfor this listenerreceiveCanceled- Indicate if this listener should receive events that have beenICancellableEventcanceledeventType- The concreteEventsubclass to subscribe toconsumer- Callback to invoke when a matching event is received
-
addListener
Add a consumer listener receiving potentially canceled events.- Type Parameters:
T- TheEventsubclass to listen for- Parameters:
receiveCanceled- Indicate if this listener should receive events that have beenICancellableEventcanceledconsumer- Callback to invoke when a matching event is received
-
addListener
<T extends Event> void addListener(boolean receiveCanceled, Class<T> eventType, Consumer<T> consumer) Add a consumer listener receiving potentially canceled events. Use this method when one of the other methods fails to determine the concreteEventsubclass that is intended to be subscribed to.- Type Parameters:
T- TheEventsubclass to listen for- Parameters:
receiveCanceled- Indicate if this listener should receive events that have beenICancellableEventcanceledeventType- The concreteEventsubclass to subscribe toconsumer- Callback to invoke when a matching event is received
-
unregister
Unregister the supplied listener from this EventBus. Removes all listeners from events. NOTE: Consumers can be stored in a variable if unregistration is required for the Consumer. -
post
Submit the event for dispatch to appropriate listenersIf this bus was not started yet, the event is returned without being dispatched.
- Parameters:
event- The event to dispatch to listeners- Returns:
- the event that was passed in
-
post
Submit the event for dispatch to listeners registered with a specificEventPriority.If this bus was not started yet, the event is returned without being dispatched.
Manually posting events phase-by-phase through this method is less performant than dispatching to all phases through a
post(Event)call. Prefer that method when per-phase dispatching is not needed.- Parameters:
phase- The priority phase to post this event forevent- The event to dispatch to listeners- Returns:
- the event that was passed in
- Throws:
IllegalStateException- if the bus does not allow per-phase post- See Also:
-
start
void start()Start this bus (if it was created shut down), making it able to post events to listeners.
-