DispatchInstrumentation

The seam through which tooling observes a Store without core depending on any tooling artifact.

Core emits neutral events here and holds no tracer, no timing and no event types of its own. Implementations live outside core, map these callbacks onto whatever they record, and are installed with Store.setDispatchInstrumentation. A store with nothing installed pays one null check per dispatch.

Two families of callbacks share the interface. The onDispatch* methods cover work inside the dispatch pipeline and are driven by the store itself. The onEvaluation* methods cover suspending work that happens outside the pipeline and still deserves a span, such as navigation guards and dynamic entry selectors, and are driven by whichever module performs that work after reading Store.activeDispatchInstrumentation.

Usage:

class LoggingInstrumentation : DispatchInstrumentation {

override suspend fun onDispatchStarted(
action: ModuleAction,
queueWaitMs: Long,
queueDepth: Long
): String {
println("dispatch ${action::class.simpleName} waited ${queueWaitMs}ms")
return action.toString()
}

override fun onDispatchCompleted(token: String, applied: Boolean, durationMs: Long) {
println("$token ${if (applied) "applied" else "blocked"} in ${durationMs}ms")
}

override fun onDispatchFailed(token: String, error: Throwable, durationMs: Long) {
println("$token failed: ${error.message}")
}

override suspend fun onDispatchDropped(action: ModuleAction, reason: DispatchDropReason) = Unit

override suspend fun onExternalControlChanged(enabled: Boolean) = Unit
}

store.setDispatchInstrumentation(LoggingInstrumentation())

See also

to install an implementation

to read the installed one

Properties

Link copied to clipboard
open val isActive: Boolean

Whether this instrumentation currently wants events.

Functions

Link copied to clipboard

Supplies a decorator for wrapping individual dispatch chain steps, or null to leave the chain untouched.

Link copied to clipboard
abstract fun onDispatchCompleted(token: String, applied: Boolean, durationMs: Long)

Called when a dispatch finishes, whether or not it changed state.

Link copied to clipboard
open suspend fun onDispatchDropped(action: ModuleAction)

Older form of onDispatchDropped that cannot say why the action was dropped.

open suspend fun onDispatchDropped(action: ModuleAction, reason: DispatchDropReason)

Called when an action is discarded without processing.

Link copied to clipboard
abstract fun onDispatchFailed(token: String, error: Throwable, durationMs: Long)

Called when a dispatch throws.

Link copied to clipboard
abstract suspend fun onDispatchStarted(action: ModuleAction, queueWaitMs: Long, queueDepth: Long): String

Called when the store begins processing an action.

Link copied to clipboard
open fun onEvaluationCompleted(token: String, result: String?, resultType: String, durationMs: Long)

Called when an evaluation returns normally.

Link copied to clipboard
open fun onEvaluationFailed(token: String, error: Throwable, durationMs: Long)

Called when an evaluation throws.

Link copied to clipboard
open suspend fun onEvaluationStarted(scope: String, name: String, params: Map<String, String>): String

Called when a suspending evaluation outside the dispatch pipeline begins.

Link copied to clipboard
abstract suspend fun onExternalControlChanged(enabled: Boolean)

Called when a remote publisher takes over authoring this store's state, or hands it back.