Class FuturesExtra
ListenableFuture interface.-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interfaceImplementations of this interface is used inĀsyncTransform2(com.google.common.util.concurrent.ListenableFuture<A>, com.google.common.util.concurrent.ListenableFuture<B>, com.spotify.futures.FuturesExtra.Function2<Z, ? super A, ? super B>)to asynchronously transform two values into a return value.static interfacestatic interfacestatic interfacestatic interfacestatic interfaceRepresents an operation that accepts a single input argument and returns no result.static interfaceImplementations of this interface is used to synchronously transform the input values into an output value.static interfaceImplementations of this interface is used to synchronously transform the input values into an output value.static interfaceImplementations of this interface is used to synchronously transform the input values into an output value.static interfaceImplementations of this interface is used to synchronously transform the input values into an output value.static interfaceImplementations of this interface is used to synchronously transform the input values into an output value. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic <T> voidaddCallback(com.google.common.util.concurrent.ListenableFuture<T> future, FuturesExtra.Consumer<? super T> success, FuturesExtra.Consumer<Throwable> failure) A lambda-friendly way to attach callbacks to aListenableFuture.static <T> voidaddCallback(com.google.common.util.concurrent.ListenableFuture<T> future, FuturesExtra.Consumer<? super T> success, FuturesExtra.Consumer<Throwable> failure, Executor executor) A lambda-friendly way to attach callbacks to aListenableFuture.static <T> voidaddFailureCallback(com.google.common.util.concurrent.ListenableFuture<T> future, FuturesExtra.Consumer<Throwable> consumer) A lambda-friendly way to attach a callback to aListenableFuture.static <T> voidaddFailureCallback(com.google.common.util.concurrent.ListenableFuture<T> future, FuturesExtra.Consumer<Throwable> consumer, Executor executor) A lambda-friendly way to attach a callback to aListenableFuture.static <T> voidaddSuccessCallback(com.google.common.util.concurrent.ListenableFuture<T> future, FuturesExtra.Consumer<? super T> consumer) A lambda-friendly way to attach a callback to aListenableFuture.static <T> voidaddSuccessCallback(com.google.common.util.concurrent.ListenableFuture<T> future, FuturesExtra.Consumer<? super T> consumer, Executor executor) A lambda-friendly way to attach a callback to aListenableFuture.static <I,O> com.google.common.util.concurrent.ListenableFuture<O> asyncTransform(com.google.common.util.concurrent.ListenableFuture<I> input, com.google.common.util.concurrent.AsyncFunction<? super I, ? extends O> function) Wrapper function forFutures.transformAsync(ListenableFuture, AsyncFunction, Executor).static <Z,A, B> com.google.common.util.concurrent.ListenableFuture<Z> asyncTransform2(com.google.common.util.concurrent.ListenableFuture<A> a, com.google.common.util.concurrent.ListenableFuture<B> b, FuturesExtra.AsyncFunction2<Z, ? super A, ? super B> function) Transform the input futures into a single future, using the provided transform function.static <Z,A, B> com.google.common.util.concurrent.ListenableFuture<Z> asyncTransform2(com.google.common.util.concurrent.ListenableFuture<A> a, com.google.common.util.concurrent.ListenableFuture<B> b, FuturesExtra.AsyncFunction2<Z, ? super A, ? super B> function, Executor executor) Transform the input futures into a single future, using the provided transform function.static <Z,A, B, C> com.google.common.util.concurrent.ListenableFuture<Z> asyncTransform3(com.google.common.util.concurrent.ListenableFuture<A> a, com.google.common.util.concurrent.ListenableFuture<B> b, com.google.common.util.concurrent.ListenableFuture<C> c, FuturesExtra.AsyncFunction3<Z, ? super A, ? super B, ? super C> function) Transform the input futures into a single future, using the provided transform function.static <Z,A, B, C> com.google.common.util.concurrent.ListenableFuture<Z> asyncTransform3(com.google.common.util.concurrent.ListenableFuture<A> a, com.google.common.util.concurrent.ListenableFuture<B> b, com.google.common.util.concurrent.ListenableFuture<C> c, FuturesExtra.AsyncFunction3<Z, ? super A, ? super B, ? super C> function, Executor executor) Transform the input futures into a single future, using the provided transform function.static <Z,A, B, C, D>
com.google.common.util.concurrent.ListenableFuture<Z>asyncTransform4(com.google.common.util.concurrent.ListenableFuture<A> a, com.google.common.util.concurrent.ListenableFuture<B> b, com.google.common.util.concurrent.ListenableFuture<C> c, com.google.common.util.concurrent.ListenableFuture<D> d, FuturesExtra.AsyncFunction4<Z, ? super A, ? super B, ? super C, ? super D> function) Transform the input futures into a single future, using the provided transform function.static <Z,A, B, C, D>
com.google.common.util.concurrent.ListenableFuture<Z>asyncTransform4(com.google.common.util.concurrent.ListenableFuture<A> a, com.google.common.util.concurrent.ListenableFuture<B> b, com.google.common.util.concurrent.ListenableFuture<C> c, com.google.common.util.concurrent.ListenableFuture<D> d, FuturesExtra.AsyncFunction4<Z, ? super A, ? super B, ? super C, ? super D> function, Executor executor) Transform the input futures into a single future, using the provided transform function.static <Z,A, B, C, D, E>
com.google.common.util.concurrent.ListenableFuture<Z>asyncTransform5(com.google.common.util.concurrent.ListenableFuture<A> a, com.google.common.util.concurrent.ListenableFuture<B> b, com.google.common.util.concurrent.ListenableFuture<C> c, com.google.common.util.concurrent.ListenableFuture<D> d, com.google.common.util.concurrent.ListenableFuture<E> e, FuturesExtra.AsyncFunction5<Z, ? super A, ? super B, ? super C, ? super D, ? super E> function) Transform the input futures into a single future, using the provided transform function.static <Z,A, B, C, D, E>
com.google.common.util.concurrent.ListenableFuture<Z>asyncTransform5(com.google.common.util.concurrent.ListenableFuture<A> a, com.google.common.util.concurrent.ListenableFuture<B> b, com.google.common.util.concurrent.ListenableFuture<C> c, com.google.common.util.concurrent.ListenableFuture<D> d, com.google.common.util.concurrent.ListenableFuture<E> e, FuturesExtra.AsyncFunction5<Z, ? super A, ? super B, ? super C, ? super D, ? super E> function, Executor executor) Transform the input futures into a single future, using the provided transform function.static <Z,A, B, C, D, E, F>
com.google.common.util.concurrent.ListenableFuture<Z>asyncTransform6(com.google.common.util.concurrent.ListenableFuture<A> a, com.google.common.util.concurrent.ListenableFuture<B> b, com.google.common.util.concurrent.ListenableFuture<C> c, com.google.common.util.concurrent.ListenableFuture<D> d, com.google.common.util.concurrent.ListenableFuture<E> e, com.google.common.util.concurrent.ListenableFuture<F> f, FuturesExtra.AsyncFunction6<Z, ? super A, ? super B, ? super C, ? super D, ? super E, ? super F> function) Transform the input futures into a single future, using the provided transform function.static <Z,A, B, C, D, E, F>
com.google.common.util.concurrent.ListenableFuture<Z>asyncTransform6(com.google.common.util.concurrent.ListenableFuture<A> a, com.google.common.util.concurrent.ListenableFuture<B> b, com.google.common.util.concurrent.ListenableFuture<C> c, com.google.common.util.concurrent.ListenableFuture<D> d, com.google.common.util.concurrent.ListenableFuture<E> e, com.google.common.util.concurrent.ListenableFuture<F> f, FuturesExtra.AsyncFunction6<Z, ? super A, ? super B, ? super C, ? super D, ? super E, ? super F> function, Executor executor) Transform the input futures into a single future, using the provided transform function.static <T> voidcheckCompleted(com.google.common.util.concurrent.ListenableFuture<T> future) check that a future is completed.static <A,B> com.google.common.util.concurrent.ListenableFuture<A> fastFail(com.google.common.util.concurrent.ListenableFuture<B> conditionValue, com.google.common.util.concurrent.ListenableFuture<A> future, Validator<B> validator) This takes two futures of typeFuturesExtraandFuturesExtraand works like a valve onFuturesExtra, with validation executed onFuturesExtra.static <A,B> com.google.common.util.concurrent.ListenableFuture<A> fastFail(com.google.common.util.concurrent.ListenableFuture<B> conditionValue, com.google.common.util.concurrent.ListenableFuture<A> future, Validator<B> validator, Executor executor) This takes two futures of typeFuturesExtraandFuturesExtraand works like a valve onFuturesExtra, with validation executed onFuturesExtra.static <T> TgetCompleted(com.google.common.util.concurrent.ListenableFuture<T> future) Get the value of a completed future.static <T> ThrowablegetException(com.google.common.util.concurrent.ListenableFuture<T> future) Get the exception of a completed future.static com.google.common.util.concurrent.ListenableFuture<JoinedResults>join(com.google.common.util.concurrent.ListenableFuture<?>... inputs) Transform a list of futures to a future that returns a joined result of them all.static com.google.common.util.concurrent.ListenableFuture<JoinedResults>Transform a list of futures to a future that returns a joined result of them all.static com.google.common.util.concurrent.ListenableFuture<JoinedResults>join(Executor executor, List<? extends com.google.common.util.concurrent.ListenableFuture<?>> inputs) Transform a list of futures to a future that returns a joined result of them all.static com.google.common.util.concurrent.ListenableFuture<JoinedResults>Transform a list of futures to a future that returns a joined result of them all.static <T> com.google.common.util.concurrent.ListenableFuture<T>makeTimeoutFuture(ScheduledExecutorService scheduledExecutorService, com.google.common.util.concurrent.ListenableFuture<T> future, long timeout, TimeUnit unit) Returns a future that fails with aTimeoutExceptionif the parent future has not finished before the timeout.static <T> com.google.common.util.concurrent.ListenableFuture<T>Returns a newListenableFuturewith the result of the first of futures that successfully completes.static <T> com.google.common.util.concurrent.ListenableFuture<T>select(List<? extends com.google.common.util.concurrent.ListenableFuture<T>> futures, Executor executor) Returns a newListenableFuturewith the result of the first of futures that successfully completes.static <I,O> com.google.common.util.concurrent.ListenableFuture<O> syncTransform(com.google.common.util.concurrent.ListenableFuture<I> input, com.google.common.base.Function<? super I, ? extends O> function) Wrapper function forFutures.transform(ListenableFuture, Function, Executor).static <Z,A, B> com.google.common.util.concurrent.ListenableFuture<Z> syncTransform2(com.google.common.util.concurrent.ListenableFuture<A> a, com.google.common.util.concurrent.ListenableFuture<B> b, FuturesExtra.Function2<Z, ? super A, ? super B> function) Transform the input futures into a single future, using the provided transform function.static <Z,A, B> com.google.common.util.concurrent.ListenableFuture<Z> syncTransform2(com.google.common.util.concurrent.ListenableFuture<A> a, com.google.common.util.concurrent.ListenableFuture<B> b, FuturesExtra.Function2<Z, ? super A, ? super B> function, Executor executor) Transform the input futures into a single future, using the provided transform function.static <Z,A, B, C> com.google.common.util.concurrent.ListenableFuture<Z> syncTransform3(com.google.common.util.concurrent.ListenableFuture<A> a, com.google.common.util.concurrent.ListenableFuture<B> b, com.google.common.util.concurrent.ListenableFuture<C> c, FuturesExtra.Function3<Z, ? super A, ? super B, ? super C> function) Transform the input futures into a single future, using the provided transform function.static <Z,A, B, C> com.google.common.util.concurrent.ListenableFuture<Z> syncTransform3(com.google.common.util.concurrent.ListenableFuture<A> a, com.google.common.util.concurrent.ListenableFuture<B> b, com.google.common.util.concurrent.ListenableFuture<C> c, FuturesExtra.Function3<Z, ? super A, ? super B, ? super C> function, Executor executor) Transform the input futures into a single future, using the provided transform function.static <Z,A, B, C, D>
com.google.common.util.concurrent.ListenableFuture<Z>syncTransform4(com.google.common.util.concurrent.ListenableFuture<A> a, com.google.common.util.concurrent.ListenableFuture<B> b, com.google.common.util.concurrent.ListenableFuture<C> c, com.google.common.util.concurrent.ListenableFuture<D> d, FuturesExtra.Function4<Z, ? super A, ? super B, ? super C, ? super D> function) Transform the input futures into a single future, using the provided transform function.static <Z,A, B, C, D>
com.google.common.util.concurrent.ListenableFuture<Z>syncTransform4(com.google.common.util.concurrent.ListenableFuture<A> a, com.google.common.util.concurrent.ListenableFuture<B> b, com.google.common.util.concurrent.ListenableFuture<C> c, com.google.common.util.concurrent.ListenableFuture<D> d, FuturesExtra.Function4<Z, ? super A, ? super B, ? super C, ? super D> function, Executor executor) Transform the input futures into a single future, using the provided transform function.static <Z,A, B, C, D, E>
com.google.common.util.concurrent.ListenableFuture<Z>syncTransform5(com.google.common.util.concurrent.ListenableFuture<A> a, com.google.common.util.concurrent.ListenableFuture<B> b, com.google.common.util.concurrent.ListenableFuture<C> c, com.google.common.util.concurrent.ListenableFuture<D> d, com.google.common.util.concurrent.ListenableFuture<E> e, FuturesExtra.Function5<Z, ? super A, ? super B, ? super C, ? super D, ? super E> function) Transform the input futures into a single future, using the provided transform function.static <Z,A, B, C, D, E>
com.google.common.util.concurrent.ListenableFuture<Z>syncTransform5(com.google.common.util.concurrent.ListenableFuture<A> a, com.google.common.util.concurrent.ListenableFuture<B> b, com.google.common.util.concurrent.ListenableFuture<C> c, com.google.common.util.concurrent.ListenableFuture<D> d, com.google.common.util.concurrent.ListenableFuture<E> e, FuturesExtra.Function5<Z, ? super A, ? super B, ? super C, ? super D, ? super E> function, Executor executor) Transform the input futures into a single future, using the provided transform function.static <Z,A, B, C, D, E, F>
com.google.common.util.concurrent.ListenableFuture<Z>syncTransform6(com.google.common.util.concurrent.ListenableFuture<A> a, com.google.common.util.concurrent.ListenableFuture<B> b, com.google.common.util.concurrent.ListenableFuture<C> c, com.google.common.util.concurrent.ListenableFuture<D> d, com.google.common.util.concurrent.ListenableFuture<E> e, com.google.common.util.concurrent.ListenableFuture<F> f, FuturesExtra.Function6<Z, ? super A, ? super B, ? super C, ? super D, ? super E, ? super F> function) Transform the input futures into a single future, using the provided transform function.static <Z,A, B, C, D, E, F>
com.google.common.util.concurrent.ListenableFuture<Z>syncTransform6(com.google.common.util.concurrent.ListenableFuture<A> a, com.google.common.util.concurrent.ListenableFuture<B> b, com.google.common.util.concurrent.ListenableFuture<C> c, com.google.common.util.concurrent.ListenableFuture<D> d, com.google.common.util.concurrent.ListenableFuture<E> e, com.google.common.util.concurrent.ListenableFuture<F> f, FuturesExtra.Function6<Z, ? super A, ? super B, ? super C, ? super D, ? super E, ? super F> function, Executor executor) Transform the input futures into a single future, using the provided transform function.private static <Z> com.google.common.util.concurrent.ListenableFuture<Z>transform(List<? extends com.google.common.util.concurrent.ListenableFuture<?>> inputs, com.google.common.base.Function<List<Object>, Z> function, Executor executor) private static <Z> com.google.common.util.concurrent.ListenableFuture<Z>transform(List<? extends com.google.common.util.concurrent.ListenableFuture<?>> inputs, com.google.common.util.concurrent.AsyncFunction<List<Object>, Z> function, Executor executor)
-
Constructor Details
-
FuturesExtra
public FuturesExtra()
-
-
Method Details
-
makeTimeoutFuture
public static <T> com.google.common.util.concurrent.ListenableFuture<T> makeTimeoutFuture(ScheduledExecutorService scheduledExecutorService, com.google.common.util.concurrent.ListenableFuture<T> future, long timeout, TimeUnit unit) Returns a future that fails with aTimeoutExceptionif the parent future has not finished before the timeout. The new returned future will always be executed on the provided scheduledExecutorService, even when the parent future does not timeout.- Parameters:
scheduledExecutorService- executor that runs the timeout code. If the future times out, this is also the thread any callbacks will run on.future- the future to wrap as a timeout future.timeout- how long to wait before timing out a futureunit- unit of the timeout- Returns:
- a future that may timeout before the parent future is done.
-
fastFail
public static <A,B> com.google.common.util.concurrent.ListenableFuture<A> fastFail(com.google.common.util.concurrent.ListenableFuture<B> conditionValue, com.google.common.util.concurrent.ListenableFuture<A> future, Validator<B> validator) This takes two futures of typeFuturesExtraandFuturesExtraand works like a valve onFuturesExtra, with validation executed onFuturesExtra.Returns a future with the result of
FuturesExtrathat will wait for a condition onFuturesExtrato be validated first. Both futures can run in parallel. If the condition fails validation, theFuturesExtrafuture will be cancelled by a call toFuture.cancel(boolean)withfalse.This is useful for when you want to optimistically run a time consuming path while validating if it should be computed or not by a parallel async computation.
- Parameters:
conditionValue- The future computing the value for validation.future- The actual value future.validator- A validator for the condition.- Returns:
- a new
ListenableFutureeventually either containing or any exception thrown by .
-
fastFail
public static <A,B> com.google.common.util.concurrent.ListenableFuture<A> fastFail(com.google.common.util.concurrent.ListenableFuture<B> conditionValue, com.google.common.util.concurrent.ListenableFuture<A> future, Validator<B> validator, Executor executor) This takes two futures of typeFuturesExtraandFuturesExtraand works like a valve onFuturesExtra, with validation executed onFuturesExtra.Returns a future with the result of
FuturesExtrathat will wait for a condition onFuturesExtrato be validated first. Both futures can run in parallel. If the condition fails validation, theFuturesExtrafuture will be cancelled by a call toFuture.cancel(boolean)withfalse.This is useful for when you want to optimistically run a time consuming path while validating if it should be computed or not by a parallel async computation.
- Parameters:
conditionValue- The future computing the value for validation.future- The actual value future.validator- A validator for the condition.executor- An executor to run the validation on.- Returns:
- a new
ListenableFutureeventually either containing or any exception thrown by .
-
select
public static <T> com.google.common.util.concurrent.ListenableFuture<T> select(List<? extends com.google.common.util.concurrent.ListenableFuture<T>> futures) Returns a newListenableFuturewith the result of the first of futures that successfully completes. If all ListenableFutures in futures fails the returned feature fails as well with the Exception of the last failed future. If futures is an empty list the returned future fails immediately withNoSuchElementException- Parameters:
futures- aListof futures- Returns:
- a new future with the result of the first completing future.
- Throws:
NullPointerException- if the is null
-
select
public static <T> com.google.common.util.concurrent.ListenableFuture<T> select(List<? extends com.google.common.util.concurrent.ListenableFuture<T>> futures, Executor executor) Returns a newListenableFuturewith the result of the first of futures that successfully completes. If all ListenableFutures in futures fails the returned feature fails as well with the Exception of the last failed future. If futures is an empty list the returned future fails immediately withNoSuchElementException- Parameters:
futures- aListof futuresexecutor- an executor to run the callback on.- Returns:
- a new future with the result of the first completing future.
- Throws:
NullPointerException- if the is null
-
addCallback
public static <T> void addCallback(com.google.common.util.concurrent.ListenableFuture<T> future, FuturesExtra.Consumer<? super T> success, FuturesExtra.Consumer<Throwable> failure) A lambda-friendly way to attach callbacks to aListenableFuture. The success callback will only be run if the future completes successfully, and failure will only be run if the future fails.- Parameters:
future- a ListenableFuture to attach the callbacks to.success- a consumer, to be called with the result of the successful future.failure- a consumer, to be called with the result of the failed future.- Throws:
NullPointerException- if the and are null
-
addCallback
public static <T> void addCallback(com.google.common.util.concurrent.ListenableFuture<T> future, FuturesExtra.Consumer<? super T> success, FuturesExtra.Consumer<Throwable> failure, Executor executor) A lambda-friendly way to attach callbacks to aListenableFuture. The success callback will only be run if the future completes successfully, and failure will only be run if the future fails.- Parameters:
future- a ListenableFuture to attach the callbacks to.success- a consumer, to be called with the result of the successful future.failure- a consumer, to be called with the result of the failed future.executor- an executor to run the callback on.- Throws:
NullPointerException- if the and are null
-
addSuccessCallback
public static <T> void addSuccessCallback(com.google.common.util.concurrent.ListenableFuture<T> future, FuturesExtra.Consumer<? super T> consumer) A lambda-friendly way to attach a callback to aListenableFuture. The callback will only be run if the future completes successfully.- Parameters:
future- a ListenableFuture to attach the callback to.consumer- a consumer, to be called with the result of the successful future.
-
addSuccessCallback
public static <T> void addSuccessCallback(com.google.common.util.concurrent.ListenableFuture<T> future, FuturesExtra.Consumer<? super T> consumer, Executor executor) A lambda-friendly way to attach a callback to aListenableFuture. The callback will only be run if the future completes successfully.- Parameters:
future- a ListenableFuture to attach the callback to.consumer- a consumer, to be called with the result of the successful future.executor- an executor to run the callback on.
-
addFailureCallback
public static <T> void addFailureCallback(com.google.common.util.concurrent.ListenableFuture<T> future, FuturesExtra.Consumer<Throwable> consumer) A lambda-friendly way to attach a callback to aListenableFuture. The callback will only be run if the future fails.- Parameters:
future- a ListenableFuture to attach the callback to.consumer- a consumer, to be called with the result of the failed future.
-
addFailureCallback
public static <T> void addFailureCallback(com.google.common.util.concurrent.ListenableFuture<T> future, FuturesExtra.Consumer<Throwable> consumer, Executor executor) A lambda-friendly way to attach a callback to aListenableFuture. The callback will only be run if the future fails.- Parameters:
future- a ListenableFuture to attach the callback to.consumer- a consumer, to be called with the result of the failed future.executor- an executor to run the callback on.
-
syncTransform2
public static <Z,A, com.google.common.util.concurrent.ListenableFuture<Z> syncTransform2B> (com.google.common.util.concurrent.ListenableFuture<A> a, com.google.common.util.concurrent.ListenableFuture<B> b, FuturesExtra.Function2<Z, ? super A, ? super B> function) Transform the input futures into a single future, using the provided transform function. The transformation follows the same semantics as asFutures.transform(ListenableFuture, Function, Executor)and the input futures are combined usingFutures.allAsList(com.google.common.util.concurrent.ListenableFuture<? extends V>...).- Parameters:
a- a ListenableFuture to combineb- a ListenableFuture to combinefunction- the implementation of the transform- Returns:
- a ListenableFuture holding the result of function.apply()
-
syncTransform2
public static <Z,A, com.google.common.util.concurrent.ListenableFuture<Z> syncTransform2B> (com.google.common.util.concurrent.ListenableFuture<A> a, com.google.common.util.concurrent.ListenableFuture<B> b, FuturesExtra.Function2<Z, ? super A, ? super B> function, Executor executor) Transform the input futures into a single future, using the provided transform function. The transformation follows the same semantics as asFutures.transform(ListenableFuture, Function, Executor)and the input futures are combined usingFutures.allAsList(com.google.common.util.concurrent.ListenableFuture<? extends V>...).- Parameters:
a- a ListenableFuture to combineb- a ListenableFuture to combinefunction- the implementation of the transformexecutor- an executor to run the function on.- Returns:
- a ListenableFuture holding the result of function.apply()
-
asyncTransform2
public static <Z,A, com.google.common.util.concurrent.ListenableFuture<Z> asyncTransform2B> (com.google.common.util.concurrent.ListenableFuture<A> a, com.google.common.util.concurrent.ListenableFuture<B> b, FuturesExtra.AsyncFunction2<Z, ? super A, ? super B> function) Transform the input futures into a single future, using the provided transform function. The transformation follows the same semantics as asFutures.transformAsync(ListenableFuture, AsyncFunction, Executor)and the input futures are combined usingFutures.allAsList(com.google.common.util.concurrent.ListenableFuture<? extends V>...).- Parameters:
a- a ListenableFuture to combineb- a ListenableFuture to combinefunction- the implementation of the transform- Returns:
- a ListenableFuture holding the result of function.apply()
-
asyncTransform2
public static <Z,A, com.google.common.util.concurrent.ListenableFuture<Z> asyncTransform2B> (com.google.common.util.concurrent.ListenableFuture<A> a, com.google.common.util.concurrent.ListenableFuture<B> b, FuturesExtra.AsyncFunction2<Z, ? super A, ? super B> function, Executor executor) Transform the input futures into a single future, using the provided transform function. The transformation follows the same semantics as asFutures.transformAsync(ListenableFuture, AsyncFunction, Executor)and the input futures are combined usingFutures.allAsList(com.google.common.util.concurrent.ListenableFuture<? extends V>...).- Parameters:
a- a ListenableFuture to combineb- a ListenableFuture to combinefunction- the implementation of the transformexecutor- an executor to run the function on.- Returns:
- a ListenableFuture holding the result of function.apply()
-
syncTransform3
public static <Z,A, com.google.common.util.concurrent.ListenableFuture<Z> syncTransform3B, C> (com.google.common.util.concurrent.ListenableFuture<A> a, com.google.common.util.concurrent.ListenableFuture<B> b, com.google.common.util.concurrent.ListenableFuture<C> c, FuturesExtra.Function3<Z, ? super A, ? super B, ? super C> function) Transform the input futures into a single future, using the provided transform function. The transformation follows the same semantics as asFutures.transform(ListenableFuture, Function, Executor)and the input futures are combined usingFutures.allAsList(com.google.common.util.concurrent.ListenableFuture<? extends V>...).- Parameters:
a- a ListenableFuture to combineb- a ListenableFuture to combinec- a ListenableFuture to combinefunction- the implementation of the transform- Returns:
- a ListenableFuture holding the result of function.apply()
-
syncTransform3
public static <Z,A, com.google.common.util.concurrent.ListenableFuture<Z> syncTransform3B, C> (com.google.common.util.concurrent.ListenableFuture<A> a, com.google.common.util.concurrent.ListenableFuture<B> b, com.google.common.util.concurrent.ListenableFuture<C> c, FuturesExtra.Function3<Z, ? super A, ? super B, ? super C> function, Executor executor) Transform the input futures into a single future, using the provided transform function. The transformation follows the same semantics as asFutures.transform(ListenableFuture, Function, Executor)and the input futures are combined usingFutures.allAsList(com.google.common.util.concurrent.ListenableFuture<? extends V>...).- Parameters:
a- a ListenableFuture to combineb- a ListenableFuture to combinec- a ListenableFuture to combinefunction- the implementation of the transformexecutor- an executor to run the function on.- Returns:
- a ListenableFuture holding the result of function.apply()
-
asyncTransform3
public static <Z,A, com.google.common.util.concurrent.ListenableFuture<Z> asyncTransform3B, C> (com.google.common.util.concurrent.ListenableFuture<A> a, com.google.common.util.concurrent.ListenableFuture<B> b, com.google.common.util.concurrent.ListenableFuture<C> c, FuturesExtra.AsyncFunction3<Z, ? super A, ? super B, ? super C> function) Transform the input futures into a single future, using the provided transform function. The transformation follows the same semantics as asFutures.transformAsync(ListenableFuture, AsyncFunction, Executor)and the input futures are combined usingFutures.allAsList(com.google.common.util.concurrent.ListenableFuture<? extends V>...).- Parameters:
a- a ListenableFuture to combineb- a ListenableFuture to combinec- a ListenableFuture to combinefunction- the implementation of the transform- Returns:
- a ListenableFuture holding the result of function.apply()
-
asyncTransform3
public static <Z,A, com.google.common.util.concurrent.ListenableFuture<Z> asyncTransform3B, C> (com.google.common.util.concurrent.ListenableFuture<A> a, com.google.common.util.concurrent.ListenableFuture<B> b, com.google.common.util.concurrent.ListenableFuture<C> c, FuturesExtra.AsyncFunction3<Z, ? super A, ? super B, ? super C> function, Executor executor) Transform the input futures into a single future, using the provided transform function. The transformation follows the same semantics as asFutures.transformAsync(ListenableFuture, AsyncFunction, Executor)and the input futures are combined usingFutures.allAsList(com.google.common.util.concurrent.ListenableFuture<? extends V>...).- Parameters:
a- a ListenableFuture to combineb- a ListenableFuture to combinec- a ListenableFuture to combinefunction- the implementation of the transformexecutor- an executor to run the function on.- Returns:
- a ListenableFuture holding the result of function.apply()
-
syncTransform4
public static <Z,A, com.google.common.util.concurrent.ListenableFuture<Z> syncTransform4B, C, D> (com.google.common.util.concurrent.ListenableFuture<A> a, com.google.common.util.concurrent.ListenableFuture<B> b, com.google.common.util.concurrent.ListenableFuture<C> c, com.google.common.util.concurrent.ListenableFuture<D> d, FuturesExtra.Function4<Z, ? super A, ? super B, ? super C, ? super D> function) Transform the input futures into a single future, using the provided transform function. The transformation follows the same semantics as asFutures.transform(ListenableFuture, Function, Executor)and the input futures are combined usingFutures.allAsList(com.google.common.util.concurrent.ListenableFuture<? extends V>...).- Parameters:
a- a ListenableFuture to combineb- a ListenableFuture to combinec- a ListenableFuture to combined- a ListenableFuture to combinefunction- the implementation of the transform- Returns:
- a ListenableFuture holding the result of function.apply()
-
syncTransform4
public static <Z,A, com.google.common.util.concurrent.ListenableFuture<Z> syncTransform4B, C, D> (com.google.common.util.concurrent.ListenableFuture<A> a, com.google.common.util.concurrent.ListenableFuture<B> b, com.google.common.util.concurrent.ListenableFuture<C> c, com.google.common.util.concurrent.ListenableFuture<D> d, FuturesExtra.Function4<Z, ? super A, ? super B, ? super C, ? super D> function, Executor executor) Transform the input futures into a single future, using the provided transform function. The transformation follows the same semantics as asFutures.transform(ListenableFuture, Function, Executor)and the input futures are combined usingFutures.allAsList(com.google.common.util.concurrent.ListenableFuture<? extends V>...).- Parameters:
a- a ListenableFuture to combineb- a ListenableFuture to combinec- a ListenableFuture to combined- a ListenableFuture to combinefunction- the implementation of the transformexecutor- an executor to run the function on.- Returns:
- a ListenableFuture holding the result of function.apply()
-
asyncTransform4
public static <Z,A, com.google.common.util.concurrent.ListenableFuture<Z> asyncTransform4B, C, D> (com.google.common.util.concurrent.ListenableFuture<A> a, com.google.common.util.concurrent.ListenableFuture<B> b, com.google.common.util.concurrent.ListenableFuture<C> c, com.google.common.util.concurrent.ListenableFuture<D> d, FuturesExtra.AsyncFunction4<Z, ? super A, ? super B, ? super C, ? super D> function) Transform the input futures into a single future, using the provided transform function. The transformation follows the same semantics as asFutures.transformAsync(ListenableFuture, AsyncFunction, Executor)and the input futures are combined usingFutures.allAsList(com.google.common.util.concurrent.ListenableFuture<? extends V>...).- Parameters:
a- a ListenableFuture to combineb- a ListenableFuture to combinec- a ListenableFuture to combined- a ListenableFuture to combinefunction- the implementation of the transform- Returns:
- a ListenableFuture holding the result of function.apply()
-
asyncTransform4
public static <Z,A, com.google.common.util.concurrent.ListenableFuture<Z> asyncTransform4B, C, D> (com.google.common.util.concurrent.ListenableFuture<A> a, com.google.common.util.concurrent.ListenableFuture<B> b, com.google.common.util.concurrent.ListenableFuture<C> c, com.google.common.util.concurrent.ListenableFuture<D> d, FuturesExtra.AsyncFunction4<Z, ? super A, ? super B, ? super C, ? super D> function, Executor executor) Transform the input futures into a single future, using the provided transform function. The transformation follows the same semantics as asFutures.transformAsync(ListenableFuture, AsyncFunction, Executor)and the input futures are combined usingFutures.allAsList(com.google.common.util.concurrent.ListenableFuture<? extends V>...).- Parameters:
a- a ListenableFuture to combineb- a ListenableFuture to combinec- a ListenableFuture to combined- a ListenableFuture to combinefunction- the implementation of the transformexecutor- an executor to run the function on.- Returns:
- a ListenableFuture holding the result of function.apply()
-
syncTransform5
public static <Z,A, com.google.common.util.concurrent.ListenableFuture<Z> syncTransform5B, C, D, E> (com.google.common.util.concurrent.ListenableFuture<A> a, com.google.common.util.concurrent.ListenableFuture<B> b, com.google.common.util.concurrent.ListenableFuture<C> c, com.google.common.util.concurrent.ListenableFuture<D> d, com.google.common.util.concurrent.ListenableFuture<E> e, FuturesExtra.Function5<Z, ? super A, ? super B, ? super C, ? super D, ? super E> function) Transform the input futures into a single future, using the provided transform function. The transformation follows the same semantics as asFutures.transform(ListenableFuture, Function, Executor)and the input futures are combined usingFutures.allAsList(com.google.common.util.concurrent.ListenableFuture<? extends V>...).- Parameters:
a- a ListenableFuture to combineb- a ListenableFuture to combinec- a ListenableFuture to combined- a ListenableFuture to combinee- a ListenableFuture to combinefunction- the implementation of the transform- Returns:
- a ListenableFuture holding the result of function.apply()
-
syncTransform5
public static <Z,A, com.google.common.util.concurrent.ListenableFuture<Z> syncTransform5B, C, D, E> (com.google.common.util.concurrent.ListenableFuture<A> a, com.google.common.util.concurrent.ListenableFuture<B> b, com.google.common.util.concurrent.ListenableFuture<C> c, com.google.common.util.concurrent.ListenableFuture<D> d, com.google.common.util.concurrent.ListenableFuture<E> e, FuturesExtra.Function5<Z, ? super A, ? super B, ? super C, ? super D, ? super E> function, Executor executor) Transform the input futures into a single future, using the provided transform function. The transformation follows the same semantics as asFutures.transform(ListenableFuture, Function, Executor)and the input futures are combined usingFutures.allAsList(com.google.common.util.concurrent.ListenableFuture<? extends V>...).- Parameters:
a- a ListenableFuture to combineb- a ListenableFuture to combinec- a ListenableFuture to combined- a ListenableFuture to combinee- a ListenableFuture to combinefunction- the implementation of the transformexecutor- an executor to run the function on.- Returns:
- a ListenableFuture holding the result of function.apply()
-
asyncTransform5
public static <Z,A, com.google.common.util.concurrent.ListenableFuture<Z> asyncTransform5B, C, D, E> (com.google.common.util.concurrent.ListenableFuture<A> a, com.google.common.util.concurrent.ListenableFuture<B> b, com.google.common.util.concurrent.ListenableFuture<C> c, com.google.common.util.concurrent.ListenableFuture<D> d, com.google.common.util.concurrent.ListenableFuture<E> e, FuturesExtra.AsyncFunction5<Z, ? super A, ? super B, ? super C, ? super D, ? super E> function) Transform the input futures into a single future, using the provided transform function. The transformation follows the same semantics as asFutures.transformAsync(ListenableFuture, AsyncFunction, Executor)and the input futures are combined usingFutures.allAsList(com.google.common.util.concurrent.ListenableFuture<? extends V>...).- Parameters:
a- a ListenableFuture to combineb- a ListenableFuture to combinec- a ListenableFuture to combined- a ListenableFuture to combinee- a ListenableFuture to combinefunction- the implementation of the transform- Returns:
- a ListenableFuture holding the result of function.apply()
-
asyncTransform5
public static <Z,A, com.google.common.util.concurrent.ListenableFuture<Z> asyncTransform5B, C, D, E> (com.google.common.util.concurrent.ListenableFuture<A> a, com.google.common.util.concurrent.ListenableFuture<B> b, com.google.common.util.concurrent.ListenableFuture<C> c, com.google.common.util.concurrent.ListenableFuture<D> d, com.google.common.util.concurrent.ListenableFuture<E> e, FuturesExtra.AsyncFunction5<Z, ? super A, ? super B, ? super C, ? super D, ? super E> function, Executor executor) Transform the input futures into a single future, using the provided transform function. The transformation follows the same semantics as asFutures.transformAsync(ListenableFuture, AsyncFunction, Executor)and the input futures are combined usingFutures.allAsList(com.google.common.util.concurrent.ListenableFuture<? extends V>...).- Parameters:
a- a ListenableFuture to combineb- a ListenableFuture to combinec- a ListenableFuture to combined- a ListenableFuture to combinee- a ListenableFuture to combinefunction- the implementation of the transformexecutor- an executor to run the function on.- Returns:
- a ListenableFuture holding the result of function.apply()
-
syncTransform6
public static <Z,A, com.google.common.util.concurrent.ListenableFuture<Z> syncTransform6B, C, D, E, F> (com.google.common.util.concurrent.ListenableFuture<A> a, com.google.common.util.concurrent.ListenableFuture<B> b, com.google.common.util.concurrent.ListenableFuture<C> c, com.google.common.util.concurrent.ListenableFuture<D> d, com.google.common.util.concurrent.ListenableFuture<E> e, com.google.common.util.concurrent.ListenableFuture<F> f, FuturesExtra.Function6<Z, ? super A, ? super B, ? super C, ? super D, ? super E, ? super F> function) Transform the input futures into a single future, using the provided transform function. The transformation follows the same semantics as asFutures.transform(ListenableFuture, Function, Executor)and the input futures are combined usingFutures.allAsList(com.google.common.util.concurrent.ListenableFuture<? extends V>...).- Parameters:
a- a ListenableFuture to combineb- a ListenableFuture to combinec- a ListenableFuture to combined- a ListenableFuture to combinee- a ListenableFuture to combinef- a ListenableFuture to combinefunction- the implementation of the transform- Returns:
- a ListenableFuture holding the result of function.apply()
-
syncTransform6
public static <Z,A, com.google.common.util.concurrent.ListenableFuture<Z> syncTransform6B, C, D, E, F> (com.google.common.util.concurrent.ListenableFuture<A> a, com.google.common.util.concurrent.ListenableFuture<B> b, com.google.common.util.concurrent.ListenableFuture<C> c, com.google.common.util.concurrent.ListenableFuture<D> d, com.google.common.util.concurrent.ListenableFuture<E> e, com.google.common.util.concurrent.ListenableFuture<F> f, FuturesExtra.Function6<Z, ? super A, ? super B, ? super C, ? super D, ? super E, ? super F> function, Executor executor) Transform the input futures into a single future, using the provided transform function. The transformation follows the same semantics as asFutures.transform(ListenableFuture, Function, Executor)and the input futures are combined usingFutures.allAsList(com.google.common.util.concurrent.ListenableFuture<? extends V>...).- Parameters:
a- a ListenableFuture to combineb- a ListenableFuture to combinec- a ListenableFuture to combined- a ListenableFuture to combinee- a ListenableFuture to combinef- a ListenableFuture to combinefunction- the implementation of the transformexecutor- an executor to run the function on.- Returns:
- a ListenableFuture holding the result of function.apply()
-
asyncTransform6
public static <Z,A, com.google.common.util.concurrent.ListenableFuture<Z> asyncTransform6B, C, D, E, F> (com.google.common.util.concurrent.ListenableFuture<A> a, com.google.common.util.concurrent.ListenableFuture<B> b, com.google.common.util.concurrent.ListenableFuture<C> c, com.google.common.util.concurrent.ListenableFuture<D> d, com.google.common.util.concurrent.ListenableFuture<E> e, com.google.common.util.concurrent.ListenableFuture<F> f, FuturesExtra.AsyncFunction6<Z, ? super A, ? super B, ? super C, ? super D, ? super E, ? super F> function) Transform the input futures into a single future, using the provided transform function. The transformation follows the same semantics as asFutures.transformAsync(ListenableFuture, AsyncFunction, Executor)and the input futures are combined usingFutures.allAsList(com.google.common.util.concurrent.ListenableFuture<? extends V>...).- Parameters:
a- a ListenableFuture to combineb- a ListenableFuture to combinec- a ListenableFuture to combined- a ListenableFuture to combinee- a ListenableFuture to combinef- a ListenableFuture to combinefunction- the implementation of the transform- Returns:
- a ListenableFuture holding the result of function.apply()
-
asyncTransform6
public static <Z,A, com.google.common.util.concurrent.ListenableFuture<Z> asyncTransform6B, C, D, E, F> (com.google.common.util.concurrent.ListenableFuture<A> a, com.google.common.util.concurrent.ListenableFuture<B> b, com.google.common.util.concurrent.ListenableFuture<C> c, com.google.common.util.concurrent.ListenableFuture<D> d, com.google.common.util.concurrent.ListenableFuture<E> e, com.google.common.util.concurrent.ListenableFuture<F> f, FuturesExtra.AsyncFunction6<Z, ? super A, ? super B, ? super C, ? super D, ? super E, ? super F> function, Executor executor) Transform the input futures into a single future, using the provided transform function. The transformation follows the same semantics as asFutures.transformAsync(ListenableFuture, AsyncFunction, Executor)and the input futures are combined usingFutures.allAsList(com.google.common.util.concurrent.ListenableFuture<? extends V>...).- Parameters:
a- a ListenableFuture to combineb- a ListenableFuture to combinec- a ListenableFuture to combined- a ListenableFuture to combinee- a ListenableFuture to combinef- a ListenableFuture to combinefunction- the implementation of the transformexecutor- an executor to run the function on.- Returns:
- a ListenableFuture holding the result of function.apply()
-
transform
-
transform
-
join
public static com.google.common.util.concurrent.ListenableFuture<JoinedResults> join(List<? extends com.google.common.util.concurrent.ListenableFuture<?>> inputs) Transform a list of futures to a future that returns a joined result of them all. The result can be used to get the joined results and ensures no future that were not part of the join is accessed.- See Also:
-
join
public static com.google.common.util.concurrent.ListenableFuture<JoinedResults> join(Executor executor, List<? extends com.google.common.util.concurrent.ListenableFuture<?>> inputs) Transform a list of futures to a future that returns a joined result of them all. The result can be used to get the joined results and ensures no future that were not part of the join is accessed.- See Also:
-
join
public static com.google.common.util.concurrent.ListenableFuture<JoinedResults> join(com.google.common.util.concurrent.ListenableFuture<?>... inputs) Transform a list of futures to a future that returns a joined result of them all. The result can be used to get the joined results and ensures no future that were not part of the join is accessed.Example
final Future<String> first = Futures.immediateFuture("ok"); final Future<Integer> second = Futures.immediateFuture(1); JoinedResults futures = FuturesExtra.join(first, second).get(); assertEquals("ok", futures.get(first)); assertEquals(1, futures.get(second)); -
join
public static com.google.common.util.concurrent.ListenableFuture<JoinedResults> join(Executor executor, com.google.common.util.concurrent.ListenableFuture<?>... inputs) Transform a list of futures to a future that returns a joined result of them all. The result can be used to get the joined results and ensures no future that were not part of the join is accessed.Example
final Future<String> first = Futures.immediateFuture("ok"); final Future<Integer> second = Futures.immediateFuture(1); JoinedResults futures = FuturesExtra.join(first, second).get(); assertEquals("ok", futures.get(first)); assertEquals(1, futures.get(second)); -
syncTransform
public static <I,O> com.google.common.util.concurrent.ListenableFuture<O> syncTransform(com.google.common.util.concurrent.ListenableFuture<I> input, com.google.common.base.Function<? super I, ? extends O> function) Wrapper function forFutures.transform(ListenableFuture, Function, Executor).- Parameters:
input- the input futurefunction- the implementation of the transform- Returns:
- a ListenableFuture holding the result of function.apply()
-
asyncTransform
public static <I,O> com.google.common.util.concurrent.ListenableFuture<O> asyncTransform(com.google.common.util.concurrent.ListenableFuture<I> input, com.google.common.util.concurrent.AsyncFunction<? super I, ? extends O> function) Wrapper function forFutures.transformAsync(ListenableFuture, AsyncFunction, Executor).- Parameters:
input- the input futurefunction- the implementation of the transform- Returns:
- a ListenableFuture holding the result of function.apply()
-
checkCompleted
public static <T> void checkCompleted(com.google.common.util.concurrent.ListenableFuture<T> future) check that a future is completed.- Parameters:
future- the future.- Throws:
IllegalStateException- if the future is not completed.
-
getCompleted
public static <T> T getCompleted(com.google.common.util.concurrent.ListenableFuture<T> future) Get the value of a completed future.- Parameters:
future- a completed future.- Returns:
- the value of the future if it has one.
- Throws:
IllegalStateException- if the future is not completed.com.google.common.util.concurrent.UncheckedExecutionException- if the future has failed
-
getException
public static <T> Throwable getException(com.google.common.util.concurrent.ListenableFuture<T> future) Get the exception of a completed future.- Parameters:
future- a completed future.- Returns:
- the exception of a future or null if no exception was thrown
- Throws:
IllegalStateException- if the future is not completed.
-