dajac commented on a change in pull request #9878:
URL: https://github.com/apache/kafka/pull/9878#discussion_r662847775
##########
File path:
clients/src/main/java/org/apache/kafka/common/internals/KafkaFutureImpl.java
##########
@@ -247,17 +138,32 @@ public boolean completeExceptionally(Throwable
newException) {
*/
@Override
public synchronized boolean cancel(boolean mayInterruptIfRunning) {
- return completeExceptionally(new CancellationException()) || exception
instanceof CancellationException;
+ return completableFuture.cancel(mayInterruptIfRunning);
+ }
+
+ // We need to deal with differences between KF's historic API and the API
of CF:
+ // CF#get() does not wrap CancellationException in ExecutionException (nor
does KF).
+ // CF#get() always wraps the _cause_ of a CompletionException in
ExecutionException (which KF does not).
+ //
+ // The semantics for KafkaFuture are that all exceptional completions of
the future (via #completeExceptionally() or exceptions from dependants)
+ // manifest as ExecutionException, as observed via both get() and getNow().
+ private void maybeRewrapAndThrow(Throwable cause) {
+ if (cause instanceof CancellationException) {
+ throw (CancellationException) cause;
+ }
}
/**
* Waits if necessary for this future to complete, and then returns its
result.
*/
@Override
public T get() throws InterruptedException, ExecutionException {
- SingleWaiter<T> waiter = new SingleWaiter<>();
- addWaiter(waiter);
- return waiter.await();
+ try {
+ return completableFuture.get();
+ } catch (ExecutionException e) {
+ maybeRewrapAndThrow(e.getCause());
+ throw e;
Review comment:
How about defining two helper methods, one for each cases?
* `private void maybeRewrapAndThrow(ExecutionException exception)`; and
* `private void maybeRewrapAndThrow(CompletionException exception)`
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]