Last active
July 8, 2022 02:34
-
-
Save bmaggi/8e42a16a02f18d3bff9b0b742a75bfe7 to your computer and use it in GitHub Desktop.
Transform KafakFuture <-> CompletableFuture
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// See https://issues.apache.org/jira/browse/KAFKA-6987 for ongoing work on KafkaFuture implementation of CompletableFuture | |
private <T> CompletableFuture<T> toCompletableFuture(final KafkaFuture<T> kafkaFuture) { | |
final CompletableFuture<T> wrappingFuture = new CompletableFuture<>(); | |
kafkaFuture.whenComplete((value, throwable) -> { | |
if (throwable != null) { | |
wrappingFuture.completeExceptionally(throwable); | |
} else { | |
wrappingFuture.complete(value); | |
} | |
}); | |
return wrappingFuture; | |
} | |
private <T> KafkaFuture<T> toKafkaFuture(final CompletableFuture<T> completableFuture) { | |
final KafkaFutureImpl<T> wrappingFuture = new KafkaFutureImpl<>(); | |
completableFuture.whenComplete((value, throwable) -> { | |
if (throwable != null) { | |
wrappingFuture.completeExceptionally(throwable); | |
} else { | |
wrappingFuture.complete(value); | |
} | |
}); | |
return wrappingFuture; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
call toCompletableFuture : org.apache.kafka.common.errors.TimeoutException: The AdminClient thread is not accepting new calls.