Event Bus
Central event dispatch interface.
Obtain an instance via the companion factory:
val bus = EventBus()From Java:
EventBus bus = EventBus.create();Subscribing
Pass any object whose methods are annotated with @Subscribe:
bus.subscribe(myListener)Pass a class (or Kotlin object) to register @JvmStatic / companion-object handlers:
bus.subscribeStatic(MyListener::class.java)Posting
bus.post(MyEvent())For Cancellable events the bus stops dispatching as soon as Cancellable.isCancelled is true.
Error handling
By default, exceptions thrown inside handlers are printed to stderr. Supply a custom handler at construction time via EventBus.invoke:
val bus = EventBus { e -> logger.error("Handler error", e) }Functions
Returns true if at least one handler is currently registered for the given event type or any of its supertypes.
Returns true if at least one wildcard handler is currently registered.
Registers all instance methods on subscriber annotated with @Subscribe.
Registers a java.util.function.Consumer as a handler for eventClass.
Kotlin-facing handler registration. Hidden from Java via @JvmSynthetic; Java callers use the java.util.function.Consumer overload below.
Java-facing wildcard handler registration. Kotlin callers use the subscribeAll extension which provides a default Priority.NORMAL value.
Registers a wildcard handler that fires for every event posted to this bus, regardless of type. Returns a Subscription token for removal.
Registers a wildcard handler with Priority.NORMAL default.
Registers all static methods on klass annotated with @Subscribe.
Returns a TypedEventBus view over this bus restricted to subtypes of E.
Removes all instance handlers previously registered for subscriber.
Removes all handlers from this bus; both instance, static, lambda-based, and wildcard. Useful for teardown in tests or on world unload.
Removes all static handlers previously registered for klass.