Package rocks.xmpp.util.concurrent
Class AsyncResult<T>
- java.lang.Object
-
- rocks.xmpp.util.concurrent.AsyncResult<T>
-
- All Implemented Interfaces:
CompletionStage<T>,Future<T>
public class AsyncResult<T> extends Object implements Future<T>, CompletionStage<T>
Represents the result of an asynchronous operation.It implements both
FutureandCompletionStageand is therefore similar toCompletableFuture, but read-only, i.e. it cannot be completed.- See Also:
CompletableFuture
-
-
Constructor Summary
Constructors Constructor Description AsyncResult(CompletionStage<T> completionStage)
-
Method Summary
-
-
-
Constructor Detail
-
AsyncResult
public AsyncResult(CompletionStage<T> completionStage)
-
-
Method Detail
-
thenApply
public <U> AsyncResult<U> thenApply(Function<? super T,? extends U> fn)
- Specified by:
thenApplyin interfaceCompletionStage<T>
-
thenApplyAsync
public <U> AsyncResult<U> thenApplyAsync(Function<? super T,? extends U> fn)
- Specified by:
thenApplyAsyncin interfaceCompletionStage<T>
-
thenApplyAsync
public <U> AsyncResult<U> thenApplyAsync(Function<? super T,? extends U> fn, Executor executor)
- Specified by:
thenApplyAsyncin interfaceCompletionStage<T>
-
thenAccept
public AsyncResult<Void> thenAccept(Consumer<? super T> action)
- Specified by:
thenAcceptin interfaceCompletionStage<T>
-
thenAcceptAsync
public AsyncResult<Void> thenAcceptAsync(Consumer<? super T> action)
- Specified by:
thenAcceptAsyncin interfaceCompletionStage<T>
-
thenAcceptAsync
public AsyncResult<Void> thenAcceptAsync(Consumer<? super T> action, Executor executor)
- Specified by:
thenAcceptAsyncin interfaceCompletionStage<T>
-
thenRun
public AsyncResult<Void> thenRun(Runnable action)
- Specified by:
thenRunin interfaceCompletionStage<T>
-
thenRunAsync
public AsyncResult<Void> thenRunAsync(Runnable action)
- Specified by:
thenRunAsyncin interfaceCompletionStage<T>
-
thenRunAsync
public AsyncResult<Void> thenRunAsync(Runnable action, Executor executor)
- Specified by:
thenRunAsyncin interfaceCompletionStage<T>
-
thenCombine
public <U,V> AsyncResult<V> thenCombine(CompletionStage<? extends U> other, BiFunction<? super T,? super U,? extends V> fn)
- Specified by:
thenCombinein interfaceCompletionStage<T>
-
thenCombineAsync
public <U,V> AsyncResult<V> thenCombineAsync(CompletionStage<? extends U> other, BiFunction<? super T,? super U,? extends V> fn)
- Specified by:
thenCombineAsyncin interfaceCompletionStage<T>
-
thenCombineAsync
public <U,V> AsyncResult<V> thenCombineAsync(CompletionStage<? extends U> other, BiFunction<? super T,? super U,? extends V> fn, Executor executor)
- Specified by:
thenCombineAsyncin interfaceCompletionStage<T>
-
thenAcceptBoth
public <U> AsyncResult<Void> thenAcceptBoth(CompletionStage<? extends U> other, BiConsumer<? super T,? super U> action)
- Specified by:
thenAcceptBothin interfaceCompletionStage<T>
-
thenAcceptBothAsync
public <U> AsyncResult<Void> thenAcceptBothAsync(CompletionStage<? extends U> other, BiConsumer<? super T,? super U> action)
- Specified by:
thenAcceptBothAsyncin interfaceCompletionStage<T>
-
thenAcceptBothAsync
public <U> AsyncResult<Void> thenAcceptBothAsync(CompletionStage<? extends U> other, BiConsumer<? super T,? super U> action, Executor executor)
- Specified by:
thenAcceptBothAsyncin interfaceCompletionStage<T>
-
runAfterBoth
public AsyncResult<Void> runAfterBoth(CompletionStage<?> other, Runnable action)
- Specified by:
runAfterBothin interfaceCompletionStage<T>
-
runAfterBothAsync
public AsyncResult<Void> runAfterBothAsync(CompletionStage<?> other, Runnable action)
- Specified by:
runAfterBothAsyncin interfaceCompletionStage<T>
-
runAfterBothAsync
public AsyncResult<Void> runAfterBothAsync(CompletionStage<?> other, Runnable action, Executor executor)
- Specified by:
runAfterBothAsyncin interfaceCompletionStage<T>
-
applyToEither
public <U> AsyncResult<U> applyToEither(CompletionStage<? extends T> other, Function<? super T,U> fn)
- Specified by:
applyToEitherin interfaceCompletionStage<T>
-
applyToEitherAsync
public <U> AsyncResult<U> applyToEitherAsync(CompletionStage<? extends T> other, Function<? super T,U> fn)
- Specified by:
applyToEitherAsyncin interfaceCompletionStage<T>
-
applyToEitherAsync
public <U> AsyncResult<U> applyToEitherAsync(CompletionStage<? extends T> other, Function<? super T,U> fn, Executor executor)
- Specified by:
applyToEitherAsyncin interfaceCompletionStage<T>
-
acceptEither
public AsyncResult<Void> acceptEither(CompletionStage<? extends T> other, Consumer<? super T> action)
- Specified by:
acceptEitherin interfaceCompletionStage<T>
-
acceptEitherAsync
public AsyncResult<Void> acceptEitherAsync(CompletionStage<? extends T> other, Consumer<? super T> action)
- Specified by:
acceptEitherAsyncin interfaceCompletionStage<T>
-
acceptEitherAsync
public AsyncResult<Void> acceptEitherAsync(CompletionStage<? extends T> other, Consumer<? super T> action, Executor executor)
- Specified by:
acceptEitherAsyncin interfaceCompletionStage<T>
-
runAfterEither
public AsyncResult<Void> runAfterEither(CompletionStage<?> other, Runnable action)
- Specified by:
runAfterEitherin interfaceCompletionStage<T>
-
runAfterEitherAsync
public AsyncResult<Void> runAfterEitherAsync(CompletionStage<?> other, Runnable action)
- Specified by:
runAfterEitherAsyncin interfaceCompletionStage<T>
-
runAfterEitherAsync
public AsyncResult<Void> runAfterEitherAsync(CompletionStage<?> other, Runnable action, Executor executor)
- Specified by:
runAfterEitherAsyncin interfaceCompletionStage<T>
-
thenCompose
public <U> AsyncResult<U> thenCompose(Function<? super T,? extends CompletionStage<U>> fn)
- Specified by:
thenComposein interfaceCompletionStage<T>
-
thenComposeAsync
public <U> AsyncResult<U> thenComposeAsync(Function<? super T,? extends CompletionStage<U>> fn)
- Specified by:
thenComposeAsyncin interfaceCompletionStage<T>
-
thenComposeAsync
public <U> AsyncResult<U> thenComposeAsync(Function<? super T,? extends CompletionStage<U>> fn, Executor executor)
- Specified by:
thenComposeAsyncin interfaceCompletionStage<T>
-
exceptionally
public AsyncResult<T> exceptionally(Function<Throwable,? extends T> fn)
- Specified by:
exceptionallyin interfaceCompletionStage<T>
-
whenComplete
public AsyncResult<T> whenComplete(BiConsumer<? super T,? super Throwable> action)
- Specified by:
whenCompletein interfaceCompletionStage<T>
-
whenCompleteAsync
public AsyncResult<T> whenCompleteAsync(BiConsumer<? super T,? super Throwable> action)
- Specified by:
whenCompleteAsyncin interfaceCompletionStage<T>
-
whenCompleteAsync
public AsyncResult<T> whenCompleteAsync(BiConsumer<? super T,? super Throwable> action, Executor executor)
- Specified by:
whenCompleteAsyncin interfaceCompletionStage<T>
-
handle
public <U> AsyncResult<U> handle(BiFunction<? super T,Throwable,? extends U> fn)
- Specified by:
handlein interfaceCompletionStage<T>
-
handleAsync
public <U> AsyncResult<U> handleAsync(BiFunction<? super T,Throwable,? extends U> fn)
- Specified by:
handleAsyncin interfaceCompletionStage<T>
-
handleAsync
public <U> AsyncResult<U> handleAsync(BiFunction<? super T,Throwable,? extends U> fn, Executor executor)
- Specified by:
handleAsyncin interfaceCompletionStage<T>
-
toCompletableFuture
public final CompletableFuture<T> toCompletableFuture()
- Specified by:
toCompletableFuturein interfaceCompletionStage<T>
-
cancel
public boolean cancel(boolean mayInterruptIfRunning)
Cancels the processing of thisFuture, i.e. completes it with aCancellationException.
-
cancel
public boolean cancel()
Cancels the processing of thisFuture, i.e. completes it with aCancellationException.This method is a shortcut to
cancel(boolean), because the boolean parameter has no effect in this implementation.- Returns:
- If this
Futureis now cancelled.
-
isCancelled
public boolean isCancelled()
- Specified by:
isCancelledin interfaceFuture<T>
-
get
public T get() throws InterruptedException, ExecutionException
- Specified by:
getin interfaceFuture<T>- Throws:
InterruptedExceptionExecutionException
-
get
public T get(long timeout, TimeUnit unit) throws InterruptedException, ExecutionException, TimeoutException
- Specified by:
getin interfaceFuture<T>- Throws:
InterruptedExceptionExecutionExceptionTimeoutException
-
getResult
public final T getResult() throws XmppException
Waits uninterruptibly on the result of the query and returns it.If the thread, waiting on the result is interrupted, this method continues to block until the result is available.
- Returns:
- The result.
- Throws:
XmppException- If the response threw an exception.
-
getResult
public final T getResult(long timeout, TimeUnit unit) throws XmppException, TimeoutException
Waits uninterruptibly on the result of the query (with a timeout) and returns it.If the thread, waiting on the result is interrupted, this method continues to block until the result is available or the timeout elapses.
- Parameters:
timeout- The timeoutunit- The time unit.- Returns:
- The result.
- Throws:
XmppException- If the response threw an exception.TimeoutException- If the result didn't receive in time.
-
-