Class EventBus
To subscribe to an event, a Java class must be non-static, implement Listener
, have a public method for each desired event
with the signature public void methodName(EventClass event)
where EventClass
is the class of the event to be
captured, have the @net.engio.mbassy.listener.Handler
annotation applied to each event handler method, and must call
register(Listener)
for each instance of the class that should receive events
The event bus will deliver each event to all subscribers of the matching event class, as well as subscribers of any event class in
the parent chain going back up to the Event
base class. For example: subscribing to JVMEvent
will receive all
events in the tv.phantombot.event.jvm
package, as it is the base event for the package
-
Method Summary
Modifier and TypeMethodDescriptionstatic EventBus
instance()
Singleton methodvoid
Performs a blocking publish of an event to the relevant subscribersvoid
Publishes an event to the relevant subscribers on a separate threadvoid
Registers an instance of a class implementingListener
to receive eventsvoid
unregister
(Listener listener) Deregisters an instance of a class implementingListener
to no longer receive events
-
Method Details
-
instance
Singleton method- Returns:
- An instance of eventbus
-
register
Registers an instance of a class implementingListener
to receive events- Parameters:
listener
- An instance to register to receive events
-
unregister
Deregisters an instance of a class implementingListener
to no longer receive events- Parameters:
listener
- An instance to deregister to no longer receive events
-
post
Performs a blocking publish of an event to the relevant subscribersThis method should only be used in extremely rare circumstances. Most publishes should be done using
postAsync(Event)
- Parameters:
event
- An event to publish
-
postAsync
Publishes an event to the relevant subscribers on a separate thread- Parameters:
event
- An event to publish
-