Bus

interface Bus

Represents an event bus capable of registering subscribers and dispatching events.

Implementations are responsible for:

  • Scanning subscriber objects and classes for functions annotated with EventHandler and ExceptionHandler.

  • Routing posted Event instances to all matching event handlers.

  • Routing exceptions thrown by handlers to matching @ExceptionHandler methods.

  • Respecting event cancellation when applicable.

A default implementation is provided via the companion object's invoke operator. Library users normally obtain a bus instance by calling Bus() rather than referencing the internal implementation directly.

Inheritors

Types

Link copied to clipboard
object Companion

Factory for obtaining the default Bus implementation.

Functions

Link copied to clipboard
open fun post(event: Event)
abstract fun post(event: Event, cancelMode: CancelMode)

Posts an event to all matching event handlers registered on this Bus.

Link copied to clipboard
abstract fun subscribe(any: Any)

Registers an object as a subscriber.

Link copied to clipboard
abstract fun subscribeStatic(type: Class<*>)
open fun subscribeStatic(type: KClass<*>)

Registers a class containing static handler methods.

Link copied to clipboard
inline fun <T> Bus.subscribeStatic()

Registers all static handler methods declared on the reified type T.

Link copied to clipboard
abstract fun unsubscribe(any: Any)

Unregisters an object from the bus.

Link copied to clipboard
abstract fun unsubscribeStatic(type: Class<*>)

Unregisters all static handlers declared for the given class.

open fun unsubscribeStatic(type: KClass<*>)

Unregisters all static handlers declared for the given Kotlin class.

Link copied to clipboard
inline fun <T> Bus.unsubscribeStatic()

Unregisters all static handler methods declared on the reified type T.