Class ImmediateResultListenableFuture<T>
- java.lang.Object
-
- org.threadly.concurrent.future.ImmediateResultListenableFuture<T>
-
- Type Parameters:
T
- The result object type returned by this future
- All Implemented Interfaces:
java.util.concurrent.Future<T>
,ListenableFuture<T>
public class ImmediateResultListenableFuture<T> extends java.lang.Object
Completed implementation ofListenableFuture
that will immediately return a result. Meaning listeners added will immediately be ran/executed,FutureCallback
's will immediately get called with the result provided, andget()
calls will never block.- Since:
- 1.3.0
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface org.threadly.concurrent.future.ListenableFuture
ListenableFuture.ListenerOptimizationStrategy
-
-
Field Summary
Fields Modifier and Type Field Description static ImmediateResultListenableFuture<java.lang.Boolean>
BOOLEAN_FALSE_RESULT
Static instance ofImmediateResultListenableFuture
which provides aBoolean
in thefalse
state as the result.static ImmediateResultListenableFuture<java.lang.Boolean>
BOOLEAN_TRUE_RESULT
Static instance ofImmediateResultListenableFuture
which provides aBoolean
in thetrue
state as the result.static ImmediateResultListenableFuture<? extends java.util.Enumeration<?>>
EMPTY_ENUMERATION_RESULT
Static instance ofImmediateResultListenableFuture
which provides an emptyEnumeration
fromCollections.emptyEnumeration()
as the result.static ImmediateResultListenableFuture<? extends java.util.Iterator<?>>
EMPTY_ITERATOR_RESULT
Static instance ofImmediateResultListenableFuture
which provides an emptyIterator
fromCollections.emptyIterator()
as the result.static ImmediateResultListenableFuture<? extends java.util.ListIterator<?>>
EMPTY_LIST_ITERATOR_RESULT
Static instance ofImmediateResultListenableFuture
which provides an emptyListIterator
fromCollections.emptyListIterator()
as the result.static ImmediateResultListenableFuture<? extends java.util.List<?>>
EMPTY_LIST_RESULT
Static instance ofImmediateResultListenableFuture
which provides an emptyList
fromCollections.emptyList()
as the result.static ImmediateResultListenableFuture<? extends java.util.Map<?,?>>
EMPTY_MAP_RESULT
Static instance ofImmediateResultListenableFuture
which provides an emptyMap
fromCollections.emptyMap()
as the result.static ImmediateResultListenableFuture<? extends java.util.Optional<?>>
EMPTY_OPTIONAL_RESULT
Static instance ofImmediateResultListenableFuture
which provides an emptyOptional
fromOptional.empty()
as the result.static ImmediateResultListenableFuture<? extends java.util.Set<?>>
EMPTY_SET_RESULT
Static instance ofImmediateResultListenableFuture
which provides an emptySet
fromCollections.emptySet()
as the result.static ImmediateResultListenableFuture<? extends java.util.SortedMap<?,?>>
EMPTY_SORTED_MAP_RESULT
Static instance ofImmediateResultListenableFuture
which provides an emptySortedMap
fromCollections.emptyMap()
as the result.static ImmediateResultListenableFuture<? extends java.util.SortedSet<?>>
EMPTY_SORTED_SET_RESULT
Static instance ofImmediateResultListenableFuture
which provides an emptySortedSet
fromCollections.emptySet()
as the result.static ImmediateResultListenableFuture<java.lang.String>
EMPTY_STRING_RESULT
Static instance ofImmediateResultListenableFuture
which provides an emptyString
as the result.static ImmediateResultListenableFuture<?>
NULL_RESULT
Static instance ofImmediateResultListenableFuture
which provides anull
result.
-
Constructor Summary
Constructors Constructor Description ImmediateResultListenableFuture(T result)
Constructs a completed future that will return the provided result.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description ListenableFuture<T>
callback(FutureCallback<? super T> callback, java.util.concurrent.Executor executor, ListenableFuture.ListenerOptimizationStrategy optimize)
Add aFutureCallback
to be called once the future has completed.boolean
cancel(boolean mayInterruptIfRunning)
This has no effect in this implementation, as this future can not be canceled.ListenableFuture<T>
failureCallback(java.util.function.Consumer<java.lang.Throwable> callback, java.util.concurrent.Executor executor, ListenableFuture.ListenerOptimizationStrategy optimize)
Add aConsumer
to be called once the future has completed.<TT extends java.lang.Throwable>
ListenableFuture<T>flatMapFailure(java.lang.Class<TT> throwableType, java.util.function.Function<? super TT,ListenableFuture<T>> mapper)
Similar toListenableFuture.mapFailure(Class, Function)
except that this mapper function returns aListenableFuture
if it needs to map the Throwable / failure into a result or another failure.<TT extends java.lang.Throwable>
ListenableFuture<T>flatMapFailure(java.lang.Class<TT> throwableType, java.util.function.Function<? super TT,ListenableFuture<T>> mapper, java.util.concurrent.Executor executor)
Similar toListenableFuture.mapFailure(Class, Function, Executor)
except that this mapper function returns aListenableFuture
if it needs to map the Throwable / failure into a result or another failure.<TT extends java.lang.Throwable>
ListenableFuture<T>flatMapFailure(java.lang.Class<TT> throwableType, java.util.function.Function<? super TT,ListenableFuture<T>> mapper, java.util.concurrent.Executor executor, ListenableFuture.ListenerOptimizationStrategy optimizeExecution)
Similar toListenableFuture.mapFailure(Class, Function, Executor, ListenerOptimizationStrategy)
except that this mapper function returns aListenableFuture
if it needs to map the Throwable into a result or another failure.T
get()
T
get(long timeout, java.util.concurrent.TimeUnit unit)
java.lang.Throwable
getFailure()
Similar toFuture.get()
except instead of providing a result, this will provide a thrown exception ifListenableFuture.isCompletedExceptionally()
returnstrue
.java.lang.Throwable
getFailure(long timeout, java.util.concurrent.TimeUnit unit)
Similar toFuture.get(long, TimeUnit)
except instead of providing a result, this will provide a thrown exception ifListenableFuture.isCompletedExceptionally()
returnstrue
.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 ofListenableFuture.map(Function)
or similar functions.boolean
isCancelled()
boolean
isCompletedExceptionally()
Returnstrue
if the future is both done and has completed with an error or was canceled.boolean
isDone()
ListenableFuture<T>
listener(java.lang.Runnable listener)
Add a listener to be called once the future has completed.ListenableFuture<T>
listener(java.lang.Runnable listener, java.util.concurrent.Executor executor, ListenableFuture.ListenerOptimizationStrategy optimize)
Add a listener to be called once the future has completed.<TT extends java.lang.Throwable>
ListenableFuture<T>mapFailure(java.lang.Class<TT> throwableType, java.util.function.Function<? super TT,? extends T> mapper)
Similar toListenableFuture.throwMap(Function)
except this mapper will only be invoked when the future is in a failure state (from either the original computation or an earlier mapper throwing an exception).<TT extends java.lang.Throwable>
ListenableFuture<T>mapFailure(java.lang.Class<TT> throwableType, java.util.function.Function<? super TT,? extends T> mapper, java.util.concurrent.Executor executor)
Similar toListenableFuture.throwMap(Function, Executor)
except this mapper will only be invoked when the future is in a failure state (from either the original computation or an earlier mapper throwing an exception).<TT extends java.lang.Throwable>
ListenableFuture<T>mapFailure(java.lang.Class<TT> throwableType, java.util.function.Function<? super TT,? extends T> mapper, java.util.concurrent.Executor executor, ListenableFuture.ListenerOptimizationStrategy optimizeExecution)
Similar toListenableFuture.throwMap(Function, Executor, ListenerOptimizationStrategy)
except this mapper will only be invoked when the future is in a failure state (from either the original computation or an earlier mapper throwing an exception).ListenableFuture<T>
resultCallback(java.util.function.Consumer<? super T> callback, java.util.concurrent.Executor executor, ListenableFuture.ListenerOptimizationStrategy optimize)
Add aConsumer
to be called once the future has completed.-
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.threadly.concurrent.future.ListenableFuture
callback, callback, failureCallback, failureCallback, flatMap, flatMap, flatMap, flatMap, listener, map, map, map, resultCallback, resultCallback, throwMap, throwMap, throwMap
-
-
-
-
Field Detail
-
NULL_RESULT
public static final ImmediateResultListenableFuture<?> NULL_RESULT
Static instance ofImmediateResultListenableFuture
which provides anull
result. Since this is a common case this can avoid GC overhead. If you want to get this in any generic type useFutureUtils.immediateResultFuture(Object)
, which when provided anull
will always return this static instance.- Since:
- 4.2.0
-
BOOLEAN_TRUE_RESULT
public static final ImmediateResultListenableFuture<java.lang.Boolean> BOOLEAN_TRUE_RESULT
Static instance ofImmediateResultListenableFuture
which provides aBoolean
in thetrue
state as the result.- Since:
- 5.6
-
BOOLEAN_FALSE_RESULT
public static final ImmediateResultListenableFuture<java.lang.Boolean> BOOLEAN_FALSE_RESULT
Static instance ofImmediateResultListenableFuture
which provides aBoolean
in thefalse
state as the result.- Since:
- 5.6
-
EMPTY_STRING_RESULT
public static final ImmediateResultListenableFuture<java.lang.String> EMPTY_STRING_RESULT
Static instance ofImmediateResultListenableFuture
which provides an emptyString
as the result.- Since:
- 5.34
-
EMPTY_OPTIONAL_RESULT
public static final ImmediateResultListenableFuture<? extends java.util.Optional<?>> EMPTY_OPTIONAL_RESULT
Static instance ofImmediateResultListenableFuture
which provides an emptyOptional
fromOptional.empty()
as the result.- Since:
- 5.34
-
EMPTY_LIST_RESULT
public static final ImmediateResultListenableFuture<? extends java.util.List<?>> EMPTY_LIST_RESULT
Static instance ofImmediateResultListenableFuture
which provides an emptyList
fromCollections.emptyList()
as the result.- Since:
- 5.34
-
EMPTY_MAP_RESULT
public static final ImmediateResultListenableFuture<? extends java.util.Map<?,?>> EMPTY_MAP_RESULT
Static instance ofImmediateResultListenableFuture
which provides an emptyMap
fromCollections.emptyMap()
as the result.- Since:
- 5.34
-
EMPTY_SORTED_MAP_RESULT
public static final ImmediateResultListenableFuture<? extends java.util.SortedMap<?,?>> EMPTY_SORTED_MAP_RESULT
Static instance ofImmediateResultListenableFuture
which provides an emptySortedMap
fromCollections.emptyMap()
as the result.- Since:
- 5.34
-
EMPTY_SET_RESULT
public static final ImmediateResultListenableFuture<? extends java.util.Set<?>> EMPTY_SET_RESULT
Static instance ofImmediateResultListenableFuture
which provides an emptySet
fromCollections.emptySet()
as the result.- Since:
- 5.34
-
EMPTY_SORTED_SET_RESULT
public static final ImmediateResultListenableFuture<? extends java.util.SortedSet<?>> EMPTY_SORTED_SET_RESULT
Static instance ofImmediateResultListenableFuture
which provides an emptySortedSet
fromCollections.emptySet()
as the result.- Since:
- 5.34
-
EMPTY_ITERATOR_RESULT
public static final ImmediateResultListenableFuture<? extends java.util.Iterator<?>> EMPTY_ITERATOR_RESULT
Static instance ofImmediateResultListenableFuture
which provides an emptyIterator
fromCollections.emptyIterator()
as the result.- Since:
- 5.34
-
EMPTY_LIST_ITERATOR_RESULT
public static final ImmediateResultListenableFuture<? extends java.util.ListIterator<?>> EMPTY_LIST_ITERATOR_RESULT
Static instance ofImmediateResultListenableFuture
which provides an emptyListIterator
fromCollections.emptyListIterator()
as the result.- Since:
- 5.34
-
EMPTY_ENUMERATION_RESULT
public static final ImmediateResultListenableFuture<? extends java.util.Enumeration<?>> EMPTY_ENUMERATION_RESULT
Static instance ofImmediateResultListenableFuture
which provides an emptyEnumeration
fromCollections.emptyEnumeration()
as the result.- Since:
- 5.34
-
-
Constructor Detail
-
ImmediateResultListenableFuture
public ImmediateResultListenableFuture(T result)
Constructs a completed future that will return the provided result.- Parameters:
result
- Result that is returned by future
-
-
Method Detail
-
isCompletedExceptionally
public boolean isCompletedExceptionally()
Description copied from interface:ListenableFuture
Returnstrue
if the future is both done and has completed with an error or was canceled. If this returnstrue
theThrowable
responsible for the error can be retrieved usingListenableFuture.getFailure()
;- Returns:
true
if this ListenableFuture completed by a thrown Exception or was canceled
-
mapFailure
public <TT extends java.lang.Throwable> ListenableFuture<T> mapFailure(java.lang.Class<TT> throwableType, java.util.function.Function<? super TT,? extends T> mapper)
Description copied from interface:ListenableFuture
Similar toListenableFuture.throwMap(Function)
except this mapper will only be invoked when the future is in a failure state (from either the original computation or an earlier mapper throwing an exception). If this future does resolve in a failure state, and that exception class matches the one provided here. The mapper function will then be provided that throwable, it can then map that throwable back into a result (perhaps anOptional
), or re-throw either the same or a different exception keep the future in a failure state. If the future completes with a normal result, this mapper will be ignored, and the result will be forwarded on without invoking this mapper.- Specified by:
mapFailure
in interfaceListenableFuture<T>
- Type Parameters:
TT
- The type of throwable that should be handled- Parameters:
throwableType
- The class referencing to the type of throwable this mapper handlesmapper
- The mapper to convert a thrown exception to either a result or thrown exception- Returns:
- A
ListenableFuture
that will resolve after the mapper is considered
-
mapFailure
public <TT extends java.lang.Throwable> ListenableFuture<T> mapFailure(java.lang.Class<TT> throwableType, java.util.function.Function<? super TT,? extends T> mapper, java.util.concurrent.Executor executor)
Description copied from interface:ListenableFuture
Similar toListenableFuture.throwMap(Function, Executor)
except this mapper will only be invoked when the future is in a failure state (from either the original computation or an earlier mapper throwing an exception). If this future does resolve in a failure state, and that exception class matches the one provided here. The mapper function will then be provided that throwable, it can then map that throwable back into a result (perhaps anOptional
), or re-throw either the same or a different exception keep the future in a failure state. If the future completes with a normal result, this mapper will be ignored, and the result will be forwarded on without invoking this mapper.- Specified by:
mapFailure
in interfaceListenableFuture<T>
- Type Parameters:
TT
- The type of throwable that should be handled- Parameters:
throwableType
- The class referencing to the type of throwable this mapper handlesmapper
- The mapper to convert a thrown exception to either a result or thrown exceptionexecutor
- Executor to invoke mapper function on, ornull
to invoke on this thread or future complete thread (depending on future state)- Returns:
- A
ListenableFuture
that will resolve after the mapper is considered
-
mapFailure
public <TT extends java.lang.Throwable> ListenableFuture<T> mapFailure(java.lang.Class<TT> throwableType, java.util.function.Function<? super TT,? extends T> mapper, java.util.concurrent.Executor executor, ListenableFuture.ListenerOptimizationStrategy optimizeExecution)
Description copied from interface:ListenableFuture
Similar toListenableFuture.throwMap(Function, Executor, ListenerOptimizationStrategy)
except this mapper will only be invoked when the future is in a failure state (from either the original computation or an earlier mapper throwing an exception). If this future does resolve in a failure state, and that exception class matches the one provided here. The mapper function will then be provided that throwable, it can then map that throwable back into a result perhaps anOptional
), or re-throw either the same or a different exception keep the future in a failure state. If the future completes with a normal result, this mapper will be ignored, and the result will be forwarded on without invoking this mapper.- Specified by:
mapFailure
in interfaceListenableFuture<T>
- Type Parameters:
TT
- The type of throwable that should be handled- Parameters:
throwableType
- The class referencing to the type of throwable this mapper handlesmapper
- The mapper to convert a thrown exception to either a result or thrown exceptionexecutor
- Executor to invoke mapper function on, ornull
to invoke on this thread or future complete thread (depending on future state)optimizeExecution
-true
to avoid listener queuing for execution if already on the desired pool- Returns:
- A
ListenableFuture
that will resolve after the mapper is considered
-
flatMapFailure
public <TT extends java.lang.Throwable> ListenableFuture<T> flatMapFailure(java.lang.Class<TT> throwableType, java.util.function.Function<? super TT,ListenableFuture<T>> mapper)
Description copied from interface:ListenableFuture
Similar toListenableFuture.mapFailure(Class, Function)
except that this mapper function returns aListenableFuture
if it needs to map the Throwable / failure into a result or another failure. The mapper function can return a Future that will (or may) provide a result, or it can provide a future that will result in the same or another failure. Similar toListenableFuture.mapFailure(Class, Function)
the mapper can also throw an exception directly.- Specified by:
flatMapFailure
in interfaceListenableFuture<T>
- Type Parameters:
TT
- The type of throwable that should be handled- Parameters:
throwableType
- The class referencing to the type of throwable this mapper handlesmapper
- Function to invoke in order to transform the futures result- Returns:
- A
ListenableFuture
that will resolve after the mapper is considered
-
flatMapFailure
public <TT extends java.lang.Throwable> ListenableFuture<T> flatMapFailure(java.lang.Class<TT> throwableType, java.util.function.Function<? super TT,ListenableFuture<T>> mapper, java.util.concurrent.Executor executor)
Description copied from interface:ListenableFuture
Similar toListenableFuture.mapFailure(Class, Function, Executor)
except that this mapper function returns aListenableFuture
if it needs to map the Throwable / failure into a result or another failure. The mapper function can return a Future that will (or may) provide a result, or it can provide a future that will result in the same or another failure. Similar toListenableFuture.mapFailure(Class, Function, Executor)
the mapper can also throw an exception directly.- Specified by:
flatMapFailure
in interfaceListenableFuture<T>
- Type Parameters:
TT
- The type of throwable that should be handled- Parameters:
throwableType
- The class referencing to the type of throwable this mapper handlesmapper
- Function to invoke in order to transform the futures resultexecutor
- Executor to invoke mapper function on, ornull
to invoke on this thread or future complete thread (depending on future state)- Returns:
- A
ListenableFuture
that will resolve after the mapper is considered
-
flatMapFailure
public <TT extends java.lang.Throwable> ListenableFuture<T> flatMapFailure(java.lang.Class<TT> throwableType, java.util.function.Function<? super TT,ListenableFuture<T>> mapper, java.util.concurrent.Executor executor, ListenableFuture.ListenerOptimizationStrategy optimizeExecution)
Description copied from interface:ListenableFuture
Similar toListenableFuture.mapFailure(Class, Function, Executor, ListenerOptimizationStrategy)
except that this mapper function returns aListenableFuture
if it needs to map the Throwable into a result or another failure. The mapper function can return a Future that will (or may) provide a result, or it can provide a future that will result in the same or another failure. Similar toListenableFuture.mapFailure(Class, Function, Executor, ListenerOptimizationStrategy)
the mapper can also throw an exception directly.- Specified by:
flatMapFailure
in interfaceListenableFuture<T>
- Type Parameters:
TT
- The type of throwable that should be handled- Parameters:
throwableType
- The class referencing to the type of throwable this mapper handlesmapper
- Function to invoke in order to transform the futures resultexecutor
- Executor to invoke mapper function on, ornull
to invoke on this thread or future complete thread (depending on future state)optimizeExecution
-true
to avoid listener queuing for execution if already on the desired pool- Returns:
- A
ListenableFuture
that will resolve after the mapper is considered
-
callback
public ListenableFuture<T> callback(FutureCallback<? super T> callback, java.util.concurrent.Executor executor, ListenableFuture.ListenerOptimizationStrategy optimize)
Description copied from interface:ListenableFuture
Add aFutureCallback
to be called once the future has completed. If the future has already finished, this will be called immediately.If the provided
Executor
is null, the callback will execute on the thread which computed the original future (once it is done). If the future has already completed, the callback will execute immediately on the thread which is adding the callback.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 seeListenableFuture.ListenerOptimizationStrategy
javadocs for more specific details of what optimizations are available.If you only care about the success result case please see
ListenableFuture.resultCallback(Consumer, Executor, ListenerOptimizationStrategy)
or conversely if you only want to be invoked for failure cases please seeListenableFuture.failureCallback(Consumer, Executor, ListenerOptimizationStrategy)
.- Parameters:
callback
- to be invoked when the computation is completeexecutor
-Executor
the callback should be ran on, ornull
optimize
-true
to avoid listener queuing for execution if already on the desired pool- Returns:
- Exactly
this
instance to add more callbacks or other functional operations
-
resultCallback
public ListenableFuture<T> resultCallback(java.util.function.Consumer<? super T> callback, java.util.concurrent.Executor executor, ListenableFuture.ListenerOptimizationStrategy optimize)
Description copied from interface:ListenableFuture
Add aConsumer
to be called once the future has completed. If the future has already finished, this will be called immediately. Assuming the future has completed without error, the result will be provided to theConsumer
, otherwise it will go un-invoked.If the provided
Executor
is null, the callback will execute on the thread which computed the original future (once it is done). If the future has already completed, the callback will execute immediately on the thread which is adding the callback.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 seeListenableFuture.ListenerOptimizationStrategy
javadocs for more specific details of what optimizations are available.- Parameters:
callback
- to be invoked when the computation is completeexecutor
-Executor
the callback should be ran on, ornull
optimize
-true
to avoid listener queuing for execution if already on the desired pool- Returns:
- Exactly
this
instance to add more callbacks or other functional operations
-
failureCallback
public ListenableFuture<T> failureCallback(java.util.function.Consumer<java.lang.Throwable> callback, java.util.concurrent.Executor executor, ListenableFuture.ListenerOptimizationStrategy optimize)
Description copied from interface:ListenableFuture
Add aConsumer
to be called once the future has completed. If the future has already finished, this will be called immediately. Assuming the future has completed with an error, theThrowable
will be provided to theConsumer
, otherwise if no error occurred, the callback will go un-invoked.If the provided
Executor
is null, the callback will execute on the thread which computed the original future (once it is done). If the future has already completed, the callback will execute immediately on the thread which is adding the callback.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 seeListenableFuture.ListenerOptimizationStrategy
javadocs for more specific details of what optimizations are available.- Parameters:
callback
- to be invoked when the computation is completeexecutor
-Executor
the callback should be ran on, ornull
optimize
-true
to avoid listener queuing for execution if already on the desired pool- Returns:
- Exactly
this
instance to add more callbacks or other functional operations
-
get
public T get()
-
get
public T get(long timeout, java.util.concurrent.TimeUnit unit)
-
getFailure
public java.lang.Throwable getFailure()
Description copied from interface:ListenableFuture
Similar toFuture.get()
except instead of providing a result, this will provide a thrown exception ifListenableFuture.isCompletedExceptionally()
returnstrue
. If the future has not completed yet this function will block until completion. If the future completed normally, this will returnnull
.- Returns:
- Throwable thrown in computing the future or
null
if completed normally
-
getFailure
public java.lang.Throwable getFailure(long timeout, java.util.concurrent.TimeUnit unit)
Description copied from interface:ListenableFuture
Similar toFuture.get(long, TimeUnit)
except instead of providing a result, this will provide a thrown exception ifListenableFuture.isCompletedExceptionally()
returnstrue
. If the future has not completed yet this function will block until completion. If the future completed normally, this will returnnull
.- Parameters:
timeout
- The maximum time to waitunit
- The time unit of the timeout argument- Returns:
- Throwable thrown in computing the future or
null
if completed normally
-
isDone
public boolean isDone()
- Specified by:
isDone
in interfacejava.util.concurrent.Future<T>
-
listener
public ListenableFuture<T> listener(java.lang.Runnable listener)
Description copied from interface:ListenableFuture
Add a listener to be called once the future has completed. If the future has already finished, this will be called immediately.The listener from this call will execute on the same thread the result was produced on, or on the adding thread if the future is already complete. If the runnable has high complexity, consider using
ListenableFuture.listener(Runnable, Executor)
.- Specified by:
listener
in interfaceListenableFuture<T>
- Parameters:
listener
- the listener to run when the computation is complete- Returns:
- Exactly
this
instance to add more listeners or other functional operations
-
listener
public ListenableFuture<T> listener(java.lang.Runnable listener, java.util.concurrent.Executor executor, ListenableFuture.ListenerOptimizationStrategy optimize)
Description copied from interface:ListenableFuture
Add a listener to be called once the future has completed. If the future has already finished, this will be called immediately.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 seeListenableFuture.ListenerOptimizationStrategy
javadocs for more specific details of what optimizations are available.- Specified by:
listener
in interfaceListenableFuture<T>
- Parameters:
listener
- the listener to run when the computation is completeexecutor
-Executor
the listener should be ran on, ornull
optimize
-true
to avoid listener queuing for execution if already on the desired pool- Returns:
- Exactly
this
instance to add more listeners or other functional operations
-
getRunningStackTrace
public java.lang.StackTraceElement[] getRunningStackTrace()
Description copied from interface:ListenableFuture
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 ofListenableFuture.map(Function)
or similar functions. If there is no thread executing the future yet, or the future has already completed, then this will returnnull
.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.
- Specified by:
getRunningStackTrace
in interfaceListenableFuture<T>
- Returns:
- The stack trace currently executing the future, or
null
if unavailable
-
cancel
public boolean cancel(boolean mayInterruptIfRunning)
This has no effect in this implementation, as this future can not be canceled.- Specified by:
cancel
in interfacejava.util.concurrent.Future<T>
- Parameters:
mayInterruptIfRunning
- will be ignored- Returns:
- will always return
false
, as this future can't be canceled
-
isCancelled
public boolean isCancelled()
- Specified by:
isCancelled
in interfacejava.util.concurrent.Future<T>
-
-