T
- Type of result provided by this ListenableFuturepublic class CancelDebuggingListenableFuture<T> extends java.lang.Object implements ListenableFuture<T>
ListenableFuture
to provide enhanced features for debugging the state at
which at which it was canceled. When a cancel request comes in this class will attempt to
record the stack trace of the delegateFuture. If it then cancels, and is able to get a stack
trace from the processing thread at time of cancellation, then any requests to get()
that result in a CancellationException
, the exception will have a cause of
CancelDebuggingListenableFuture.FutureProcessingStack
with the previous stack trace included.Modifier and Type | Class and Description |
---|---|
static class |
CancelDebuggingListenableFuture.FutureProcessingStack
Throwable that is not thrown, but instead added as a cause to indicate the processing stack
trace at the time of cancellation.
|
ListenableFuture.ListenerOptimizationStrategy
Constructor and Description |
---|
CancelDebuggingListenableFuture(ListenableFuture<T> delegateFuture)
Construct a new
CancelDebuggingListenableFuture by wrapping the provided future. |
Modifier and Type | Method and Description |
---|---|
boolean |
cancel(boolean interrupt) |
T |
get() |
T |
get(long arg0,
java.util.concurrent.TimeUnit arg1) |
java.lang.StackTraceElement[] |
getRunningStackTrace()
A best effort to return the stack trace for for the executing thread of either this future,
or a future which this depends on through the use of
ListenableFuture.map(Function) or similar
functions. |
boolean |
isCancelled() |
boolean |
isDone() |
ListenableFuture<T> |
listener(java.lang.Runnable listener,
java.util.concurrent.Executor executor,
ListenableFuture.ListenerOptimizationStrategy optimizeExecution)
Add a listener to be called once the future has completed.
|
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
addCallback, addCallback, addCallback, addListener, addListener, addListener, callback, callback, callback, failureCallback, failureCallback, failureCallback, flatMap, flatMap, flatMap, flatMap, flatMapFailure, flatMapFailure, flatMapFailure, listener, listener, map, map, map, mapFailure, mapFailure, mapFailure, resultCallback, resultCallback, resultCallback, throwMap, throwMap, throwMap
public CancelDebuggingListenableFuture(ListenableFuture<T> delegateFuture)
CancelDebuggingListenableFuture
by wrapping the provided future.delegateFuture
- A non-null future to wrappublic boolean cancel(boolean interrupt)
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 arg0, java.util.concurrent.TimeUnit arg1) 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 ListenableFuture<T> listener(java.lang.Runnable listener, java.util.concurrent.Executor executor, ListenableFuture.ListenerOptimizationStrategy optimizeExecution)
ListenableFuture
If the provided Executor
is null, the listener will execute on the thread which
computed the original future (once it is done). If the future has already completed, the
listener will execute immediately on the thread which is adding the listener.
Caution should be used when choosing to optimize the listener execution. If the listener is
complex, or wanting to be run concurrent, this optimization could prevent that. In addition
it will prevent other listeners from potentially being invoked until it completes. However
if the listener is small / fast, this can provide significant performance gains. It should
also be known that not all ListenableFuture
implementations may be able to do such an
optimization. Please see ListenableFuture.ListenerOptimizationStrategy
javadocs for more specific
details of what optimizations are available.
listener
in interface ListenableFuture<T>
listener
- the listener to run when the computation is completeexecutor
- Executor
the listener should be ran on, or null
optimizeExecution
- true
to avoid listener queuing for execution if already on the desired poolthis
instance to add more listeners or other functional operationspublic java.lang.StackTraceElement[] getRunningStackTrace()
ListenableFuture
ListenableFuture.map(Function)
or similar
functions. If there is no thread executing the future yet, or the future has already
completed, then this will return null
.
This is done without locking (though generating a stack trace still requires a JVM safe point), so the resulting stack trace is NOT guaranteed to be accurate. In most cases (particularly when blocking) this should be accurate though.
getRunningStackTrace
in interface ListenableFuture<T>
null
if unavailable