public final class EventBus
extends java.lang.Object
This class is based on Guava's EventBus
but priority is supported
and events are dispatched at the time of call, rather than being queued up.
This does allow dispatching during an in-progress dispatch.
Constructor and Description |
---|
EventBus() |
Modifier and Type | Method and Description |
---|---|
void |
post(java.lang.Object event)
Posts an event to all registered handlers.
|
void |
register(java.lang.Object object)
Registers all handler methods on
object to receive events. |
void |
subscribe(java.lang.Class<?> clazz,
EventHandler handler)
Registers the given handler for the given class to receive events.
|
void |
subscribeAll(com.google.common.collect.Multimap<java.lang.Class<?>,EventHandler> handlers)
Registers the given handler for the given class to receive events.
|
void |
unregister(java.lang.Object object)
Unregisters all handler methods on a registered
object . |
void |
unsubscribe(java.lang.Class<?> clazz,
EventHandler handler)
Unregisters the given handler for the given class.
|
void |
unsubscribeAll(com.google.common.collect.Multimap<java.lang.Class<?>,EventHandler> handlers)
Unregisters the given handlers.
|
public void subscribe(java.lang.Class<?> clazz, EventHandler handler)
clazz
- the event class to registerhandler
- the handler to registerpublic void subscribeAll(com.google.common.collect.Multimap<java.lang.Class<?>,EventHandler> handlers)
handlers
- a map of handlerspublic void unsubscribe(java.lang.Class<?> clazz, EventHandler handler)
clazz
- the classhandler
- the handlerpublic void unsubscribeAll(com.google.common.collect.Multimap<java.lang.Class<?>,EventHandler> handlers)
handlers
- a map of handlerspublic void register(java.lang.Object object)
object
to receive events.
Handler methods are selected and classified using this EventBus's
SubscriberFindingStrategy
; the default strategy is the
AnnotatedSubscriberFinder
.object
- object whose handler methods should be registered.public void unregister(java.lang.Object object)
object
.object
- object whose handler methods should be unregistered.java.lang.IllegalArgumentException
- if the object was not previously registered.public void post(java.lang.Object event)
event
- event to post.