Class FuturesExtra

java.lang.Object
com.spotify.futures.FuturesExtra

public class FuturesExtra extends Object
Static utility methods pertaining to the ListenableFuture interface.
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    static interface 
    static interface 
     
    static interface 
     
    static interface 
     
    static interface 
     
    static interface 
    Represents an operation that accepts a single input argument and returns no result.
    static interface 
    Implementations of this interface is used to synchronously transform the input values into an output value.
    static interface 
    Implementations of this interface is used to synchronously transform the input values into an output value.
    static interface 
    Implementations of this interface is used to synchronously transform the input values into an output value.
    static interface 
    Implementations of this interface is used to synchronously transform the input values into an output value.
    static interface 
    Implementations of this interface is used to synchronously transform the input values into an output value.
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    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 a ListenableFuture.
    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 a ListenableFuture.
    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 a ListenableFuture.
    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 a ListenableFuture.
    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 a ListenableFuture.
    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 a ListenableFuture.
    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 for Futures.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> void
    checkCompleted(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 type FuturesExtra and FuturesExtra and works like a valve on FuturesExtra, with validation executed on FuturesExtra.
    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 type FuturesExtra and FuturesExtra and works like a valve on FuturesExtra, with validation executed on FuturesExtra.
    static <T> T
    getCompleted(com.google.common.util.concurrent.ListenableFuture<T> future)
    Get the value of a completed future.
    static <T> Throwable
    getException(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>
    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.
    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>
    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.
    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 a TimeoutException if the parent future has not finished before the timeout.
    static <T> com.google.common.util.concurrent.ListenableFuture<T>
    select(List<? extends com.google.common.util.concurrent.ListenableFuture<T>> futures)
    Returns a new ListenableFuture with 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 new ListenableFuture with 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 for Futures.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)
     

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • 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 a TimeoutException if 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 future
      unit - 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 type FuturesExtra and FuturesExtra and works like a valve on FuturesExtra, with validation executed on FuturesExtra.

      Returns a future with the result of FuturesExtra that will wait for a condition on FuturesExtra to be validated first. Both futures can run in parallel. If the condition fails validation, the FuturesExtra future will be cancelled by a call to Future.cancel(boolean) with false.

      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 ListenableFuture eventually 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 type FuturesExtra and FuturesExtra and works like a valve on FuturesExtra, with validation executed on FuturesExtra.

      Returns a future with the result of FuturesExtra that will wait for a condition on FuturesExtra to be validated first. Both futures can run in parallel. If the condition fails validation, the FuturesExtra future will be cancelled by a call to Future.cancel(boolean) with false.

      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 ListenableFuture eventually 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 new ListenableFuture with 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 with NoSuchElementException
      Parameters:
      futures - a List of 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 new ListenableFuture with 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 with NoSuchElementException
      Parameters:
      futures - a List of futures
      executor - 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 a ListenableFuture. 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 a ListenableFuture. 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 a ListenableFuture. 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 a ListenableFuture. 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 a ListenableFuture. 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 a ListenableFuture. 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, 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. The transformation follows the same semantics as as Futures.transform(ListenableFuture, Function, Executor) and the input futures are combined using Futures.allAsList(com.google.common.util.concurrent.ListenableFuture<? extends V>...).
      Parameters:
      a - a ListenableFuture to combine
      b - a ListenableFuture to combine
      function - the implementation of the transform
      Returns:
      a ListenableFuture holding the result of function.apply()
    • 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, Executor executor)
      Transform the input futures into a single future, using the provided transform function. The transformation follows the same semantics as as Futures.transform(ListenableFuture, Function, Executor) and the input futures are combined using Futures.allAsList(com.google.common.util.concurrent.ListenableFuture<? extends V>...).
      Parameters:
      a - a ListenableFuture to combine
      b - a ListenableFuture to combine
      function - the implementation of the transform
      executor - an executor to run the function on.
      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)
      Transform the input futures into a single future, using the provided transform function. The transformation follows the same semantics as as Futures.transformAsync(ListenableFuture, AsyncFunction, Executor) and the input futures are combined using Futures.allAsList(com.google.common.util.concurrent.ListenableFuture<? extends V>...).
      Parameters:
      a - a ListenableFuture to combine
      b - a ListenableFuture to combine
      function - 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, Executor executor)
      Transform the input futures into a single future, using the provided transform function. The transformation follows the same semantics as as Futures.transformAsync(ListenableFuture, AsyncFunction, Executor) and the input futures are combined using Futures.allAsList(com.google.common.util.concurrent.ListenableFuture<? extends V>...).
      Parameters:
      a - a ListenableFuture to combine
      b - a ListenableFuture to combine
      function - the implementation of the transform
      executor - an executor to run the function on.
      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)
      Transform the input futures into a single future, using the provided transform function. The transformation follows the same semantics as as Futures.transform(ListenableFuture, Function, Executor) and the input futures are combined using Futures.allAsList(com.google.common.util.concurrent.ListenableFuture<? extends V>...).
      Parameters:
      a - a ListenableFuture to combine
      b - a ListenableFuture to combine
      c - a ListenableFuture to combine
      function - 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, Executor executor)
      Transform the input futures into a single future, using the provided transform function. The transformation follows the same semantics as as Futures.transform(ListenableFuture, Function, Executor) and the input futures are combined using Futures.allAsList(com.google.common.util.concurrent.ListenableFuture<? extends V>...).
      Parameters:
      a - a ListenableFuture to combine
      b - a ListenableFuture to combine
      c - a ListenableFuture to combine
      function - the implementation of the transform
      executor - an executor to run the function on.
      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)
      Transform the input futures into a single future, using the provided transform function. The transformation follows the same semantics as as Futures.transformAsync(ListenableFuture, AsyncFunction, Executor) and the input futures are combined using Futures.allAsList(com.google.common.util.concurrent.ListenableFuture<? extends V>...).
      Parameters:
      a - a ListenableFuture to combine
      b - a ListenableFuture to combine
      c - a ListenableFuture to combine
      function - 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, Executor executor)
      Transform the input futures into a single future, using the provided transform function. The transformation follows the same semantics as as Futures.transformAsync(ListenableFuture, AsyncFunction, Executor) and the input futures are combined using Futures.allAsList(com.google.common.util.concurrent.ListenableFuture<? extends V>...).
      Parameters:
      a - a ListenableFuture to combine
      b - a ListenableFuture to combine
      c - a ListenableFuture to combine
      function - the implementation of the transform
      executor - an executor to run the function on.
      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)
      Transform the input futures into a single future, using the provided transform function. The transformation follows the same semantics as as Futures.transform(ListenableFuture, Function, Executor) and the input futures are combined using Futures.allAsList(com.google.common.util.concurrent.ListenableFuture<? extends V>...).
      Parameters:
      a - a ListenableFuture to combine
      b - a ListenableFuture to combine
      c - a ListenableFuture to combine
      d - a ListenableFuture to combine
      function - 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, Executor executor)
      Transform the input futures into a single future, using the provided transform function. The transformation follows the same semantics as as Futures.transform(ListenableFuture, Function, Executor) and the input futures are combined using Futures.allAsList(com.google.common.util.concurrent.ListenableFuture<? extends V>...).
      Parameters:
      a - a ListenableFuture to combine
      b - a ListenableFuture to combine
      c - a ListenableFuture to combine
      d - a ListenableFuture to combine
      function - the implementation of the transform
      executor - an executor to run the function on.
      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)
      Transform the input futures into a single future, using the provided transform function. The transformation follows the same semantics as as Futures.transformAsync(ListenableFuture, AsyncFunction, Executor) and the input futures are combined using Futures.allAsList(com.google.common.util.concurrent.ListenableFuture<? extends V>...).
      Parameters:
      a - a ListenableFuture to combine
      b - a ListenableFuture to combine
      c - a ListenableFuture to combine
      d - a ListenableFuture to combine
      function - 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, Executor executor)
      Transform the input futures into a single future, using the provided transform function. The transformation follows the same semantics as as Futures.transformAsync(ListenableFuture, AsyncFunction, Executor) and the input futures are combined using Futures.allAsList(com.google.common.util.concurrent.ListenableFuture<? extends V>...).
      Parameters:
      a - a ListenableFuture to combine
      b - a ListenableFuture to combine
      c - a ListenableFuture to combine
      d - a ListenableFuture to combine
      function - the implementation of the transform
      executor - an executor to run the function on.
      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)
      Transform the input futures into a single future, using the provided transform function. The transformation follows the same semantics as as Futures.transform(ListenableFuture, Function, Executor) and the input futures are combined using Futures.allAsList(com.google.common.util.concurrent.ListenableFuture<? extends V>...).
      Parameters:
      a - a ListenableFuture to combine
      b - a ListenableFuture to combine
      c - a ListenableFuture to combine
      d - a ListenableFuture to combine
      e - a ListenableFuture to combine
      function - 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, Executor executor)
      Transform the input futures into a single future, using the provided transform function. The transformation follows the same semantics as as Futures.transform(ListenableFuture, Function, Executor) and the input futures are combined using Futures.allAsList(com.google.common.util.concurrent.ListenableFuture<? extends V>...).
      Parameters:
      a - a ListenableFuture to combine
      b - a ListenableFuture to combine
      c - a ListenableFuture to combine
      d - a ListenableFuture to combine
      e - a ListenableFuture to combine
      function - the implementation of the transform
      executor - an executor to run the function on.
      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)
      Transform the input futures into a single future, using the provided transform function. The transformation follows the same semantics as as Futures.transformAsync(ListenableFuture, AsyncFunction, Executor) and the input futures are combined using Futures.allAsList(com.google.common.util.concurrent.ListenableFuture<? extends V>...).
      Parameters:
      a - a ListenableFuture to combine
      b - a ListenableFuture to combine
      c - a ListenableFuture to combine
      d - a ListenableFuture to combine
      e - a ListenableFuture to combine
      function - 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, Executor executor)
      Transform the input futures into a single future, using the provided transform function. The transformation follows the same semantics as as Futures.transformAsync(ListenableFuture, AsyncFunction, Executor) and the input futures are combined using Futures.allAsList(com.google.common.util.concurrent.ListenableFuture<? extends V>...).
      Parameters:
      a - a ListenableFuture to combine
      b - a ListenableFuture to combine
      c - a ListenableFuture to combine
      d - a ListenableFuture to combine
      e - a ListenableFuture to combine
      function - the implementation of the transform
      executor - an executor to run the function on.
      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)
      Transform the input futures into a single future, using the provided transform function. The transformation follows the same semantics as as Futures.transform(ListenableFuture, Function, Executor) and the input futures are combined using Futures.allAsList(com.google.common.util.concurrent.ListenableFuture<? extends V>...).
      Parameters:
      a - a ListenableFuture to combine
      b - a ListenableFuture to combine
      c - a ListenableFuture to combine
      d - a ListenableFuture to combine
      e - a ListenableFuture to combine
      f - a ListenableFuture to combine
      function - 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, Executor executor)
      Transform the input futures into a single future, using the provided transform function. The transformation follows the same semantics as as Futures.transform(ListenableFuture, Function, Executor) and the input futures are combined using Futures.allAsList(com.google.common.util.concurrent.ListenableFuture<? extends V>...).
      Parameters:
      a - a ListenableFuture to combine
      b - a ListenableFuture to combine
      c - a ListenableFuture to combine
      d - a ListenableFuture to combine
      e - a ListenableFuture to combine
      f - a ListenableFuture to combine
      function - the implementation of the transform
      executor - an executor to run the function on.
      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)
      Transform the input futures into a single future, using the provided transform function. The transformation follows the same semantics as as Futures.transformAsync(ListenableFuture, AsyncFunction, Executor) and the input futures are combined using Futures.allAsList(com.google.common.util.concurrent.ListenableFuture<? extends V>...).
      Parameters:
      a - a ListenableFuture to combine
      b - a ListenableFuture to combine
      c - a ListenableFuture to combine
      d - a ListenableFuture to combine
      e - a ListenableFuture to combine
      f - a ListenableFuture to combine
      function - 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, Executor executor)
      Transform the input futures into a single future, using the provided transform function. The transformation follows the same semantics as as Futures.transformAsync(ListenableFuture, AsyncFunction, Executor) and the input futures are combined using Futures.allAsList(com.google.common.util.concurrent.ListenableFuture<? extends V>...).
      Parameters:
      a - a ListenableFuture to combine
      b - a ListenableFuture to combine
      c - a ListenableFuture to combine
      d - a ListenableFuture to combine
      e - a ListenableFuture to combine
      f - a ListenableFuture to combine
      function - the implementation of the transform
      executor - an executor to run the function on.
      Returns:
      a ListenableFuture holding the result of function.apply()
    • transform

      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)
    • transform

      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)
    • 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 for Futures.transform(ListenableFuture, Function, Executor).
      Parameters:
      input - the input future
      function - 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 for Futures.transformAsync(ListenableFuture, AsyncFunction, Executor).
      Parameters:
      input - the input future
      function - 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.