Changed behaviour
This commit is contained in:
1 parent
ed4a626af3
commit
90c7abb5e8
2 files changed
+19
-2
No files matched your search
@@ -41,6 +41,14 @@ open class EventDispatcher(val eventStore: EventStore, private val lifecycleStor
|
|||||||
//val producedEvents: MutableList<Event> = mutableListOf()
|
//val producedEvents: MutableList<Event> = mutableListOf()
|
||||||
|
|
||||||
EventListenerRegistry.getListeners().forEach { listener ->
|
EventListenerRegistry.getListeners().forEach { listener ->
|
||||||
|
|
||||||
|
if (listener.allowDerivativeOnHistoricalEvent() &&
|
||||||
|
lifecycleStore.hasAccepted(referenceId, listener::class.java.simpleName)
|
||||||
|
) {
|
||||||
|
log.debug { "🔁 Listener ${listener::class.simpleName} already accepted for $referenceId → skipping further candidates" }
|
||||||
|
return@forEach
|
||||||
|
}
|
||||||
|
|
||||||
for (candidate in candidates) {
|
for (candidate in candidates) {
|
||||||
//log.debug("Evaluating candidate: ${candidate::class.simpleName} for listener ${listener::class.simpleName}")
|
//log.debug("Evaluating candidate: ${candidate::class.simpleName} for listener ${listener::class.simpleName}")
|
||||||
try {
|
try {
|
||||||
@@ -61,8 +69,8 @@ open class EventDispatcher(val eventStore: EventStore, private val lifecycleStor
|
|||||||
)
|
)
|
||||||
onDispatched(candidate, listener, DispatchResult.Accepted)
|
onDispatched(candidate, listener, DispatchResult.Accepted)
|
||||||
if (listener.allowDerivativeOnHistoricalEvent()) {
|
if (listener.allowDerivativeOnHistoricalEvent()) {
|
||||||
log.debug { "⏹️ Listener ${listener::class.simpleName} requested historical derivation → stopping dispatch early" }
|
log.debug { "⏹️ Listener ${listener::class.simpleName} requested historical derivation → adding listener to accepted list" }
|
||||||
return
|
break
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
lifecycleStore.add(
|
lifecycleStore.add(
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ interface ILifecycleStore {
|
|||||||
fun add(entry: LifecycleEntry)
|
fun add(entry: LifecycleEntry)
|
||||||
fun getAll(): List<LifecycleEntry>
|
fun getAll(): List<LifecycleEntry>
|
||||||
fun getForRef(ref: UUID): List<LifecycleEntry>
|
fun getForRef(ref: UUID): List<LifecycleEntry>
|
||||||
|
fun hasAccepted(ref: UUID, listenerName: String): Boolean
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -14,6 +15,14 @@ class LifecycleStore(private val capacity: Int = 50_000): ILifecycleStore {
|
|||||||
|
|
||||||
private val buffer = ArrayDeque<LifecycleEntry>(capacity)
|
private val buffer = ArrayDeque<LifecycleEntry>(capacity)
|
||||||
|
|
||||||
|
override fun hasAccepted(ref: UUID, listenerName: String): Boolean =
|
||||||
|
getForRef(ref).any {
|
||||||
|
it is ListenerResult &&
|
||||||
|
it.listener == listenerName &&
|
||||||
|
it.result == "Accepted"
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
@Synchronized
|
@Synchronized
|
||||||
override fun add(entry: LifecycleEntry) {
|
override fun add(entry: LifecycleEntry) {
|
||||||
if (buffer.size >= capacity) {
|
if (buffer.size >= capacity) {
|
||||||
|
|||||||
Reference in new issue
Block a user