Class KafkaFuture<T>
- All Implemented Interfaces:
- Future<T>
Relation to CompletionStage
 It is possible to obtain a CompletionStage from a
 KafkaFuture instance by calling toCompletionStage().
 If converting whenComplete(BiConsumer) or thenApply(BaseFunction) to
 CompletableFuture.whenComplete(java.util.function.BiConsumer) or
 CompletableFuture.thenApply(java.util.function.Function) be aware that the returned
 KafkaFuture will fail with an ExecutionException, whereas a CompletionStage fails
 with a CompletionException.
- 
Nested Class SummaryNested ClassesModifier and TypeClassDescriptionstatic interfaceA function which takes objects of type A and returns objects of type B.static interfaceA consumer of two different types of object.static classDeprecated.Since Kafka 3.0.
- 
Constructor SummaryConstructors
- 
Method SummaryModifier and TypeMethodDescriptionstatic KafkaFuture<Void>allOf(KafkaFuture<?>... futures) Returns a new KafkaFuture that is completed when all the given futures have completed.abstract booleancancel(boolean mayInterruptIfRunning) If not already completed, completes this future with a CancellationException.static <U> KafkaFuture<U>completedFuture(U value) Returns a new KafkaFuture that is already completed with the given value.abstract Tget()Waits if necessary for this future to complete, and then returns its result.abstract TWaits if necessary for at most the given time for this future to complete, and then returns its result, if available.abstract TReturns the result value (or throws any encountered exception) if completed, else returns the given valueIfAbsent.abstract booleanReturns true if this CompletableFuture was cancelled before it completed normally.abstract booleanReturns true if this CompletableFuture completed exceptionally, in any way.abstract booleanisDone()Returns true if completed in any fashion: normally, exceptionally, or via cancellation.abstract <R> KafkaFuture<R>thenApply(KafkaFuture.BaseFunction<T, R> function) Returns a new KafkaFuture that, when this future completes normally, is executed with this futures's result as the argument to the supplied function.abstract <R> KafkaFuture<R>thenApply(KafkaFuture.Function<T, R> function) PreferthenApply(BaseFunction)as this function is here for backwards compatibility reasons and might be deprecated/removed in a future release.abstract CompletionStage<T>Gets aCompletionStagewith the same completion properties as thisKafkaFuture.abstract KafkaFuture<T>whenComplete(KafkaFuture.BiConsumer<? super T, ? super Throwable> action) Returns a new KafkaFuture with the same result or exception as this future, that executes the given action when this future completes.
- 
Constructor Details- 
KafkaFuturepublic KafkaFuture()
 
- 
- 
Method Details- 
completedFutureReturns a new KafkaFuture that is already completed with the given value.
- 
allOfReturns a new KafkaFuture that is completed when all the given futures have completed. If any future throws an exception, the returned future returns it. If multiple futures throw an exception, which one gets returned is arbitrarily chosen.
- 
toCompletionStageGets aCompletionStagewith the same completion properties as thisKafkaFuture. The returned instance will complete when this future completes and in the same way (with the same result or exception).Calling toCompletableFuture()on the returned instance will yield aCompletableFuture, but invocation of the completion methods (complete()and other methods in thecomplete*()andobtrude*()families) on thatCompletableFutureinstance will result inUnsupportedOperationExceptionbeing thrown. Unlike a "minimal"CompletableFuture, theget*()and other methods ofCompletableFuturethat are not inherited fromCompletionStagewill work normally.If you want to block on the completion of a KafkaFuture you should use get(),get(long, TimeUnit)orgetNow(Object), rather than calling.toCompletionStage().toCompletableFuture().get()etc.- Since:
- Kafka 3.0
 
- 
thenApplyReturns a new KafkaFuture that, when this future completes normally, is executed with this futures's result as the argument to the supplied function. The function may be invoked by the thread that callsthenApplyor it may be invoked by the thread that completes the future.
- 
thenApplyPreferthenApply(BaseFunction)as this function is here for backwards compatibility reasons and might be deprecated/removed in a future release.
- 
whenCompletepublic abstract KafkaFuture<T> whenComplete(KafkaFuture.BiConsumer<? super T, ? super Throwable> action) Returns a new KafkaFuture with the same result or exception as this future, that executes the given action when this future completes. When this future is done, the given action is invoked with the result (or null if none) and the exception (or null if none) of this future as arguments. The returned future is completed when the action returns. The supplied action should not throw an exception. However, if it does, the following rules apply: if this future completed normally but the supplied action throws an exception, then the returned future completes exceptionally with the supplied action's exception. Or, if this future completed exceptionally and the supplied action throws an exception, then the returned future completes exceptionally with this future's exception. The action may be invoked by the thread that callswhenCompleteor it may be invoked by the thread that completes the future.- Parameters:
- action- the action to preform
- Returns:
- the new future
 
- 
cancelpublic abstract boolean cancel(boolean mayInterruptIfRunning) If not already completed, completes this future with a CancellationException. Dependent futures that have not already completed will also complete exceptionally, with a CompletionException caused by this CancellationException.
- 
getWaits if necessary for this future to complete, and then returns its result.- Specified by:
- getin interface- Future<T>
- Throws:
- InterruptedException
- ExecutionException
 
- 
getpublic abstract T get(long timeout, TimeUnit unit) throws InterruptedException, ExecutionException, TimeoutException Waits if necessary for at most the given time for this future to complete, and then returns its result, if available.- Specified by:
- getin interface- Future<T>
- Throws:
- InterruptedException
- ExecutionException
- TimeoutException
 
- 
getNowReturns the result value (or throws any encountered exception) if completed, else returns the given valueIfAbsent.
- 
isCancelledpublic abstract boolean isCancelled()Returns true if this CompletableFuture was cancelled before it completed normally.- Specified by:
- isCancelledin interface- Future<T>
 
- 
isCompletedExceptionallypublic abstract boolean isCompletedExceptionally()Returns true if this CompletableFuture completed exceptionally, in any way.
- 
isDonepublic abstract boolean isDone()Returns true if completed in any fashion: normally, exceptionally, or via cancellation.
 
-