Class AsyncListenableFuture<V>
- java.lang.Object
-
- co.paralleluniverse.fibers.FiberAsync<V,java.util.concurrent.ExecutionException>
-
- co.paralleluniverse.fibers.futures.AsyncListenableFuture<V>
-
- All Implemented Interfaces:
java.io.Serializable
public class AsyncListenableFuture<V> extends FiberAsync<V,java.util.concurrent.ExecutionException>
Turns Google Guava'sListenableFuture
s into a fiber-blocking operation.- See Also:
- Serialized Form
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static <V> V
get(com.google.common.util.concurrent.ListenableFuture<V> future)
Blocks the current strand (either fiber or thread) until the given future completes, and returns its result.static <V> V
get(com.google.common.util.concurrent.ListenableFuture<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(com.google.common.util.concurrent.ListenableFuture<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.-
Methods inherited from class co.paralleluniverse.fibers.FiberAsync
asyncCompleted, asyncFailed, getResult, interrupted, isCompleted, prepark, requestSync, run, run, run, runBlocking, runBlocking, runBlocking, waitForRegistration, wrapException
-
-
-
-
Method Detail
-
get
public static <V> V get(com.google.common.util.concurrent.ListenableFuture<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(com.google.common.util.concurrent.ListenableFuture<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(com.google.common.util.concurrent.ListenableFuture<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>
-
requestSync
protected V requestSync() throws java.util.concurrent.ExecutionException, java.lang.InterruptedException
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
-
-