Class SettableListenableFuture<T>
- java.lang.Object
-
- org.threadly.concurrent.future.SettableListenableFuture<T>
-
- Type Parameters:
T
- The result object type returned by this future
- All Implemented Interfaces:
java.util.concurrent.Future<T>
,FutureCallback<T>
,ListenableFuture<T>
public class SettableListenableFuture<T> extends java.lang.Object implements ListenableFuture<T>, FutureCallback<T>
This class is designed to be a helper when returning a single result asynchronously. This is particularly useful if this result is produced over multiple threads (and thus the scheduler returned future is not useful).- Since:
- 1.2.0
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface org.threadly.concurrent.future.ListenableFuture
ListenableFuture.ListenerOptimizationStrategy
-
-
Constructor Summary
Constructors Constructor Description SettableListenableFuture()
Constructs a newSettableListenableFuture
.SettableListenableFuture(boolean throwIfAlreadyComplete)
Constructs a newSettableListenableFuture
.
-
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 interrupt)
void
clearResult()
Clears the stored result from this set future.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.void
handleFailure(java.lang.Throwable t)
This call defers tosetFailure(Throwable)
.void
handleResult(T result)
This call defers tosetResult(Object)
.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, 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.boolean
setFailure(java.lang.Throwable failure)
Call to indicate this future is done, and provide the occurred failure.boolean
setResult(T result)
Call to indicate this future is done, and provide the given result.void
setRunningThread(java.lang.Thread thread)
Optional call to set the thread internally that will be generating the result for this future.java.lang.String
toString()
-
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface org.threadly.concurrent.future.ListenableFuture
callback, callback, callback, failureCallback, failureCallback, failureCallback, flatMap, flatMap, flatMap, flatMap, flatMapFailure, flatMapFailure, flatMapFailure, getFailure, getFailure, getRunningStackTrace, isCompletedExceptionally, listener, listener, listener, map, map, map, mapFailure, mapFailure, mapFailure, resultCallback, resultCallback, resultCallback, throwMap, throwMap, throwMap
-
-
-
-
Constructor Detail
-
SettableListenableFuture
public SettableListenableFuture()
Constructs a newSettableListenableFuture
. You can return this immediately and provide a result to the object later when it is ready.This defaults in the behavior since version 1.2.0 where if the future has completed (either by
Future.cancel(boolean)
,setResult(Object)
, orsetFailure(Throwable)
), any additional attempts tosetResult(Object)
orsetFailure(Throwable)
will result in aIllegalStateException
being thrown.
-
SettableListenableFuture
public SettableListenableFuture(boolean throwIfAlreadyComplete)
Constructs a newSettableListenableFuture
. You can return this immediately and provide a result to the object later when it is ready.This constructor allows you to control the behavior when results are attempt to be set after the future has already completed (either by
Future.cancel(boolean)
,setResult(Object)
, orsetFailure(Throwable)
).If
true
, any additional attempts tosetResult(Object)
orsetFailure(Throwable)
will result in aIllegalStateException
being thrown.If
false
, additional attempts to set a result will just be silently ignored.- Parameters:
throwIfAlreadyComplete
- Defines the behavior when result or failure is set on a completed future
-
-
Method Detail
-
handleResult
public void handleResult(T result)
This call defers tosetResult(Object)
. It is implemented so that you can construct this, return it immediately, but only later provide this as a callback to anotherListenableFuture
implementation.This should never be invoked by the implementor, this should only be invoked by other
ListenableFuture
's through the use of providing this toListenableFuture.callback(FutureCallback)
.If this is being used to chain together
ListenableFuture
's,setResult(Object)
/setFailure(Throwable)
should never be called manually (or an exception will occur).- Specified by:
handleResult
in interfaceFutureCallback<T>
- Parameters:
result
- Result object to provide to the future to be returned fromFuture.get()
call
-
handleFailure
public void handleFailure(java.lang.Throwable t)
This call defers tosetFailure(Throwable)
. It is implemented so that you can construct this, return it immediately, but only later provide this as a callback to anotherListenableFuture
implementation. If the parent chained future was canceled this implementation will attempt to cancel the future as well.This should never be invoked by the implementor, this should only be invoked by other
ListenableFuture
's through the use of providing this toListenableFuture.callback(FutureCallback)
.If this is being used to chain together
ListenableFuture
's,setResult(Object)
/setFailure(Throwable)
should never be called manually (or an exception will occur).- Specified by:
handleFailure
in interfaceFutureCallback<T>
- Parameters:
t
- Throwable to be provided as the cause from the ExecutionException thrown fromFuture.get()
call
-
setResult
public boolean setResult(T result)
Call to indicate this future is done, and provide the given result. It is expected that only this orsetFailure(Throwable)
are called.If future has already completed and constructed with
SettableListenableFuture()
ortrue
provided toSettableListenableFuture(boolean)
this will throw anIllegalStateException
. If complete but constructed with afalse
this result will be ignored.- Parameters:
result
- result to provide forFuture.get()
call, can benull
- Returns:
true
if the result was set (ie future did not complete in failure or cancel}
-
setFailure
public boolean setFailure(java.lang.Throwable failure)
Call to indicate this future is done, and provide the occurred failure. It is expected that only this orsetResult(Object)
are called, and only called once. If the provided failure isnull
, a newException
will be created so that something is always provided in theExecutionException
on calls toFuture.get()
.If the future has already completed and constructed with
SettableListenableFuture()
ortrue
provided toSettableListenableFuture(boolean)
this will throw anIllegalStateException
. If complete but constructed with afalse
this failure result will be ignored.- Parameters:
failure
- Throwable that caused failure during computation.- Returns:
true
if the failure was set (ie future did not complete with result or cancel}
-
setRunningThread
public void setRunningThread(java.lang.Thread thread)
Optional call to set the thread internally that will be generating the result for this future. Setting this thread allows it so that if aFuture.cancel(boolean)
call is invoked withtrue
, we can send an interrupt to this thread.The reference to this thread will be cleared after this future has completed (thus allowing it to be garbage collected).
- Parameters:
thread
- Thread that is generating the result for this future
-
clearResult
public void clearResult()
Clears the stored result from this set future. This allows the result to be available for garbage collection. After this call, future calls toFuture.get()
will throw anIllegalStateException
. So it is critical that this is only called after you are sure no future calls to get the result on this future will be attempted.The design of this is so that if you want to chain
ListenableFuture
's together, you can clear the results of old ones after their result has been consumed. This is really only useful in very specific instances.WARNING, this may produce some unexpected behaviors. For example if the result is being pulled while this is concurrently invoked a
null
result may be returned when a result was previously available. In additionFuture.get()
andListenableFuture.callback(FutureCallback)
attempt to reliably error in this condition butListenableFuture.failureCallback(Consumer)
andListenableFuture.resultCallback(Consumer)
do not.ListenableFuture.failureCallback(Consumer)
will only show the unexpected clearResult state if the future had finished in a failure condition we can't report. AndListenableFuture.resultCallback(Consumer)
will always be a no-op after clearing. In short BE CAUTIOUS, only use this if you are certain the result or failure wont be re-queried and you understand the risks.
-
cancel
public boolean cancel(boolean interrupt)
-
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.- 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.
- Returns:
- The stack trace currently executing the future, or
null
if unavailable
-
isCancelled
public boolean isCancelled()
-
isDone
public boolean isDone()
-
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
-
get
public T get() throws java.lang.InterruptedException, java.util.concurrent.ExecutionException
- Throws:
java.lang.InterruptedException
java.util.concurrent.ExecutionException
-
get
public T get(long timeout, java.util.concurrent.TimeUnit unit) throws java.lang.InterruptedException, java.util.concurrent.ExecutionException, java.util.concurrent.TimeoutException
- Throws:
java.lang.InterruptedException
java.util.concurrent.ExecutionException
java.util.concurrent.TimeoutException
-
getFailure
public java.lang.Throwable getFailure() throws java.lang.InterruptedException
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 - Throws:
java.lang.InterruptedException
- If the current thread was interrupted while blocking
-
getFailure
public java.lang.Throwable getFailure(long timeout, java.util.concurrent.TimeUnit unit) throws java.lang.InterruptedException, java.util.concurrent.TimeoutException
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 - Throws:
java.lang.InterruptedException
- If the current thread was interrupted while blockingjava.util.concurrent.TimeoutException
- If the timeout was reached before the future completed
-
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
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
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
-
-