|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
@Beta public interface ListenableFuture<V>
This interface defines a future that has listeners attached to it, which
is useful for asynchronous workflows. Each listener has an associated
executor, and is invoked using this executor once the Future
's
computation is complete. The listener will be
executed even if it is added after the computation is complete.
Usage:
final ListenableFuture<?> future = myService.async(myRequest);
future.addListener(new Runnable() {
public void run() {
System.out.println("Operation Complete.");
try {
System.out.println("Result: " + future.get());
} catch (Exception e) {
System.out.println("Error: " + e.message());
}
}
}, exec);
Method Summary | |
---|---|
void |
addListener(Runnable listener,
Executor exec)
Adds a listener and executor to the ListenableFuture. |
Methods inherited from interface java.util.concurrent.Future |
---|
cancel, get, get, isCancelled, isDone |
Method Detail |
---|
void addListener(Runnable listener, Executor exec)
Adds a listener and executor to the ListenableFuture.
The listener will be passed
to the executor for execution when the Future
's computation is
complete.
There is no guaranteed ordering of execution of listeners, they may get called in the order they were added and they may get called out of order, but any listener added through this method is guaranteed to be called once the computation is complete.
listener
- the listener to run when the computation is complete.exec
- the executor to run the listener in.
NullPointerException
- if the executor or listener was null.
RejectedExecutionException
- if we tried to execute the listener
immediately but the executor rejected it.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |