Class DefaultPromise<V>

    • Constructor Detail

      • DefaultPromise

        public DefaultPromise()
    • Method Detail

      • setSuccess

        public Promise<V> setSuccess​(V result)
        Description copied from interface: Promise
        Marks this future as a success and notifies all listeners.

        If it is success or failed already it will throw an IllegalStateException.

        Specified by:
        setSuccess in interface Promise<V>
      • trySuccess

        public boolean trySuccess​(V result)
        Description copied from interface: Promise
        Marks this future as a success and notifies all listeners.
        Specified by:
        trySuccess in interface Promise<V>
        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.
      • tryFailure

        public boolean tryFailure​(Throwable cause)
        Description copied from interface: Promise
        Marks this future as a failure and notifies all listeners.
        Specified by:
        tryFailure in interface Promise<V>
        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.
      • addListener

        public Promise<V> addListener​(FutureListener<? extends Future<? super V>> listener)
        Description copied from interface: Future
        Adds the specified listener to this future. The specified listener is notified when this future is done. If this future is already completed, the specified listener is notified immediately.
        Specified by:
        addListener in interface Future<V>
        Specified by:
        addListener in interface Promise<V>
      • removeListener

        public Promise<V> removeListener​(FutureListener<? extends Future<? super V>> listener)
        Description copied from interface: Future
        Removes the first occurrence of the specified listener from this future. The specified listener is no longer notified when this future is done. If the specified listener is not associated with this future, this method does nothing and returns silently.
        Specified by:
        removeListener in interface Future<V>
        Specified by:
        removeListener in interface Promise<V>
      • await

        public boolean await​(long timeout,
                             TimeUnit unit)
                      throws InterruptedException
        Description copied from interface: Future
        Waits for this future to be completed within the specified time limit.
        Specified by:
        await in interface Future<V>
        Returns:
        true if and only if the future was completed within the specified time limit
        Throws:
        InterruptedException - if the current thread was interrupted
      • isSuccess

        public boolean isSuccess()
        Description copied from interface: Future
        Returns true if and only if the operation was completed successfully.
        Specified by:
        isSuccess in interface Future<V>
      • cause

        public Throwable cause()
        Description copied from interface: Future
        Returns the cause of the failed operation if the operation has failed.
        Specified by:
        cause in interface Future<V>
        Returns:
        the cause of the failure. null if succeeded or this future is not completed yet.
      • getNow

        public V getNow()
        Description copied from interface: Future
        Return the result without blocking. If the future is not done yet this will return null.

        As it is possible that a null value is used to mark the future as successful you also need to check if the future is really done with Future.isDone() and not relay on the returned null value.

        Specified by:
        getNow in interface Future<V>
      • cancel

        public boolean cancel​(boolean mayInterruptIfRunning)
        Specified by:
        cancel in interface Future<V>
      • isCancelled

        public boolean isCancelled()
        Specified by:
        isCancelled in interface Future<V>
      • isDone

        public boolean isDone()
        Specified by:
        isDone in interface Future<V>