use of com.google.api.core.ApiFutureCallback in project java-pubsublite-kafka by googleapis.
the class SingleSubscriptionConsumerImpl method poll.
@Override
public ConsumerRecords<byte[], byte[]> poll(Duration duration) {
if (autocommit) {
ApiFuture<?> future = commitAll();
ApiFutures.addCallback(future, new ApiFutureCallback<Object>() {
@Override
public void onFailure(Throwable throwable) {
logger.atWarning().withCause(throwable).log("Failed to commit offsets.");
}
@Override
public void onSuccess(Object result) {
}
}, MoreExecutors.directExecutor());
}
Map<Partition, Queue<SequencedMessage>> partitionQueues = doPoll(duration);
Map<TopicPartition, List<ConsumerRecord<byte[], byte[]>>> records = new HashMap<>();
partitionQueues.forEach((partition, queue) -> {
if (queue.isEmpty())
return;
List<ConsumerRecord<byte[], byte[]>> partitionRecords = queue.stream().map(message -> RecordTransforms.fromMessage(message, topic, partition)).collect(Collectors.toList());
records.put(new TopicPartition(topic.toString(), (int) partition.value()), partitionRecords);
});
return new ConsumerRecords<>(records);
}
use of com.google.api.core.ApiFutureCallback in project java-bigtable by googleapis.
the class DynamicFlowControlCallable method futureCall.
@Override
public ApiFuture futureCall(Object request, ApiCallContext context) {
final Runnable flowControllerRunnable = new DynamicFlowControlRunnable();
ApiFuture future = innerCallable.futureCall(request, context);
ApiFutures.addCallback(future, new ApiFutureCallback() {
@Override
public void onFailure(Throwable t) {
// skipping recording the latencies for those.
if (t instanceof DeadlineExceededException) {
flowControllerRunnable.run();
}
}
@Override
public void onSuccess(Object result) {
flowControllerRunnable.run();
}
}, MoreExecutors.directExecutor());
return future;
}
Aggregations