Class FutureCombiner<T>

All Implemented Interfaces:
com.google.common.util.concurrent.ListenableFuture<T>, io.netty.util.concurrent.Future<T>, 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 Details

    • setUncancellable

      protected boolean setUncancellable()
      Overrides:
      setUncancellable in class AbstractFuture<T>
    • setUncancellableExclusive

      protected boolean setUncancellableExclusive()
      Overrides:
      setUncancellableExclusive in class AbstractFuture<T>
    • trySuccess

      protected boolean trySuccess(T t)
      Overrides:
      trySuccess in class AbstractFuture<T>
    • tryFailure

      protected boolean tryFailure(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 Future<T>
      Overrides:
      cancel in class AbstractFuture<T>
    • nettySuccessListener

      public static FutureCombiner<Void> nettySuccessListener(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<List<V>> allOf(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<List<V>> successfulOf(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