All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.enodeframework.eventing.BatchAggregateEventAppendResult.kt Maven / Gradle / Ivy

package org.enodeframework.eventing

import java.util.concurrent.CompletableFuture
import java.util.concurrent.ConcurrentHashMap

class BatchAggregateEventAppendResult(private val expectedAggregateRootCount: Int) {
    private var aggregateEventAppendResultDict = ConcurrentHashMap()
    var taskCompletionSource = CompletableFuture()
    fun addCompleteAggregate(aggregateRootId: String, result: AggregateEventAppendResult) {
        if (aggregateEventAppendResultDict.putIfAbsent(aggregateRootId, result) == null) {
            val completedAggregateRootCount = aggregateEventAppendResultDict.keys.size
            if (completedAggregateRootCount == expectedAggregateRootCount) {
                val eventAppendResult = EventAppendResult()
                for ((key, value) in aggregateEventAppendResultDict) {
                    if (value.eventAppendStatus === EventAppendStatus.Success) {
                        eventAppendResult.addSuccessAggregateRootId(key)
                    } else if (value.eventAppendStatus === EventAppendStatus.DuplicateEvent) {
                        eventAppendResult.addDuplicateEventAggregateRootId(key)
                    } else if (value.eventAppendStatus === EventAppendStatus.DuplicateCommand) {
                        eventAppendResult.addDuplicateCommandIds(key, value.duplicateCommandIds)
                    }
                }
                taskCompletionSource.complete(eventAppendResult)
            }
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy