Class AsyncCompletionStage<V>
- java.lang.Object
-
- co.paralleluniverse.fibers.FiberAsync<V,java.util.concurrent.ExecutionException>
-
- co.paralleluniverse.fibers.futures.AsyncCompletionStage<V>
-
- All Implemented Interfaces:
java.io.Serializable
public class AsyncCompletionStage<V> extends FiberAsync<V,java.util.concurrent.ExecutionException>
TurnsCompletableFuture
s into fiber-blocking operations.- See Also:
- Serialized Form
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static <V> V
get(java.util.concurrent.CompletionStage<V> future)
Blocks the current strand (either fiber or thread) until the given future completes, and returns its result.static <V> V
get(java.util.concurrent.CompletionStage<V> future, long timeout, java.util.concurrent.TimeUnit unit)
Blocks the current strand (either fiber or thread) until the given future completes - but no longer than the given timeout - and returns its result.static <V> V
get(java.util.concurrent.CompletionStage<V> future, Timeout timeout)
Blocks the current strand (either fiber or thread) until the given future completes - but no longer than the given timeout - and returns its result.protected void
requestAsync()
A user of this class must override this method to start the asynchronous operation and register the callback.protected V
requestSync()
Called ifFiberAsync.run()
is not being executed in a fiber.protected java.util.concurrent.ExecutionException
wrapException(java.lang.Throwable t)
Takes the exception generated by the async operation and possibly wraps it in an exception that will be thrown by therun
method.-
Methods inherited from class co.paralleluniverse.fibers.FiberAsync
asyncCompleted, asyncFailed, getResult, interrupted, isCompleted, prepark, requestSync, run, run, run, runBlocking, runBlocking, runBlocking, waitForRegistration
-
-
-
-
Method Detail
-
get
public static <V> V get(java.util.concurrent.CompletionStage<V> future) throws java.util.concurrent.ExecutionException, java.lang.InterruptedException, SuspendExecution
Blocks the current strand (either fiber or thread) until the given future completes, and returns its result.- Parameters:
future
- the future- Returns:
- the future's result
- Throws:
java.util.concurrent.ExecutionException
- if the future's computation threw an exceptionjava.lang.InterruptedException
- if the current thread was interrupted while waitingSuspendExecution
-
get
public static <V> V get(java.util.concurrent.CompletionStage<V> future, long timeout, java.util.concurrent.TimeUnit unit) throws java.util.concurrent.ExecutionException, java.lang.InterruptedException, SuspendExecution, java.util.concurrent.TimeoutException
Blocks the current strand (either fiber or thread) until the given future completes - but no longer than the given timeout - and returns its result.- Parameters:
future
- the futuretimeout
- the maximum duration to wait for the future's resultunit
- the timeout's time unit- Returns:
- the future's result
- Throws:
java.util.concurrent.ExecutionException
- if the future's computation threw an exceptionjava.util.concurrent.TimeoutException
- if the timeout expired before the future completedjava.lang.InterruptedException
- if the current thread was interrupted while waitingSuspendExecution
-
get
public static <V> V get(java.util.concurrent.CompletionStage<V> future, Timeout timeout) throws java.util.concurrent.ExecutionException, java.lang.InterruptedException, SuspendExecution, java.util.concurrent.TimeoutException
Blocks the current strand (either fiber or thread) until the given future completes - but no longer than the given timeout - and returns its result.- Parameters:
future
- the futuretimeout
- the method will not block for longer than the amount remaining in theTimeout
- Returns:
- the future's result
- Throws:
java.util.concurrent.ExecutionException
- if the future's computation threw an exceptionjava.util.concurrent.TimeoutException
- if the timeout expired before the future completedjava.lang.InterruptedException
- if the current thread was interrupted while waitingSuspendExecution
-
requestAsync
protected void requestAsync()
Description copied from class:FiberAsync
A user of this class must override this method to start the asynchronous operation and register the callback. This method may not use anyThreadLocal
s.- Specified by:
requestAsync
in classFiberAsync<V,java.util.concurrent.ExecutionException>
-
wrapException
protected java.util.concurrent.ExecutionException wrapException(java.lang.Throwable t)
Description copied from class:FiberAsync
Takes the exception generated by the async operation and possibly wraps it in an exception that will be thrown by therun
method.- Overrides:
wrapException
in classFiberAsync<V,java.util.concurrent.ExecutionException>
-
requestSync
protected V requestSync() throws java.lang.InterruptedException, java.util.concurrent.ExecutionException
Description copied from class:FiberAsync
Called ifFiberAsync.run()
is not being executed in a fiber. Should perform the operation synchronously and return its result. The default implementation of this method throws an `IllegalThreadStateException`.- Overrides:
requestSync
in classFiberAsync<V,java.util.concurrent.ExecutionException>
- Returns:
- The operation's result.
- Throws:
java.lang.InterruptedException
java.util.concurrent.ExecutionException
-
-