no.ssb.sagalog.SagaLog Maven / Gradle / Ivy
package no.ssb.sagalog;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.CompletableFuture;
import java.util.stream.Collectors;
import java.util.stream.Stream;
public interface SagaLog {
CompletableFuture write(SagaLogEntryBuilder builder);
CompletableFuture truncate(SagaLogEntryId id);
CompletableFuture truncate();
Stream readIncompleteSagas();
Stream readEntries(String executionId);
String toString(SagaLogEntryId id);
SagaLogEntryId fromString(String id);
byte[] toBytes(SagaLogEntryId id);
SagaLogEntryId fromBytes(byte[] idBytes);
default SagaLogEntryBuilder builder() {
return new SagaLogEntryBuilder();
}
default Map> getSnapshotOfSagaLogEntriesByNodeId(String executionId) {
Map> recoverySagaLogEntriesBySagaNodeId = new LinkedHashMap<>();
List entries = readEntries(executionId).collect(Collectors.toList());
for (SagaLogEntry entry : entries) {
List nodeEntries = recoverySagaLogEntriesBySagaNodeId.get(entry.getNodeId());
if (nodeEntries == null) {
nodeEntries = new ArrayList<>(4);
recoverySagaLogEntriesBySagaNodeId.put(entry.getNodeId(), nodeEntries);
}
nodeEntries.add(entry);
}
return recoverySagaLogEntriesBySagaNodeId;
}
}