collectHandlersFor

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.

This utility performs a breadth-first traversal of the event type hierarchy:

  1. Starts at eventClass.

  2. For each visited class, looks up any handlers in methodCache keyed by that class and appends them to result.

  3. Enqueues the superclass (if it implements Event) and all interfaces that implement Event, continuing until the hierarchy has been exhausted.

The function is generic and can be used for:

as long as they are stored in a Cache<Class<out Event>, MutableList<T>> keyed by the event type for which they apply.

Typically, the returned list is then sorted by priority and cached in a resolved-handler cache to avoid recomputing the hierarchy traversal for subsequent events of the same runtime type.

Return

a combined list of handlers applicable to eventClass and all of its relevant supertypes and interfaces.

Parameters

T

the handler entry type, such as EventHandlerEntry or ExceptionHandlerEntry.

eventClass

the concrete event type being dispatched.

methodCache

the cache from event type to handler lists from which entries should be collected.