public class CompletionListenerFuture extends Object implements CompletionListener, Future<Void>
For example:
//create a completion future to use to wait for loadAll
CompletionListenerFuture future = new CompletionListenerFuture();
//load the values for the set of keys, replacing those that may already exist
//in the cache
cache.loadAll(keys, true, future);
//wait for the cache to load the keys
future.get();
A CompletionListenerFuture may only be used once. Attempts to use an instance
multiple times, as part of multiple asynchronous calls will result in an
IllegalStateException
being raised.
Constructor and Description |
---|
CompletionListenerFuture()
Constructs a CompletionListenerFuture.
|
Modifier and Type | Method and Description |
---|---|
boolean |
cancel(boolean b) |
Void |
get()
Waits if necessary for the computation to complete, and then
retrieves its result.
|
Void |
get(long timeout,
TimeUnit unit)
Waits if necessary for at most the given time for the computation
to complete, and then retrieves its result, if available.
|
boolean |
isCancelled() |
boolean |
isDone() |
void |
onCompletion()
Notifies the application that the operation completed successfully.
|
void |
onException(Exception e)
Notifies the application that the operation failed.
|
public CompletionListenerFuture()
public void onCompletion() throws IllegalStateException
onCompletion
in interface CompletionListener
IllegalStateException
- if the instance is used more than oncepublic void onException(Exception e) throws IllegalStateException
onException
in interface CompletionListener
e
- the Exception that occurredIllegalStateException
- if the instance is used more than oncepublic boolean isCancelled()
isCancelled
in interface Future<Void>
public Void get() throws InterruptedException, ExecutionException
get
in interface Future<Void>
CancellationException
- if the computation was cancelledExecutionException
- if the computation threw an
exception. This wraps the exception received by (Exception)
InterruptedException
- if the current thread was interrupted
while waitingpublic Void get(long timeout, TimeUnit unit) throws InterruptedException, ExecutionException, TimeoutException
get
in interface Future<Void>
timeout
- the maximum time to waitunit
- the time unit of the timeout argumentCancellationException
- if the computation was cancelledExecutionException
- if the computation threw an
exception. This wraps the exception received by (Exception)
InterruptedException
- if the current thread was interrupted
while waitingTimeoutException
- if the wait timed outCopyright © 2014. All Rights Reserved.