Class FutureCombiner<T>

  • All Implemented Interfaces:
    com.google.common.util.concurrent.ListenableFuture<T>, io.netty.util.concurrent.Future<T>, java.util.concurrent.Future<T>, Awaitable, Future<T>

    public class FutureCombiner<T>
    extends AsyncFuture<T>
    Netty's PromiseCombiner is not threadsafe, and we combine futures from multiple event executors. This class groups a number of Future into a single logical Future, by registering a listener to each that decrements a shared counter; if any of them fail, the FutureCombiner is completed with the first cause, but in all scenario only completes when all underlying future have completed (exceptionally or otherwise) This Future is always uncancellable. We extend AsyncFuture, and simply provide it an uncancellable Promise that will be completed by the listeners registered to the input futures.
    • Method Detail

      • tryFailure

        protected boolean tryFailure​(java.lang.Throwable throwable)
        Overrides:
        tryFailure in class AbstractFuture<T>
      • cancel

        public boolean cancel​(boolean b)
        Specified by:
        cancel in interface io.netty.util.concurrent.Future<T>
        Specified by:
        cancel in interface java.util.concurrent.Future<T>
        Overrides:
        cancel in class AbstractFuture<T>
      • nettySuccessListener

        public static FutureCombiner<java.lang.Void> nettySuccessListener​(java.util.Collection<? extends io.netty.util.concurrent.Future<?>> futures)
        Waits for all of futures to complete, only propagating failures on completion
      • allOf

        public static <V> Future<java.util.List<V>> allOf​(java.util.Collection<? extends io.netty.util.concurrent.Future<? extends V>> futures)
        Waits only until the first failure, or until all have succeeded. Returns a list of results if successful; an exception if any failed.
        Parameters:
        futures - futures to wait for completion of
        Returns:
        a Future containing all results of futures
      • successfulOf

        public static <V> Future<java.util.List<V>> successfulOf​(java.util.List<? extends io.netty.util.concurrent.Future<V>> futures)
        Waits for all futures to complete, returning a list containing values of all successful input futures. This emulates Guava's Futures::successfulAsList in that results will be in the same order as inputs and any non-success value (e.g. failure or cancellation) will be replaced by null.
        Parameters:
        futures - futures to wait for completion of
        Returns:
        a Future containing all successful results of futures and nulls for non-successful futures