- java.lang.Object
-
- com.spotify.futures.FuturesExtra
-
public class FuturesExtra extends java.lang.ObjectStatic utility methods pertaining to theListenableFutureinterface.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interfaceFuturesExtra.AsyncFunction2<Z,A,B>Implementations 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>, java.util.concurrent.Executor)to asynchronously transform two values into a return value.static interfaceFuturesExtra.AsyncFunction3<Z,A,B,C>static interfaceFuturesExtra.AsyncFunction4<Z,A,B,C,D>static interfaceFuturesExtra.AsyncFunction5<Z,A,B,C,D,E>static interfaceFuturesExtra.AsyncFunction6<Z,A,B,C,D,E,F>static interfaceFuturesExtra.Consumer<T>Represents an operation that accepts a single input argument and returns no result.static interfaceFuturesExtra.Function2<Z,A,B>Implementations of this interface is used to synchronously transform the input values into an output value.static interfaceFuturesExtra.Function3<Z,A,B,C>Implementations of this interface is used to synchronously transform the input values into an output value.static interfaceFuturesExtra.Function4<Z,A,B,C,D>Implementations of this interface is used to synchronously transform the input values into an output value.static interfaceFuturesExtra.Function5<Z,A,B,C,D,E>Implementations of this interface is used to synchronously transform the input values into an output value.static interfaceFuturesExtra.Function6<Z,A,B,C,D,E,F>Implementations of this interface is used to synchronously transform the input values into an output value.
-
Constructor Summary
Constructors Constructor Description FuturesExtra()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static <T> voidaddCallback(com.google.common.util.concurrent.ListenableFuture<T> future, FuturesExtra.Consumer<? super T> success, FuturesExtra.Consumer<java.lang.Throwable> failure, java.util.concurrent.Executor executor)A lambda-friendly way to attach callbacks to aListenableFuture.static <T> voidaddFailureCallback(com.google.common.util.concurrent.ListenableFuture<T> future, FuturesExtra.Consumer<java.lang.Throwable> consumer, java.util.concurrent.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, java.util.concurrent.Executor executor)A lambda-friendly way to attach a callback to aListenableFuture.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, java.util.concurrent.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, java.util.concurrent.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, java.util.concurrent.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, java.util.concurrent.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, java.util.concurrent.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, java.util.concurrent.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> java.lang.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(java.util.concurrent.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.static com.google.common.util.concurrent.ListenableFuture<JoinedResults>join(java.util.concurrent.Executor executor, java.util.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 <T> com.google.common.util.concurrent.ListenableFuture<T>makeTimeoutFuture(java.util.concurrent.ScheduledExecutorService scheduledExecutorService, com.google.common.util.concurrent.ListenableFuture<T> future, long timeout, java.util.concurrent.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>select(java.util.List<? extends com.google.common.util.concurrent.ListenableFuture<T>> futures, java.util.concurrent.Executor executor)Returns a newListenableFuturewith the result of the first of futures that successfully completes.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, java.util.concurrent.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, java.util.concurrent.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, java.util.concurrent.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, java.util.concurrent.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, java.util.concurrent.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(java.util.List<? extends com.google.common.util.concurrent.ListenableFuture<?>> inputs, com.google.common.base.Function<java.util.List<java.lang.Object>,Z> function, java.util.concurrent.Executor executor)private static <Z> com.google.common.util.concurrent.ListenableFuture<Z>transform(java.util.List<? extends com.google.common.util.concurrent.ListenableFuture<?>> inputs, com.google.common.util.concurrent.AsyncFunction<java.util.List<java.lang.Object>,Z> function, java.util.concurrent.Executor executor)
-
-
-
Method Detail
-
makeTimeoutFuture
public static <T> com.google.common.util.concurrent.ListenableFuture<T> makeTimeoutFuture(java.util.concurrent.ScheduledExecutorService scheduledExecutorService, com.google.common.util.concurrent.ListenableFuture<T> future, long timeout, java.util.concurrent.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, java.util.concurrent.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.- Returns:
- a new
ListenableFutureeventually either containing {@param future} or any exception thrown by {@param validator}.
-
select
public static <T> com.google.common.util.concurrent.ListenableFuture<T> select(java.util.List<? extends com.google.common.util.concurrent.ListenableFuture<T>> futures, java.util.concurrent.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 futures- Returns:
- a new future with the result of the first completing future.
- Throws:
java.lang.NullPointerException- if the {@param futures} is null
-
addCallback
public static <T> void addCallback(com.google.common.util.concurrent.ListenableFuture<T> future, FuturesExtra.Consumer<? super T> success, FuturesExtra.Consumer<java.lang.Throwable> failure, java.util.concurrent.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.- Throws:
java.lang.NullPointerException- if the {@param success} and {@param failure} are null
-
addSuccessCallback
public static <T> void addSuccessCallback(com.google.common.util.concurrent.ListenableFuture<T> future, FuturesExtra.Consumer<? super T> consumer, java.util.concurrent.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.
-
addFailureCallback
public static <T> void addFailureCallback(com.google.common.util.concurrent.ListenableFuture<T> future, FuturesExtra.Consumer<java.lang.Throwable> consumer, java.util.concurrent.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.
-
syncTransform2
public 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, java.util.concurrent.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 transform- Returns:
- a ListenableFuture holding the result of function.apply()
-
asyncTransform2
public 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, java.util.concurrent.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 transform- Returns:
- a ListenableFuture holding the result of function.apply()
-
syncTransform3
public 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, java.util.concurrent.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 transform- Returns:
- a ListenableFuture holding the result of function.apply()
-
asyncTransform3
public 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, java.util.concurrent.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 transform- Returns:
- a ListenableFuture holding the result of function.apply()
-
syncTransform4
public 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, java.util.concurrent.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 transform- Returns:
- a ListenableFuture holding the result of function.apply()
-
asyncTransform4
public 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, java.util.concurrent.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 transform- Returns:
- a ListenableFuture holding the result of function.apply()
-
syncTransform5
public 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, java.util.concurrent.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 transform- Returns:
- a ListenableFuture holding the result of function.apply()
-
asyncTransform5
public 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, java.util.concurrent.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 transform- Returns:
- a ListenableFuture holding the result of function.apply()
-
syncTransform6
public 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, java.util.concurrent.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 transform- Returns:
- a ListenableFuture holding the result of function.apply()
-
asyncTransform6
public 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, java.util.concurrent.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 transform- Returns:
- a ListenableFuture holding the result of function.apply()
-
transform
private static <Z> com.google.common.util.concurrent.ListenableFuture<Z> transform(java.util.List<? extends com.google.common.util.concurrent.ListenableFuture<?>> inputs, com.google.common.base.Function<java.util.List<java.lang.Object>,Z> function, java.util.concurrent.Executor executor)
-
transform
private static <Z> com.google.common.util.concurrent.ListenableFuture<Z> transform(java.util.List<? extends com.google.common.util.concurrent.ListenableFuture<?>> inputs, com.google.common.util.concurrent.AsyncFunction<java.util.List<java.lang.Object>,Z> function, java.util.concurrent.Executor executor)
-
join
public static com.google.common.util.concurrent.ListenableFuture<JoinedResults> join(java.util.concurrent.Executor executor, java.util.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(Executor, ListenableFuture...)
-
join
public static com.google.common.util.concurrent.ListenableFuture<JoinedResults> join(java.util.concurrent.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));
-
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:
java.lang.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:
java.lang.IllegalStateException- if the future is not completed.com.google.common.util.concurrent.UncheckedExecutionException- if the future has failed
-
getException
public static <T> java.lang.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:
java.lang.IllegalStateException- if the future is not completed.
-
-