Package javax.cache.integration
Class CompletionListenerFuture
- java.lang.Object
-
- javax.cache.integration.CompletionListenerFuture
-
- All Implemented Interfaces:
java.util.concurrent.Future<java.lang.Void>,CompletionListener
public class CompletionListenerFuture extends java.lang.Object implements CompletionListener, java.util.concurrent.Future<java.lang.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
IllegalStateExceptionbeing raised.- Since:
- 1.0
-
-
Field Summary
Fields Modifier and Type Field Description private java.lang.Exceptionexceptionprivate booleanisCompletedprivate java.lang.Objectlock
-
Constructor Summary
Constructors Constructor Description CompletionListenerFuture()Constructs a CompletionListenerFuture.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description booleancancel(boolean b)Cancelling is not supported, always throws exception.java.lang.Voidget()Waits if necessary for the operation to complete.java.lang.Voidget(long timeout, java.util.concurrent.TimeUnit unit)Waits if necessary for at most the given time for the operation to complete.booleanisCancelled()Cancelling is not supported, always returns falsebooleanisDone()private voidmarkAsCompleted()Mark operation as completed and wakeup all listeners, called under lock.voidonCompletion()Notifies the application that the operation completed successfully.voidonException(java.lang.Exception e)Notifies the application that the operation failed.
-
-
-
Method Detail
-
onCompletion
public void onCompletion() throws java.lang.IllegalStateExceptionNotifies the application that the operation completed successfully.- Specified by:
onCompletionin interfaceCompletionListener- Throws:
java.lang.IllegalStateException- if the instance is used more than once
-
onException
public void onException(java.lang.Exception e) throws java.lang.IllegalStateExceptionNotifies the application that the operation failed.- Specified by:
onExceptionin interfaceCompletionListener- Parameters:
e- the Exception that occurred- Throws:
java.lang.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 interfacejava.util.concurrent.Future<java.lang.Void>- Throws:
java.lang.UnsupportedOperationException- thrown always
-
isCancelled
public boolean isCancelled()
Cancelling is not supported, always returns false- Specified by:
isCancelledin interfacejava.util.concurrent.Future<java.lang.Void>- Returns:
- always false.
-
isDone
public boolean isDone()
- Specified by:
isDonein interfacejava.util.concurrent.Future<java.lang.Void>
-
get
public java.lang.Void get() throws java.lang.InterruptedException, java.util.concurrent.ExecutionExceptionWaits if necessary for the operation to complete. Always returnsnull.- Specified by:
getin interfacejava.util.concurrent.Future<java.lang.Void>- Returns:
- always
null - Throws:
java.util.concurrent.ExecutionException- if the computation threw an exception. This wraps the exception received by(Exception)java.lang.InterruptedException- if the current thread was interrupted while waiting
-
get
public java.lang.Void get(long timeout, java.util.concurrent.TimeUnit unit) throws java.lang.InterruptedException, java.util.concurrent.ExecutionException, java.util.concurrent.TimeoutExceptionWaits if necessary for at most the given time for the operation to complete. Always returnsnull.- Specified by:
getin interfacejava.util.concurrent.Future<java.lang.Void>- Parameters:
timeout- the maximum time to waitunit- the time unit of the timeout argument- Returns:
- always
null - Throws:
java.util.concurrent.ExecutionException- if the computation threw an exception. This wraps the exception received by(Exception)java.lang.InterruptedException- if the current thread was interrupted while waitingjava.util.concurrent.TimeoutException- if the wait timed out
-
-