Class FuturesExtra


  • public class FuturesExtra
    extends java.lang.Object
    Static utility methods pertaining to the ListenableFuture interface.
    • Constructor Summary

      Constructors 
      Constructor Description
      FuturesExtra()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      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 a ListenableFuture.
      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 a ListenableFuture.
      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 a ListenableFuture.
      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> 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, java.util.concurrent.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> java.lang.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​(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 a TimeoutException if 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 new ListenableFuture with 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)  
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • FuturesExtra

        public FuturesExtra()
    • 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 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,
                                                                                                 java.util.concurrent.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.
        Returns:
        a new ListenableFuture eventually 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 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:
        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 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:
        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 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.
      • 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 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.
      • 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 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()
      • 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 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()
      • 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 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()
      • 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 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()
      • 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 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()
      • 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 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()
      • 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 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()
      • 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 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()
      • 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 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()
      • 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 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()
      • 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.