Package javax.cache.integration
Class CompletionListenerFuture
- java.lang.Object
-
- javax.cache.integration.CompletionListenerFuture
-
- All Implemented Interfaces:
Future<Void>
,CompletionListener
public class CompletionListenerFuture extends Object implements CompletionListener, Future<Void>
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
- Author:
- Brian Oliver, Greg Luck, Jens Wilke
-
-
Constructor Summary
Constructors Constructor Description CompletionListenerFuture()
Constructs a CompletionListenerFuture.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
cancel(boolean b)
Cancelling is not supported, always throws exception.Void
get()
Waits if necessary for the operation to complete.Void
get(long timeout, TimeUnit unit)
Waits if necessary for at most the given time for the operation to complete.boolean
isCancelled()
Cancelling is not supported, always returns falseboolean
isDone()
void
onCompletion()
Notifies the application that the operation completed successfully.void
onException(Exception e)
Notifies the application that the operation failed.
-
-
-
Method Detail
-
onCompletion
public void onCompletion() throws IllegalStateException
Notifies the application that the operation completed successfully.- Specified by:
onCompletion
in interfaceCompletionListener
- Throws:
IllegalStateException
- if the instance is used more than once
-
onException
public void onException(Exception e) throws IllegalStateException
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
-
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.
-
get
public Void get() throws InterruptedException, ExecutionException
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
-
-