Class ListenableCompletableFuture<V>

  • All Implemented Interfaces:
    com.google.common.util.concurrent.ListenableFuture<V>, java.util.concurrent.CompletionStage<V>, java.util.concurrent.Future<V>, ListenableCompletionStage<V>

    public class ListenableCompletableFuture<V>
    extends java.util.concurrent.CompletableFuture<V>
    implements ListenableCompletionStage<V>
    A CompletableFuture that is also a ListenableFuture for migration from Guava ListenableFuture to CompletableFuture.
    • Nested Class Summary

      • Nested classes/interfaces inherited from class java.util.concurrent.CompletableFuture

        java.util.concurrent.CompletableFuture.AsynchronousCompletionTask
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static <T> ListenableCompletableFuture<T> completedFuture​(T value)
      Returns a new CompletableFuture that is already completed with the given value.
      static <T> ListenableCompletableFuture<T> failedFuture​(java.lang.Throwable throwable)
      Returns a new ListenableCompletableFuture that is already completed exceptionally with the given throwable.
      static <T> ListenableCompletableFuture<T> of​(java.util.concurrent.CompletableFuture<T> future)
      Converts a generic CompletableFuture to a ListenableCompletableFuture.
      • Methods inherited from class java.util.concurrent.CompletableFuture

        acceptEither, acceptEitherAsync, acceptEitherAsync, allOf, anyOf, applyToEither, applyToEitherAsync, applyToEitherAsync, cancel, complete, completeAsync, completeAsync, completedStage, completeExceptionally, completeOnTimeout, copy, defaultExecutor, delayedExecutor, delayedExecutor, exceptionally, failedStage, get, get, getNow, getNumberOfDependents, handle, handleAsync, handleAsync, isCancelled, isCompletedExceptionally, isDone, join, minimalCompletionStage, newIncompleteFuture, obtrudeException, obtrudeValue, orTimeout, runAfterBoth, runAfterBothAsync, runAfterBothAsync, runAfterEither, runAfterEitherAsync, runAfterEitherAsync, runAsync, runAsync, supplyAsync, supplyAsync, thenAccept, thenAcceptAsync, thenAcceptAsync, thenAcceptBoth, thenAcceptBothAsync, thenAcceptBothAsync, thenApply, thenApplyAsync, thenApplyAsync, thenCombine, thenCombineAsync, thenCombineAsync, thenCompose, thenComposeAsync, thenComposeAsync, thenRun, thenRunAsync, thenRunAsync, toCompletableFuture, toString, whenComplete, whenCompleteAsync, whenCompleteAsync
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
      • Methods inherited from interface java.util.concurrent.CompletionStage

        acceptEither, acceptEitherAsync, acceptEitherAsync, applyToEither, applyToEitherAsync, applyToEitherAsync, exceptionally, handle, handleAsync, handleAsync, runAfterBoth, runAfterBothAsync, runAfterBothAsync, runAfterEither, runAfterEitherAsync, runAfterEitherAsync, thenAccept, thenAcceptAsync, thenAcceptAsync, thenAcceptBoth, thenAcceptBothAsync, thenAcceptBothAsync, thenApply, thenApplyAsync, thenApplyAsync, thenCombine, thenCombineAsync, thenCombineAsync, thenCompose, thenComposeAsync, thenComposeAsync, thenRun, thenRunAsync, thenRunAsync, toCompletableFuture, whenComplete, whenCompleteAsync, whenCompleteAsync
      • Methods inherited from interface java.util.concurrent.Future

        cancel, get, get, isCancelled, isDone
    • Constructor Detail

      • ListenableCompletableFuture

        public ListenableCompletableFuture()
    • Method Detail

      • completedFuture

        public static <T> ListenableCompletableFuture<T> completedFuture​(T value)
        Returns a new CompletableFuture that is already completed with the given value.

        When the migration to CompletableFuture is finished use of this method can be replaced with CompletableFuture.completedFuture(Object).

        Type Parameters:
        T - the type of the value
        Parameters:
        value - the value
        Returns:
        the completed CompletableFuture
      • failedFuture

        public static <T> ListenableCompletableFuture<T> failedFuture​(java.lang.Throwable throwable)
        Returns a new ListenableCompletableFuture that is already completed exceptionally with the given throwable.

        When the migration to CompletableFuture is finished this can be deprecated and FutureUtils.failedFuture(Throwable) can be used instead.

        Type Parameters:
        T - the type of the expected value
        Parameters:
        throwable - the exceptions
        Returns:
        the completed CompletableFuture
      • of

        public static <T> ListenableCompletableFuture<T> of​(java.util.concurrent.CompletableFuture<T> future)
        Converts a generic CompletableFuture to a ListenableCompletableFuture. If the passed in future is already a ListenableCompletableFuture no conversion is performed.

        When the migration to CompletableFuture is finished usages of this method can simply be removed as the conversion will no longer be required.

        Type Parameters:
        T - the type of the futures return value
        Parameters:
        future - A CompletableFuture that may need to be converted
        Returns:
        A ListenableCompletableFuture