Top Description Fields Constructors Methods
javax.cache.integration

public Class CompletionListenerFuture

extends Object
implements CompletionListener, Future<Void>
Class Inheritance
All Implemented Interfaces
java.util.concurrent.Future, javax.cache.integration.CompletionListener
Imports
java.util.concurrent.ExecutionException, .Future, .TimeUnit, .TimeoutException

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 java.lang.IllegalStateException being raised.

Authors
Brian Oliver, Greg Luck, Jens Wilke
Since
1.0

Field Summary

Modifier and TypeField and Description
private Exception
private boolean
private final Object

Constructor Summary

AccessConstructor and Description
public
CompletionListenerFuture()

Constructs a CompletionListenerFuture.

Method Summary

Modifier and TypeMethod and Description
public boolean
cancel(boolean
true if the thread executing this task should be interrupted (if the thread is known to the implementation); otherwise, in-progress tasks are allowed to complete
b
)

Implements java.util.concurrent.Future.cancel.

Cancelling is not supported, always throws exception.
public Void

Returns:

always null
get
()

Implements java.util.concurrent.Future.get.

Waits if necessary for the operation to complete.
public Void

Returns:

always null
get
(long
the maximum time to wait
timeout
,
TimeUnit
the time unit of the timeout argument
unit
)

Implements java.util.concurrent.Future.get.

Waits if necessary for at most the given time for the operation to complete.
public boolean

Returns:

always false.
isCancelled
()

Implements java.util.concurrent.Future.isCancelled.

Cancelling is not supported, always returns false
public boolean
isDone()

Implements java.util.concurrent.Future.isDone.

Returns true if this task completed.
private void
markAsCompleted()

Mark operation as completed and wakeup all listeners, called under lock.

public void
onCompletion()

Implements javax.cache.integration.CompletionListener.onCompletion.

Notifies the application that the operation completed successfully.
public void
onException(Exception
the Exception that occurred
e
)

Implements javax.cache.integration.CompletionListener.onException.

Notifies the application that the operation failed.
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

exceptionback to summary
private Exception exception
isCompletedback to summary
private boolean isCompleted
lockback to summary
private final Object lock

Constructor Detail

CompletionListenerFutureback to summary
public CompletionListenerFuture()

Constructs a CompletionListenerFuture.

Method Detail

cancelback to summary
public boolean cancel(boolean b)

Implements java.util.concurrent.Future.cancel.

Cancelling is not supported, always throws exception.

Parameters
b:boolean

Doc from java.util.concurrent.Future.cancel.

true if the thread executing this task should be interrupted (if the thread is known to the implementation); otherwise, in-progress tasks are allowed to complete

Returns:boolean

Doc from java.util.concurrent.Future.cancel.

false if the task could not be cancelled, typically because it has already completed; true otherwise. If two or more threads cause a task to be cancelled, then at least one of them returns true. Implementations may provide stronger guarantees.

Annotations
@Override
Exceptions
UnsupportedOperationException:
thrown always
getback to summary
public Void get() throws InterruptedException, ExecutionException

Implements java.util.concurrent.Future.get.

Waits if necessary for the operation to complete. Always returns null.

Returns:Void

always null

Annotations
@Override
Exceptions
InterruptedException:
if the current thread was interrupted while waiting
ExecutionException:
if the computation threw an exception. This wraps the exception received by (Exception)
getback to summary
public Void get(long timeout, TimeUnit unit) throws InterruptedException, ExecutionException, TimeoutException

Implements java.util.concurrent.Future.get.

Waits if necessary for at most the given time for the operation to complete. Always returns null.

Parameters
timeout:long

the maximum time to wait

unit:TimeUnit

the time unit of the timeout argument

Returns:Void

always null

Annotations
@Override
Exceptions
InterruptedException:
if the current thread was interrupted while waiting
ExecutionException:
if the computation threw an exception. This wraps the exception received by (Exception)
TimeoutException:
if the wait timed out
isCancelledback to summary
public boolean isCancelled()

Implements java.util.concurrent.Future.isCancelled.

Cancelling is not supported, always returns false

Returns:boolean

always false.

Annotations
@Override
isDoneback to summary
public boolean isDone()

Implements java.util.concurrent.Future.isDone.

Doc from java.util.concurrent.Future.isDone.

Returns true if this task completed. Completion may be due to normal termination, an exception, or cancellation -- in all of these cases, this method will return true.

Returns:boolean

true if this task completed

Annotations
@Override
markAsCompletedback to summary
private void markAsCompleted()

Mark operation as completed and wakeup all listeners, called under lock.

onCompletionback to summary
public void onCompletion() throws IllegalStateException

Implements javax.cache.integration.CompletionListener.onCompletion.

Notifies the application that the operation completed successfully.

Annotations
@Override
Exceptions
IllegalStateException:
if the instance is used more than once
onExceptionback to summary
public void onException(Exception e) throws IllegalStateException

Implements javax.cache.integration.CompletionListener.onException.

Notifies the application that the operation failed.

Parameters
e:Exception

the Exception that occurred

Annotations
@Override
Exceptions
IllegalStateException:
if the instance is used more than once