- All Known Implementing Classes:
EventBus
public interface IEventBus
EventBus API.
Register for events and post events.
-
Method Summary
Modifier and TypeMethodDescription<T extends Event & IGenericEvent<? extends F>,F>
voidaddGenericListener(Class<F> genericClassFilter, Consumer<T> consumer) Deprecated, for removal: This API element is subject to removal in a future version.Use non-generic events instead, or another system.<T extends Event & IGenericEvent<? extends F>,F>
voidaddGenericListener(Class<F> genericClassFilter, EventPriority priority, boolean receiveCanceled, Class<T> eventType, Consumer<T> consumer) Deprecated, for removal: This API element is subject to removal in a future version.Use non-generic events instead, or another system.<T extends Event & IGenericEvent<? extends F>,F>
voidaddGenericListener(Class<F> genericClassFilter, EventPriority priority, boolean receiveCanceled, Consumer<T> consumer) Deprecated, for removal: This API element is subject to removal in a future version.Use non-generic events instead, or another system.<T extends Event & IGenericEvent<? extends F>,F>
voidaddGenericListener(Class<F> genericClassFilter, EventPriority priority, Consumer<T> consumer) Deprecated, for removal: This API element is subject to removal in a future version.Use non-generic events instead, or another system.<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.voidstart()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. 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.
- Parameters:
target- Either aClassinstance or an arbitrary object, for scanning and event listener creation
-
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
-
addGenericListener
@Deprecated(forRemoval=true) <T extends Event & IGenericEvent<? extends F>,F> void addGenericListener(Class<F> genericClassFilter, Consumer<T> consumer) Deprecated, for removal: This API element is subject to removal in a future version.Use non-generic events instead, or another system.Add a consumer listener for aGenericEventsubclass, filtered to only be called for the specified filterClass.- Type Parameters:
T- TheGenericEventsubclass to listen forF- TheClassto filter theGenericEventfor- Parameters:
genericClassFilter- AClasswhich theGenericEventshould be filtered forconsumer- Callback to invoke when a matching event is received
-
addGenericListener
@Deprecated(forRemoval=true) <T extends Event & IGenericEvent<? extends F>,F> void addGenericListener(Class<F> genericClassFilter, EventPriority priority, Consumer<T> consumer) Deprecated, for removal: This API element is subject to removal in a future version.Use non-generic events instead, or another system.Add a consumer listener with the specifiedEventPriorityand not receiving canceled events, for aGenericEventsubclass, filtered to only be called for the specified filterClass.- Type Parameters:
T- TheGenericEventsubclass to listen forF- TheClassto filter theGenericEventfor- Parameters:
genericClassFilter- AClasswhich theGenericEventshould be filtered forpriority-EventPriorityfor this listenerconsumer- Callback to invoke when a matching event is received
-
addGenericListener
@Deprecated(forRemoval=true) <T extends Event & IGenericEvent<? extends F>,F> void addGenericListener(Class<F> genericClassFilter, EventPriority priority, boolean receiveCanceled, Consumer<T> consumer) Deprecated, for removal: This API element is subject to removal in a future version.Use non-generic events instead, or another system.Add a consumer listener with the specifiedEventPriorityand potentially canceled events, for aGenericEventsubclass, filtered to only be called for the specified filterClass.- Type Parameters:
T- TheGenericEventsubclass to listen forF- TheClassto filter theGenericEventfor- Parameters:
genericClassFilter- AClasswhich theGenericEventshould be filtered forpriority-EventPriorityfor this listenerreceiveCanceled- Indicate if this listener should receive events that have beenICancellableEventcanceledconsumer- Callback to invoke when a matching event is received
-
addGenericListener
@Deprecated(forRemoval=true) <T extends Event & IGenericEvent<? extends F>,F> void addGenericListener(Class<F> genericClassFilter, EventPriority priority, boolean receiveCanceled, Class<T> eventType, Consumer<T> consumer) Deprecated, for removal: This API element is subject to removal in a future version.Use non-generic events instead, or another system.Add a consumer listener with the specifiedEventPriorityand potentially canceled events, for aGenericEventsubclass, filtered to only be called for the specified filterClass. Use this method when one of the other methods fails to determine the concreteGenericEventsubclass that is intended to be subscribed to.- Type Parameters:
T- TheGenericEventsubclass to listen forF- TheClassto filter theGenericEventfor- Parameters:
genericClassFilter- AClasswhich theGenericEventshould be filtered forpriority-EventPriorityfor this listenerreceiveCanceled- Indicate if this listener should receive events that have beenICancellableEventcanceledeventType- The concreteGenericEventsubclass 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:
event- 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()
-