EventManager

internal class EventManager : Bus

Internal implementation of the Bus interface responsible for:

  • Discovering and registering event handler methods (@EventHandler),

  • Discovering and registering exception handler methods (@ExceptionHandler),

  • Managing instance subscribers through weak references,

  • Managing static subscribers registered by class,

  • Dispatching events with respect to handler priority, cancellation and polymorphic event-type matching,

  • Routing exceptions to matching exception handlers,

  • Caching resolved handler lists for efficient repeated dispatch.

This class is not exposed publicly; callers obtain a bus instance via Bus.invoke rather than referencing this implementation directly.

Constructors

Link copied to clipboard
constructor()

Types

Link copied to clipboard
object Companion

Holds utilities and shared logger for the event system.

Properties

Link copied to clipboard

Maps each event type to its registered handler list.

Link copied to clipboard

Maps each event type to its registered exception handlers.

Link copied to clipboard

Cache of fully resolved exception handler lists for each event class.

Link copied to clipboard
private val lock: Any

Synchronization lock for all subscription and cache mutation operations.

Link copied to clipboard
private val objectEventCache: Cache<Any, List<Class<out Event>>>

Tracks which event types each subscriber object handles.

Link copied to clipboard
private val objectExceptionCache: Cache<Any, List<Class<out Event>>>

Tracks which event types each subscriber object has exception handlers for.

Link copied to clipboard

Cache of fully resolved handler lists for each event class.

Link copied to clipboard
private val staticEventCache: Cache<Class<*>, List<Class<out Event>>>

Tracks which event types each static subscriber class handles.

Link copied to clipboard
private val staticExceptionCache: Cache<Class<*>, List<Class<out Event>>>

Tracks which event types each static subscriber class has exception handlers for.

Functions

Link copied to clipboard
private fun <T> collectHandlersFor(eventClass: Class<out Event>, methodCache: Cache<Class<out Event>, List<T>>): List<T>

Collects all handlers associated with the given event class, including those registered for its supertypes and interfaces that implement Event.

Link copied to clipboard
private fun dispatchExceptionHandlers(event: Event, throwable: Throwable)

Dispatches a throwable raised by an event handler to registered @ExceptionHandler methods.

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

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

Link copied to clipboard
open override fun subscribe(any: Any)

Registers an object as a subscriber.

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

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
open override fun unsubscribe(any: Any)

Unregisters an object from the bus.

Link copied to clipboard
open fun unsubscribeStatic(type: KClass<*>)

Unregisters all static handlers declared for the given Kotlin class.

open override fun unsubscribeStatic(type: Class<*>)

Unregisters all static handlers declared for the given class.

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

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