org.springframework.util.concurrent

Class CompletableToListenableFutureAdapter<T>

  • java.lang.Object
    • org.springframework.util.concurrent.CompletableToListenableFutureAdapter<T>
  • Type Parameters:
    T - the result type returned by this Future's get method
    All Implemented Interfaces:
    java.util.concurrent.Future<T>, ListenableFuture<T>


    public class CompletableToListenableFutureAdapter<T>
    extends java.lang.Object
    implements ListenableFuture<T>
    Adapts a CompletableFuture or CompletionStage into a Spring ListenableFuture.
    Since:
    4.2
    Author:
    Sebastien Deleuze, Juergen Hoeller
    • Constructor Detail

      • CompletableToListenableFutureAdapter

        public CompletableToListenableFutureAdapter(java.util.concurrent.CompletionStage<T> completionStage)
        Create a new adapter for the given CompletionStage.
        Since:
        4.3.7
      • CompletableToListenableFutureAdapter

        public CompletableToListenableFutureAdapter(java.util.concurrent.CompletableFuture<T> completableFuture)
        Create a new adapter for the given CompletableFuture.
    • Method Detail

      • addCallback

        public void addCallback(SuccessCallback<? super T> successCallback,
                                FailureCallback failureCallback)
        Description copied from interface: ListenableFuture
        Java 8 lambda-friendly alternative with success and failure callbacks.
        Specified by:
        addCallback in interface ListenableFuture<T>
        Parameters:
        successCallback - the success callback
        failureCallback - the failure callback
      • cancel

        public boolean cancel(boolean mayInterruptIfRunning)
        Specified by:
        cancel in interface java.util.concurrent.Future<T>
      • isCancelled

        public boolean isCancelled()
        Specified by:
        isCancelled in interface java.util.concurrent.Future<T>
      • isDone

        public boolean isDone()
        Specified by:
        isDone in interface java.util.concurrent.Future<T>
      • get

        public T get()
              throws java.lang.InterruptedException,
                     java.util.concurrent.ExecutionException
        Specified by:
        get in interface java.util.concurrent.Future<T>
        Throws:
        java.lang.InterruptedException
        java.util.concurrent.ExecutionException
      • get

        public T get(long timeout,
                     java.util.concurrent.TimeUnit unit)
              throws java.lang.InterruptedException,
                     java.util.concurrent.ExecutionException,
                     java.util.concurrent.TimeoutException
        Specified by:
        get in interface java.util.concurrent.Future<T>
        Throws:
        java.lang.InterruptedException
        java.util.concurrent.ExecutionException
        java.util.concurrent.TimeoutException