use of software.amazon.qldb.tutorial.model.streams.StreamRecord in project amazon-qldb-dmv-sample-java by aws-samples.
the class StreamJournal method streamRecordsToJournalBlocks.
private static List<JournalBlock> streamRecordsToJournalBlocks() {
Map<ByteBuffer, QldbRevision> revisionsByHash = new HashMap<>();
recordBuffer.stream().filter(record -> record.getRecordType().equals("REVISION_DETAILS")).forEach(record -> {
try {
Revision revision = ((RevisionDetailsRecord) record.getPayload()).getRevision();
byte[] revisionHash = revision.getHash();
revisionsByHash.put(wrap(revisionHash).asReadOnlyBuffer(), QldbRevision.fromIon((IonStruct) Constants.MAPPER.writeValueAsIonValue(revision)));
} catch (IOException e) {
throw new IllegalArgumentException("Could not map RevisionDetailsRecord to QldbRevision.", e);
}
});
return recordBuffer.stream().filter(streamRecord -> streamRecord.getRecordType().equals("BLOCK_SUMMARY")).map(streamRecord -> (BlockSummaryRecord) streamRecord.getPayload()).distinct().map(blockSummaryRecord -> blockSummaryRecordToJournalBlock(blockSummaryRecord, revisionsByHash)).sorted(Comparator.comparingLong(o -> o.getBlockAddress().getSequenceNo())).collect(Collectors.toList());
}
Aggregations