use of lombok.NonNull in project pravega by pravega.
the class ContainerTableExtensionImpl method createSegment.
// endregion
// region TableStore Implementation
@Override
public CompletableFuture<Void> createSegment(@NonNull String segmentName, SegmentType segmentType, TableSegmentConfig config, Duration timeout) {
Exceptions.checkNotClosed(this.closed.get(), this);
// Ensure at least a TableSegment type.
segmentType = SegmentType.builder(segmentType).tableSegment().build();
val attributes = new HashMap<>(TableAttributes.DEFAULT_VALUES);
attributes.putAll(selectLayout(segmentName, segmentType).getNewSegmentAttributes(config));
val attributeUpdates = attributes.entrySet().stream().map(e -> new AttributeUpdate(e.getKey(), AttributeUpdateType.None, e.getValue())).collect(Collectors.toList());
logRequest("createSegment", segmentName, segmentType, config);
return this.segmentContainer.createStreamSegment(segmentName, segmentType, attributeUpdates, timeout);
}
use of lombok.NonNull in project pravega by pravega.
the class FixedKeyLengthTableSegmentLayout method put.
@Override
CompletableFuture<List<Long>> put(@NonNull DirectSegmentAccess segment, @NonNull List<TableEntry> entries, long tableSegmentOffset, TimeoutTimer timer) {
val segmentInfo = segment.getInfo();
ensureSegmentType(segmentInfo.getName(), segmentInfo.getType());
val segmentKeyLength = getSegmentKeyLength(segmentInfo);
ensureValidKeyLength(segmentInfo.getName(), segmentKeyLength);
val attributeUpdates = new AttributeUpdateCollection();
int batchOffset = 0;
val batchOffsets = new ArrayList<Integer>();
boolean isConditional = false;
for (val e : entries) {
val key = e.getKey();
Preconditions.checkArgument(key.getKey().getLength() == segmentKeyLength, "Entry Key Length for key `%s` incompatible with segment '%s' which requires key lengths of %s.", key, segmentInfo.getName(), segmentKeyLength);
attributeUpdates.add(createIndexUpdate(key, batchOffset));
isConditional |= key.hasVersion();
batchOffsets.add(batchOffset);
batchOffset += this.serializer.getUpdateLength(e);
}
logRequest("put", segmentInfo.getName(), isConditional, tableSegmentOffset, entries.size(), batchOffset);
if (batchOffset > this.config.getMaxBatchSize()) {
throw new UpdateBatchTooLargeException(batchOffset, this.config.getMaxBatchSize());
}
// Update total number of entries in Table (this includes updates to the same key).
attributeUpdates.add(new AttributeUpdate(TableAttributes.TOTAL_ENTRY_COUNT, AttributeUpdateType.Accumulate, entries.size()));
val serializedEntries = this.serializer.serializeUpdate(entries);
val append = tableSegmentOffset == TableSegmentLayout.NO_OFFSET ? segment.append(serializedEntries, attributeUpdates, timer.getRemaining()) : segment.append(serializedEntries, attributeUpdates, tableSegmentOffset, timer.getRemaining());
return handleConditionalUpdateException(append, segmentInfo).thenApply(segmentOffset -> {
this.compactionService.process(new CompactionCandidate(segment));
return batchOffsets.stream().map(offset -> offset + segmentOffset).collect(Collectors.toList());
});
}
use of lombok.NonNull in project pravega by pravega.
the class MetadataCleanerTests method testPersistAll.
/**
* Tests {@link MetadataCleaner#persistAll}.
*/
@Test
public void testPersistAll() throws Exception {
@Cleanup val context = new TestContext();
Assert.assertNotEquals(0, context.metadata.getActiveSegmentCount());
context.cleaner.persistAll(TIMEOUT).get(TIMEOUT.toMillis(), TimeUnit.MILLISECONDS);
val expectedSegments = context.metadata.getAllStreamSegmentIds().stream().map(context.metadata::getStreamSegmentMetadata).filter(Objects::nonNull).filter(sm -> !sm.isDeleted() && !sm.isMerged()).collect(Collectors.toList());
AssertExtensions.assertGreaterThan("Expected at least one eligible segment.", 0, expectedSegments.size());
assertEquals("Unexpected number of segments persisted.", expectedSegments.size(), context.metadataStore.getSegmentCount());
for (val sm : expectedSegments) {
val info = context.metadataStore.getSegmentInfo(sm.getName(), TIMEOUT).get(TIMEOUT.toMillis(), TimeUnit.MILLISECONDS);
Assert.assertNotNull("No persisted info for " + sm.getName(), info);
assertEquals("Unexpected length for " + sm.getName(), sm.getLength(), info.getLength());
}
}
use of lombok.NonNull in project open-kilda by telstra.
the class CommandBuilderImpl method makeMirrorConfig.
private MirrorConfig makeMirrorConfig(@NonNull FlowPath flowPath, @NonNull SwitchId mirrorSwitchId, int mirrorPort) {
MirrorConfig mirrorConfig = null;
FlowMirrorPoints flowMirrorPoints = flowPath.getFlowMirrorPointsSet().stream().filter(mirrorPoints -> mirrorSwitchId.equals(mirrorPoints.getMirrorSwitchId())).findFirst().orElse(null);
if (flowMirrorPoints != null) {
Set<MirrorConfigData> mirrorConfigDataSet = flowMirrorPoints.getMirrorPaths().stream().map(mirrorPath -> new MirrorConfigData(mirrorPath.getEgressPort(), mirrorPath.getEgressOuterVlan())).collect(Collectors.toSet());
if (!mirrorConfigDataSet.isEmpty()) {
mirrorConfig = MirrorConfig.builder().groupId(flowMirrorPoints.getMirrorGroupId()).flowPort(mirrorPort).mirrorConfigDataSet(mirrorConfigDataSet).build();
}
}
return mirrorConfig;
}
use of lombok.NonNull in project FastHub by k0shk0sh.
the class GroupedNotificationModel method construct.
@NonNull
public static List<GroupedNotificationModel> construct(@Nullable List<Notification> items) {
List<GroupedNotificationModel> models = new ArrayList<>();
if (items == null || items.isEmpty())
return models;
Map<Repo, List<Notification>> grouped = Stream.of(items).filter(value -> !value.isUnread()).collect(Collectors.groupingBy(Notification::getRepository, LinkedHashMap::new, Collectors.mapping(o -> o, toList())));
Stream.of(grouped).filter(repoListEntry -> repoListEntry.getValue() != null && !repoListEntry.getValue().isEmpty()).forEach(repoListEntry -> {
Repo repo = repoListEntry.getKey();
List<Notification> notifications = repoListEntry.getValue();
models.add(new GroupedNotificationModel(repo));
Stream.of(notifications).sorted((o1, o2) -> o2.getUpdatedAt().compareTo(o1.getUpdatedAt())).forEach(notification -> models.add(new GroupedNotificationModel(notification)));
});
return models;
}
Aggregations