Package javax.cache.integration
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 java.util.concurrent.Future
Future.State
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionboolean
cancel
(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.boolean
Cancelling is not supported, always returns falseboolean
isDone()
private void
Mark operation as completed and wakeup all listeners, called under lock.void
Notifies the application that the operation completed successfully.void
Notifies the application that the operation failed.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface java.util.concurrent.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:
onCompletion
in interfaceCompletionListener
- Throws:
IllegalStateException
- if the instance is used more than once
-
onException
Notifies the application that the operation failed.- Specified by:
onException
in 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:
cancel
in interfaceFuture<Void>
- Throws:
UnsupportedOperationException
- thrown always
-
isCancelled
public boolean isCancelled()Cancelling is not supported, always returns false- Specified by:
isCancelled
in interfaceFuture<Void>
- Returns:
- always false.
-
isDone
public boolean isDone() -
get
Waits if necessary for the operation to complete. Always returnsnull
.- Specified by:
get
in 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:
get
in 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
-