Class CompletionListenerFuture
java.lang.Object
javax.cache.integration.CompletionListenerFuture
- All Implemented Interfaces:
Future<Void>, CompletionListener
A CompletionListenerFuture is a CompletionListener implementation that
supports being used as a Future.
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.
- Since:
- 1.0
-
Nested Class Summary
Nested classes/interfaces inherited from interface Future
Future.State -
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbooleancancel(boolean b) Cancelling is not supported, always throws exception.get()Waits if necessary for the operation to complete.Waits if necessary for at most the given time for the operation to complete.booleanCancelling is not supported, always returns falsebooleanisDone()private voidMark operation as completed and wakeup all listeners, called under lock.voidNotifies the application that the operation completed successfully.voidNotifies the application that the operation failed.Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface Future
exceptionNow, resultNow, state
-
Field Details
-
lock
-
isCompleted
private boolean isCompleted -
exception
-
-
Constructor Details
-
CompletionListenerFuture
public CompletionListenerFuture()Constructs a CompletionListenerFuture.
-
-
Method Details
-
onCompletion
Notifies the application that the operation completed successfully.- Specified by:
onCompletionin interfaceCompletionListener- Throws:
IllegalStateException- if the instance is used more than once
-
onException
Notifies the application that the operation failed.- Specified by:
onExceptionin interfaceCompletionListener- Parameters:
e- the Exception that occurred- Throws:
IllegalStateException- if the instance is used more than once
-
markAsCompleted
private void markAsCompleted()Mark operation as completed and wakeup all listeners, called under lock. -
cancel
public boolean cancel(boolean b) Cancelling is not supported, always throws exception.- Specified by:
cancelin interfaceFuture<Void>- Throws:
UnsupportedOperationException- thrown always
-
isCancelled
public boolean isCancelled()Cancelling is not supported, always returns false- Specified by:
isCancelledin interfaceFuture<Void>- Returns:
- always false.
-
isDone
-
get
Waits if necessary for the operation to complete. Always returnsnull.- Specified by:
getin interfaceFuture<Void>- Returns:
- always
null - Throws:
ExecutionException- if the computation threw an exception. This wraps the exception received by(Exception)InterruptedException- if the current thread was interrupted while waiting
-
get
public Void get(long timeout, TimeUnit unit) throws InterruptedException, ExecutionException, TimeoutException Waits if necessary for at most the given time for the operation to complete. Always returnsnull.- Specified by:
getin interfaceFuture<Void>- Parameters:
timeout- the maximum time to waitunit- the time unit of the timeout argument- Returns:
- always
null - Throws:
ExecutionException- 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 out
-