use of com.google.cloud.pubsublite.Offset in project beam by apache.
the class PerSubscriptionPartitionSdf method processElement.
@ProcessElement
public ProcessContinuation processElement(RestrictionTracker<OffsetByteRange, OffsetByteProgress> tracker, @Element SubscriptionPartition subscriptionPartition, OutputReceiver<SequencedMessage> receiver) throws Exception {
SubscriptionPartitionProcessor processor = processorFactory.newProcessor(subscriptionPartition, tracker, receiver);
ProcessContinuation result = processor.runFor(maxSleepTime);
processor.lastClaimed().ifPresent(lastClaimedOffset -> {
Offset commitOffset = Offset.of(lastClaimedOffset.value() + 1);
try {
committerFactory.apply(subscriptionPartition).commitOffset(commitOffset);
} catch (Exception e) {
throw ExtractStatus.toCanonical(e).underlying;
}
});
return result;
}
use of com.google.cloud.pubsublite.Offset in project beam by apache.
the class SubscriptionPartitionProcessorImpl method handleMessages.
private void handleMessages(List<SequencedMessage> messages) {
if (completionFuture.isDone()) {
return;
}
Offset lastOffset = Offset.of(Iterables.getLast(messages).getCursor().getOffset());
long byteSize = messages.stream().mapToLong(SequencedMessage::getSizeBytes).sum();
if (tracker.tryClaim(OffsetByteProgress.of(lastOffset, byteSize))) {
lastClaimedOffset = Optional.of(lastOffset);
messages.forEach(message -> receiver.outputWithTimestamp(message, new Instant(Timestamps.toMillis(message.getPublishTime()))));
try {
subscriber.allowFlow(FlowControlRequest.newBuilder().setAllowedBytes(byteSize).setAllowedMessages(messages.size()).build());
} catch (CheckedApiException e) {
completionFuture.setException(e);
}
} else {
completionFuture.set(null);
}
}
Aggregations