Class DefaultAsyncFuture<T>

    • Nested Class Summary

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

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

      Constructors 
      Constructor Description
      DefaultAsyncFuture​(boolean cancellable)
      Creates a new instance.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      AsyncPromise<T> addListener​(AsyncFutureListener<T> listener)
      Adds the specified listener to this future.
      AsyncPromise<T> addListener​(AsyncPromise<T> listener)
      Adds the specified future as a listener to this future.
      AsyncFuture<T> await()
      Waits for this future to be completed.
      boolean await​(long timeout, java.util.concurrent.TimeUnit unit)
      Waits for this future to be completed within the specified time limit.
      AsyncFuture<T> awaitUninterruptibly()
      Waits for this future to be completed without interruption.
      boolean awaitUninterruptibly​(long timeout, java.util.concurrent.TimeUnit unit)
      Waits for this future to be completed within the specified time limit without interruption.
      boolean cancel​(boolean mayInterruptIfRunning)  
      boolean complete​(T value)  
      boolean completeExceptionally​(java.lang.Throwable ex)  
      T get​(long timeout, java.util.concurrent.TimeUnit unit)  
      java.lang.Throwable getCause()
      Returns the cause of the failed I/O operation if the I/O operation has failed.
      T getNow()
      Non-blocking variant of Future.get()
      boolean isSuccess()
      Returns true if and only if the I/O operation was completed successfully.
      boolean setFailure​(java.lang.Throwable t)
      Marks this future as a failure and notifies all listeners.
      boolean setSuccess​(T result)
      Marks this future as a success and notifies all listeners.
      • Methods inherited from class java.util.concurrent.CompletableFuture

        acceptEither, acceptEitherAsync, acceptEitherAsync, allOf, anyOf, applyToEither, applyToEitherAsync, applyToEitherAsync, completeAsync, completeAsync, completedFuture, completedStage, completeOnTimeout, copy, defaultExecutor, delayedExecutor, delayedExecutor, exceptionally, failedFuture, failedStage, 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

        get, isCancelled, isDone
    • Constructor Detail

      • DefaultAsyncFuture

        public DefaultAsyncFuture​(boolean cancellable)
        Creates a new instance.
        Parameters:
        cancellable - true if and only if this future can be canceled
    • Method Detail

      • getCause

        public final java.lang.Throwable getCause()
        Description copied from interface: AsyncFuture
        Returns the cause of the failed I/O operation if the I/O operation has failed.
        Specified by:
        getCause in interface AsyncFuture<T>
        Returns:
        the cause of the failure. null if succeeded or this future is not completed yet.
        See Also:
        AsyncFuture.getCause()
      • setSuccess

        public boolean setSuccess​(T result)
        Description copied from interface: AsyncPromise
        Marks this future as a success and notifies all listeners.
        Specified by:
        setSuccess in interface AsyncPromise<T>
        Returns:
        true if and only if successfully marked this future as a success. Otherwise false because this future is already marked as either a success or a failure.
        See Also:
        AsyncPromise.setSuccess(Object)
      • setFailure

        public boolean setFailure​(@Nonnull
                                  java.lang.Throwable t)
        Description copied from interface: AsyncPromise
        Marks this future as a failure and notifies all listeners.
        Specified by:
        setFailure in interface AsyncPromise<T>
        Returns:
        true if and only if successfully marked this future as a failure. Otherwise false because this future is already marked as either a success or a failure.
        See Also:
        AsyncPromise.setFailure(Throwable)
      • addListener

        @Nonnull
        public AsyncPromise<T> addListener​(AsyncPromise<T> listener)
        Adds the specified future as a listener to this future. The specified future is notified when this future is done. If this future is already completed, the specified future is notified immediately.
        Specified by:
        addListener in interface AsyncFuture<T>
        Specified by:
        addListener in interface AsyncPromise<T>
        Parameters:
        listener -
        Returns:
        this to permit chaining of operations.
      • await

        @Nonnull
        public final AsyncFuture<T> await()
                                   throws java.lang.InterruptedException
        Description copied from interface: AsyncFuture
        Waits for this future to be completed.
        Specified by:
        await in interface AsyncFuture<T>
        Throws:
        java.lang.InterruptedException - if the current thread was interrupted
        See Also:
        AsyncFuture.await()
      • await

        public final boolean await​(long timeout,
                                   @Nonnull
                                   java.util.concurrent.TimeUnit unit)
                            throws java.lang.InterruptedException
        Description copied from interface: AsyncFuture
        Waits for this future to be completed within the specified time limit.
        Specified by:
        await in interface AsyncFuture<T>
        Specified by:
        await in interface Time.Awaitable
        Returns:
        true if and only if the future was completed within the specified time limit
        Throws:
        java.lang.InterruptedException - if the current thread was interrupted
        See Also:
        AsyncFuture.await(long, java.util.concurrent.TimeUnit)
      • awaitUninterruptibly

        public final boolean awaitUninterruptibly​(long timeout,
                                                  @Nonnull
                                                  java.util.concurrent.TimeUnit unit)
        Description copied from interface: AsyncFuture
        Waits for this future to be completed within the specified time limit without interruption. This method catches an InterruptedException and discards it silently.
        Specified by:
        awaitUninterruptibly in interface AsyncFuture<T>
        Returns:
        true if and only if the future was completed within the specified time limit
        See Also:
        AsyncFuture.awaitUninterruptibly(long, java.util.concurrent.TimeUnit)
      • get

        public T get​(long timeout,
                     @Nonnull
                     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>
        Overrides:
        get in class java.util.concurrent.CompletableFuture<T>
        Throws:
        java.lang.InterruptedException
        java.util.concurrent.ExecutionException
        java.util.concurrent.TimeoutException
      • complete

        public final boolean complete​(T value)
        Overrides:
        complete in class java.util.concurrent.CompletableFuture<T>
      • completeExceptionally

        public final boolean completeExceptionally​(java.lang.Throwable ex)
        Overrides:
        completeExceptionally in class java.util.concurrent.CompletableFuture<T>
      • cancel

        public boolean cancel​(boolean mayInterruptIfRunning)
        Specified by:
        cancel in interface java.util.concurrent.Future<T>
        Overrides:
        cancel in class java.util.concurrent.CompletableFuture<T>
        See Also:
        Future.cancel(boolean)
      • getNow

        public final T getNow()
        Description copied from interface: AsyncFuture
        Non-blocking variant of Future.get()
        Specified by:
        getNow in interface AsyncFuture<T>
        Returns:
        value or null