Candidate adjustment + new logging

This commit is contained in:
Brage Skjønborg committed 2026-03-07 17:14:15 +01:00
1 parent 624991551b
commit b0f0cd9936
1 file changed
+11 -8
@@ -25,6 +25,7 @@ open class EventDispatcher(val eventStore: EventStore) {
EventListenerRegistry.getListeners().forEach { listener -> EventListenerRegistry.getListeners().forEach { listener ->
for (candidate in candidates) { for (candidate in candidates) {
log.debug("Evaluating candidate: ${candidate::class.simpleName} for listener ${listener::class.simpleName}")
try { try {
val result = listener.onEvent(candidate, effectiveHistory) val result = listener.onEvent(candidate, effectiveHistory)
@@ -35,26 +36,28 @@ open class EventDispatcher(val eventStore: EventStore) {
} }
} catch (e: SoftDispatchException.UnqualifiedEntryEventException) { } catch (e: SoftDispatchException.UnqualifiedEntryEventException) {
log.debug("Soft-dispatch skip (unqualified entry): ${e.message}") log.debug("Skipped: ${listener::class.simpleName} ignored ${candidate::class.simpleName} → ${e.message}")
} catch (e: SoftDispatchException.SkipListenerException) { } catch (e: SoftDispatchException.SkipListenerException) {
log.debug("Soft-dispatch skip: ${e.message}") log.debug("Skipped: ${listener::class.simpleName} skipped ${candidate::class.simpleName} → ${e.message}")
} catch (e: SoftDispatchException) { } catch (e: SoftDispatchException) {
log.warn( log.warn(
"Soft-dispatch in ${listener::class.simpleName} " + "Skipped: ${listener::class.simpleName} rejected ${candidate::class.simpleName} → ${e.message}"
"for event ${e.eventType?.simpleName}: ${e.message}"
) )
} }
} }
} }
} }
fun List<Event>.replayCandidates(): List<Event> { fun List<Event>.replayCandidates(): List<Event> {
val derivedFromIds = this.mapNotNull { it.metadata.derivedFromId }.flatten().toSet() val derivedFromIds = this
.filterNot { it is SignalEvent } // ignorer signaler som “forbrukere”
.mapNotNull { it.metadata.derivedFromId }
.flatten()
.toSet()
return this return this
.filterNot { it is SignalEvent } .filterNot { it is SignalEvent } // signaler er fortsatt ikke kandidater
.filter { it.eventId !in derivedFromIds } .filter { it.eventId !in derivedFromIds }
} }