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

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

There is a newer version: 1.1.10
Show newest version
package org.enodeframework.eventing;

import java.util.Map;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ConcurrentHashMap;

public class BatchAggregateEventAppendResult {
    private final int expectedAggregateRootCount;
    public ConcurrentHashMap aggregateEventAppendResultDict = new ConcurrentHashMap<>();
    public CompletableFuture taskCompletionSource = new CompletableFuture<>();

    public BatchAggregateEventAppendResult(int expectedAggregateRootCount) {
        this.expectedAggregateRootCount = expectedAggregateRootCount;
    }

    public void addCompleteAggregate(String aggregateRootId, AggregateEventAppendResult result) {
        if (aggregateEventAppendResultDict.putIfAbsent(aggregateRootId, result) == null) {
            int completedAggregateRootCount = aggregateEventAppendResultDict.keySet().size();
            if (completedAggregateRootCount == expectedAggregateRootCount) {
                EventAppendResult eventAppendResult = new EventAppendResult();
                for (Map.Entry entry : aggregateEventAppendResultDict.entrySet()) {
                    if (entry.getValue().getEventAppendStatus() == EventAppendStatus.Success) {
                        eventAppendResult.addSuccessAggregateRootId(entry.getKey());
                    } else if (entry.getValue().getEventAppendStatus() == EventAppendStatus.DuplicateEvent) {
                        eventAppendResult.addDuplicateEventAggregateRootId(entry.getKey());
                    } else if (entry.getValue().getEventAppendStatus() == EventAppendStatus.DuplicateCommand) {
                        eventAppendResult.addDuplicateCommandIds(entry.getKey(), entry.getValue().getDuplicateCommandIds());
                    }
                }
                taskCompletionSource.complete(eventAppendResult);
            }
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy