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
Future
andCompletionStage
and 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:
thenApply
in interfaceCompletionStage<T>
-
thenApplyAsync
public <U> AsyncResult<U> thenApplyAsync(Function<? super T,? extends U> fn)
- Specified by:
thenApplyAsync
in interfaceCompletionStage<T>
-
thenApplyAsync
public <U> AsyncResult<U> thenApplyAsync(Function<? super T,? extends U> fn, Executor executor)
- Specified by:
thenApplyAsync
in interfaceCompletionStage<T>
-
thenAccept
public AsyncResult<Void> thenAccept(Consumer<? super T> action)
- Specified by:
thenAccept
in interfaceCompletionStage<T>
-
thenAcceptAsync
public AsyncResult<Void> thenAcceptAsync(Consumer<? super T> action)
- Specified by:
thenAcceptAsync
in interfaceCompletionStage<T>
-
thenAcceptAsync
public AsyncResult<Void> thenAcceptAsync(Consumer<? super T> action, Executor executor)
- Specified by:
thenAcceptAsync
in interfaceCompletionStage<T>
-
thenRun
public AsyncResult<Void> thenRun(Runnable action)
- Specified by:
thenRun
in interfaceCompletionStage<T>
-
thenRunAsync
public AsyncResult<Void> thenRunAsync(Runnable action)
- Specified by:
thenRunAsync
in interfaceCompletionStage<T>
-
thenRunAsync
public AsyncResult<Void> thenRunAsync(Runnable action, Executor executor)
- Specified by:
thenRunAsync
in interfaceCompletionStage<T>
-
thenCombine
public <U,V> AsyncResult<V> thenCombine(CompletionStage<? extends U> other, BiFunction<? super T,? super U,? extends V> fn)
- Specified by:
thenCombine
in interfaceCompletionStage<T>
-
thenCombineAsync
public <U,V> AsyncResult<V> thenCombineAsync(CompletionStage<? extends U> other, BiFunction<? super T,? super U,? extends V> fn)
- Specified by:
thenCombineAsync
in 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:
thenCombineAsync
in interfaceCompletionStage<T>
-
thenAcceptBoth
public <U> AsyncResult<Void> thenAcceptBoth(CompletionStage<? extends U> other, BiConsumer<? super T,? super U> action)
- Specified by:
thenAcceptBoth
in interfaceCompletionStage<T>
-
thenAcceptBothAsync
public <U> AsyncResult<Void> thenAcceptBothAsync(CompletionStage<? extends U> other, BiConsumer<? super T,? super U> action)
- Specified by:
thenAcceptBothAsync
in interfaceCompletionStage<T>
-
thenAcceptBothAsync
public <U> AsyncResult<Void> thenAcceptBothAsync(CompletionStage<? extends U> other, BiConsumer<? super T,? super U> action, Executor executor)
- Specified by:
thenAcceptBothAsync
in interfaceCompletionStage<T>
-
runAfterBoth
public AsyncResult<Void> runAfterBoth(CompletionStage<?> other, Runnable action)
- Specified by:
runAfterBoth
in interfaceCompletionStage<T>
-
runAfterBothAsync
public AsyncResult<Void> runAfterBothAsync(CompletionStage<?> other, Runnable action)
- Specified by:
runAfterBothAsync
in interfaceCompletionStage<T>
-
runAfterBothAsync
public AsyncResult<Void> runAfterBothAsync(CompletionStage<?> other, Runnable action, Executor executor)
- Specified by:
runAfterBothAsync
in interfaceCompletionStage<T>
-
applyToEither
public <U> AsyncResult<U> applyToEither(CompletionStage<? extends T> other, Function<? super T,U> fn)
- Specified by:
applyToEither
in interfaceCompletionStage<T>
-
applyToEitherAsync
public <U> AsyncResult<U> applyToEitherAsync(CompletionStage<? extends T> other, Function<? super T,U> fn)
- Specified by:
applyToEitherAsync
in interfaceCompletionStage<T>
-
applyToEitherAsync
public <U> AsyncResult<U> applyToEitherAsync(CompletionStage<? extends T> other, Function<? super T,U> fn, Executor executor)
- Specified by:
applyToEitherAsync
in interfaceCompletionStage<T>
-
acceptEither
public AsyncResult<Void> acceptEither(CompletionStage<? extends T> other, Consumer<? super T> action)
- Specified by:
acceptEither
in interfaceCompletionStage<T>
-
acceptEitherAsync
public AsyncResult<Void> acceptEitherAsync(CompletionStage<? extends T> other, Consumer<? super T> action)
- Specified by:
acceptEitherAsync
in interfaceCompletionStage<T>
-
acceptEitherAsync
public AsyncResult<Void> acceptEitherAsync(CompletionStage<? extends T> other, Consumer<? super T> action, Executor executor)
- Specified by:
acceptEitherAsync
in interfaceCompletionStage<T>
-
runAfterEither
public AsyncResult<Void> runAfterEither(CompletionStage<?> other, Runnable action)
- Specified by:
runAfterEither
in interfaceCompletionStage<T>
-
runAfterEitherAsync
public AsyncResult<Void> runAfterEitherAsync(CompletionStage<?> other, Runnable action)
- Specified by:
runAfterEitherAsync
in interfaceCompletionStage<T>
-
runAfterEitherAsync
public AsyncResult<Void> runAfterEitherAsync(CompletionStage<?> other, Runnable action, Executor executor)
- Specified by:
runAfterEitherAsync
in interfaceCompletionStage<T>
-
thenCompose
public <U> AsyncResult<U> thenCompose(Function<? super T,? extends CompletionStage<U>> fn)
- Specified by:
thenCompose
in interfaceCompletionStage<T>
-
thenComposeAsync
public <U> AsyncResult<U> thenComposeAsync(Function<? super T,? extends CompletionStage<U>> fn)
- Specified by:
thenComposeAsync
in interfaceCompletionStage<T>
-
thenComposeAsync
public <U> AsyncResult<U> thenComposeAsync(Function<? super T,? extends CompletionStage<U>> fn, Executor executor)
- Specified by:
thenComposeAsync
in interfaceCompletionStage<T>
-
exceptionally
public AsyncResult<T> exceptionally(Function<Throwable,? extends T> fn)
- Specified by:
exceptionally
in interfaceCompletionStage<T>
-
whenComplete
public AsyncResult<T> whenComplete(BiConsumer<? super T,? super Throwable> action)
- Specified by:
whenComplete
in interfaceCompletionStage<T>
-
whenCompleteAsync
public AsyncResult<T> whenCompleteAsync(BiConsumer<? super T,? super Throwable> action)
- Specified by:
whenCompleteAsync
in interfaceCompletionStage<T>
-
whenCompleteAsync
public AsyncResult<T> whenCompleteAsync(BiConsumer<? super T,? super Throwable> action, Executor executor)
- Specified by:
whenCompleteAsync
in interfaceCompletionStage<T>
-
handle
public <U> AsyncResult<U> handle(BiFunction<? super T,Throwable,? extends U> fn)
- Specified by:
handle
in interfaceCompletionStage<T>
-
handleAsync
public <U> AsyncResult<U> handleAsync(BiFunction<? super T,Throwable,? extends U> fn)
- Specified by:
handleAsync
in interfaceCompletionStage<T>
-
handleAsync
public <U> AsyncResult<U> handleAsync(BiFunction<? super T,Throwable,? extends U> fn, Executor executor)
- Specified by:
handleAsync
in interfaceCompletionStage<T>
-
toCompletableFuture
public final CompletableFuture<T> toCompletableFuture()
- Specified by:
toCompletableFuture
in 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
Future
is now cancelled.
-
isCancelled
public boolean isCancelled()
- Specified by:
isCancelled
in interfaceFuture<T>
-
get
public T get() throws InterruptedException, ExecutionException
- Specified by:
get
in interfaceFuture<T>
- Throws:
InterruptedException
ExecutionException
-
get
public T get(long timeout, TimeUnit unit) throws InterruptedException, ExecutionException, TimeoutException
- Specified by:
get
in interfaceFuture<T>
- Throws:
InterruptedException
ExecutionException
TimeoutException
-
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.
-
-