sharedSubscribeLogic

private fun <T : Priority> sharedSubscribeLogic(methodCache: Cache<Class<out Event>, List<T>>, objectCache: Cache<Any, List<Class<out Event>>>, staticCache: Cache<Class<*>, List<Class<out Event>>>, eventClass: Class<out Event>, priority: Int, handlerEntry: T, any: Any? = null, type: Class<*>? = null)

Shared internal logic for registering both event handlers and exception handlers.

This method unifies the subscription flow for:

  • instance-based handlers (event or exception),

  • static handlers (event or exception),

  • any handler type implementing Priority.

Responsibilities

  1. Insert the handler into the appropriate list within methodCache, maintaining descending priority order (higher values run first).

  2. Record handler ownership in either:

    Only one of any or type should be provided for any call.

Usage

This function is used for:

  • normal event handler registration,

  • exception handler registration,

  • both instance and static subscriptions.

By abstracting the storage and bookkeeping rules, the event system avoids duplicated logic for events vs. exceptions.

Cache Invalidation

This function does not clear any resolved-handler caches. Callers are responsible for invalidating:

  • resolvedEventCache for event handlers, or

  • exceptionResolvedCache for exception handlers.

after completing all registration work.

Parameters

T

the handler entry type (e.g. EventHandlerEntry, ExceptionHandlerEntry).

methodCache

cache from event type to the mutable list of handlers associated with it.

objectCache

Caffeine cache tracking which event types an instance subscriber owns handlers for.

staticCache

cache tracking which event types a static subscriber class owns handlers for.

eventClass

the event type under which this handler should be registered.

priority

the handler’s priority; higher values are ordered earlier.

handlerEntry

the fully constructed handler entry.

any

instance subscriber, or null if registering a static handler.

type

static subscriber class, or null if registering an instance handler.