@Beta public abstract class AbstractCheckedFuture<V,X extends Exception> extends Object implements CheckedFuture<V,X>
ListenableFuture that adds support for
the checkedGet() and checkedGet(long, TimeUnit) methods.| Modifier and Type | Field and Description |
|---|---|
protected ListenableFuture<V> |
delegate
The delegate, used to pass along all our methods.
|
| Modifier | Constructor and Description |
|---|---|
protected |
AbstractCheckedFuture(ListenableFuture<V> delegate)
Constructs an
AbstractCheckedFuture that wraps a delegate. |
| Modifier and Type | Method and Description |
|---|---|
void |
addListener(Runnable listener,
Executor exec)
Registers a listener to be run on
the given executor.
|
boolean |
cancel(boolean mayInterruptIfRunning) |
V |
checkedGet()
Exception checking version of
Future.get() that will translate
InterruptedException, CancellationException and
ExecutionException into application-specific exceptions. |
V |
checkedGet(long timeout,
TimeUnit unit)
Exception checking version of
Future.get(long, TimeUnit) that will
translate InterruptedException, CancellationException and
ExecutionException into application-specific exceptions. |
V |
get() |
V |
get(long timeout,
TimeUnit unit) |
boolean |
isCancelled() |
boolean |
isDone() |
protected abstract X |
mapException(Exception e)
Translates from an
InterruptedException,
CancellationException or ExecutionException thrown by
get to an exception of type X to be thrown by
checkedGet. |
protected final ListenableFuture<V> delegate
protected AbstractCheckedFuture(ListenableFuture<V> delegate)
AbstractCheckedFuture that wraps a delegate.protected abstract X mapException(Exception e)
InterruptedException,
CancellationException or ExecutionException thrown by
get to an exception of type X to be thrown by
checkedGet. Subclasses must implement this method.
If e is an InterruptedException, the calling
checkedGet method has already restored the interrupt after catching
the exception. If an implementation of mapException(Exception)
wishes to swallow the interrupt, it can do so by calling
Thread.interrupted().
public V checkedGet() throws X extends Exception
Future.get() that will translate
InterruptedException, CancellationException and
ExecutionException into application-specific exceptions.
This implementation calls get() and maps that method's standard
exceptions to instances of type X using mapException(java.lang.Exception).
In addition, if get throws an InterruptedException, this
implementation will set the current thread's interrupt status before
calling mapException.
checkedGet in interface CheckedFuture<V,X extends Exception>X - if get() throws an InterruptedException,
CancellationException, or ExecutionExceptionX extends Exceptionpublic V checkedGet(long timeout, TimeUnit unit) throws TimeoutException, X extends Exception
Future.get(long, TimeUnit) that will
translate InterruptedException, CancellationException and
ExecutionException into application-specific exceptions. On
timeout this method throws a normal TimeoutException.
This implementation calls get(long, TimeUnit) and maps that
method's standard exceptions (excluding TimeoutException, which is
propagated) to instances of type X using mapException(java.lang.Exception).
In addition, if get throws an InterruptedException, this
implementation will set the current thread's interrupt status before
calling mapException.
checkedGet in interface CheckedFuture<V,X extends Exception>X - if get() throws an InterruptedException,
CancellationException, or ExecutionExceptionTimeoutException - if retrieving the result timed out.X extends Exceptionpublic boolean cancel(boolean mayInterruptIfRunning)
public boolean isCancelled()
isCancelled in interface Future<V>public V get() throws InterruptedException, ExecutionException
get in interface Future<V>InterruptedExceptionExecutionExceptionpublic V get(long timeout, TimeUnit unit) throws InterruptedException, ExecutionException, TimeoutException
get in interface Future<V>InterruptedExceptionExecutionExceptionTimeoutExceptionpublic void addListener(Runnable listener, Executor exec)
ListenableFutureFuture's
computation is complete or, if the computation
is already complete, immediately.
There is no guaranteed ordering of execution of listeners, but any listener added through this method is guaranteed to be called once the computation is complete.
Listeners cannot throw checked exceptions and should not throw RuntimeException unless their executors are prepared to handle it.
Listeners that will execute in MoreExecutors.sameThreadExecutor()
should take special care, since they may run during the call to addListener or during the call that sets the future's value.
addListener in interface ListenableFuture<V>listener - the listener to run when the computation is completeexec - the executor to run the listener inCopyright © 2010-2012. All Rights Reserved.