Package at.aimon.session.web.metrics
Interface SessionMetrics
public interface SessionMetrics
Operational metric hooks for
WebAgentSessionManager (design §12 WS-06).
Implementations forward to a metrics backend (Micrometer, OpenTelemetry, Dropwizard, …). The interface itself is
deliberately framework-agnostic — every method has a no-op default so callers can implement only the metrics they
actually export, and so the manager can wire NOOP as the safe default when the application has not asked
for instrumentation.
Callback contract:
- Hooks are invoked on whichever thread emits the corresponding event (turn executor, scheduler, signal-bus dispatcher, …) — implementations must not block and must be thread-safe.
- Hooks must never throw — the manager wraps each invocation defensively so a metrics outage cannot break the session lifecycle, but well-behaved adapters should still swallow their own exceptions.
- Latency-bearing hooks receive a non-null
Duration. Reason-bearing hooks receive a non-null enum.
The set of hooks mirrors the four §12 acceptance bullets: lock acquire latency, cache hit-rate, evict frequency, and lease-extend failures. Submit-outcome and holder-loss hooks are added because they answer the same operational questions ("are nodes piling up in the inbox?", "did we trip a recovery in production?") with the same backend cost.
-
Nested Class Summary
Nested ClassesModifier and TypeInterfaceDescriptionstatic enumWhy the local session cache dropped an entry. -
Field Summary
Fields -
Method Summary
Modifier and TypeMethodDescriptiondefault voidCalled when the local session cache drops an entry (regardless of cause).default voidCalled whenLocalSessionCache.ensureOpenfound an existing entry.default voidCalled whenLocalSessionCache.ensureOpenopened a fresh session.default voidCalled by the holder-loss sweeper after winning thecompareAndResetCAS for a stale IN_FLIGHT entry — i.e. exactly once per recovered conversation, on the recovering node.default voidCalled once per turn whenConversationLock.extendreturns false (lease lost).default voidCalled on every successfulConversationLock.extendfrom theLeaseRenewer.default voidonLockAcquireRejected(Duration latency) Called whenConversationLock.tryAcquire()returned empty (lock held elsewhere).default voidonLockAcquireSucceeded(Duration latency) Called whenConversationLock.tryAcquire()returned a handle.default voidCalled once per submit, after the manager has classified the request.
-
Field Details
-
NOOP
No-op metrics. Wire this in the manager when no metrics backend is configured — keeping the call sites uniform avoids null-checks in hot paths.
-
-
Method Details
-
onLockAcquireSucceeded
Called whenConversationLock.tryAcquire()returned a handle.- Parameters:
latency- wall-clock duration of thetryAcquirecall (never null)
-
onLockAcquireRejected
Called whenConversationLock.tryAcquire()returned empty (lock held elsewhere). The submit is then forwarded to the inbox.- Parameters:
latency- wall-clock duration of thetryAcquirecall (never null)
-
onCacheHit
default void onCacheHit()Called whenLocalSessionCache.ensureOpenfound an existing entry. -
onCacheMiss
default void onCacheMiss()Called whenLocalSessionCache.ensureOpenopened a fresh session. -
onCacheEviction
Called when the local session cache drops an entry (regardless of cause).- Parameters:
reason- the eviction classification (never null)
-
onLeaseExtendSucceeded
default void onLeaseExtendSucceeded()Called on every successfulConversationLock.extendfrom theLeaseRenewer. -
onLeaseExtendFailed
default void onLeaseExtendFailed()Called once per turn whenConversationLock.extendreturns false (lease lost). -
onSubmitOutcome
Called once per submit, after the manager has classified the request.- Parameters:
kind- the submit outcome kind (never null)
-
onHolderLossRecovered
default void onHolderLossRecovered()Called by the holder-loss sweeper after winning thecompareAndResetCAS for a stale IN_FLIGHT entry — i.e. exactly once per recovered conversation, on the recovering node.
-