public abstract class TransformingFuture<T,V> extends java.lang.Object implements ListenableFuture<T>
Future
methods to an existing
Future
instance while providing a callback (transform(V)
) to complete
processing when the operation completes. The callback typically transforms the type of the
delegate future into a future of a new type.Modifier | Constructor and Description |
---|---|
protected |
TransformingFuture(ListenableFuture<V> delegateFuture) |
Modifier and Type | Method and Description |
---|---|
void |
addListener(FutureListener<T> callback)
Add a listener to this
Future which will be called when the async operation
completes. |
boolean |
cancel(boolean mayInterruptIfRunning) |
T |
get() |
T |
get(long timeout,
java.util.concurrent.TimeUnit unit) |
boolean |
isCancelled() |
boolean |
isDone() |
void |
removeListener(FutureListener<T> callback)
Remove a previously-registered listener from collection of listeners for this
Future . |
protected abstract T |
transform(V value) |
protected TransformingFuture(ListenableFuture<V> delegateFuture)
public boolean cancel(boolean mayInterruptIfRunning)
cancel
in interface java.util.concurrent.Future<T>
public T get() throws java.lang.InterruptedException, java.util.concurrent.ExecutionException
get
in interface java.util.concurrent.Future<T>
java.lang.InterruptedException
java.util.concurrent.ExecutionException
public T get(long timeout, java.util.concurrent.TimeUnit unit) throws java.lang.InterruptedException, java.util.concurrent.ExecutionException, java.util.concurrent.TimeoutException
get
in interface java.util.concurrent.Future<T>
java.lang.InterruptedException
java.util.concurrent.ExecutionException
java.util.concurrent.TimeoutException
public boolean isCancelled()
isCancelled
in interface java.util.concurrent.Future<T>
public boolean isDone()
isDone
in interface java.util.concurrent.Future<T>
public void addListener(FutureListener<T> callback)
ListenableFuture
Future
which will be called when the async operation
completes. If the async operation has already completed, the listener will be called
immediately.addListener
in interface ListenableFuture<T>
callback
- a FutureListener
implementation to call when the operation completespublic void removeListener(FutureListener<T> callback)
ListenableFuture
Future
. The listener will not be called which will be called when the async
operation completes. If listener
is not currently registered, this method is
a nop.removeListener
in interface ListenableFuture<T>
callback
- a previously-registered FutureListener
implementation to remove from the
list of callback to call when the operation completes