Class FutureImpl<R>

  • All Implemented Interfaces:
    java.util.concurrent.Future<R>
    Direct Known Subclasses:
    ConnectFuture

    public class FutureImpl<R>
    extends java.lang.Object
    implements java.util.concurrent.Future<R>
    Simple Future implementation, which uses synchronization Object to synchronize during the lifecycle.
    See Also:
    Future
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private java.lang.Throwable failure  
      private boolean isCancelled  
      private boolean isDone  
      protected R result  
      private java.lang.Object sync  
    • Constructor Summary

      Constructors 
      Constructor Description
      FutureImpl()  
      FutureImpl​(java.lang.Object sync)  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      boolean cancel​(boolean mayInterruptIfRunning)
      void failure​(java.lang.Throwable failure)
      Notify about the failure, occured during asynchronous operation execution.
      R get()
      R get​(long timeout, java.util.concurrent.TimeUnit unit)
      R getResult()
      Get current result value without any blocking.
      boolean isCancelled()
      boolean isDone()
      protected void notifyHaveResult()
      Notify blocked listeners threads about operation completion.
      void setResult​(R result)
      Set the result value and notify about operation completion.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • sync

        private final java.lang.Object sync
      • isDone

        private boolean isDone
      • isCancelled

        private boolean isCancelled
      • failure

        private java.lang.Throwable failure
      • result

        protected R result
    • Constructor Detail

      • FutureImpl

        public FutureImpl()
      • FutureImpl

        public FutureImpl​(java.lang.Object sync)
    • Method Detail

      • getResult

        public R getResult()
        Get current result value without any blocking.
        Returns:
        current result value without any blocking.
      • setResult

        public void setResult​(R result)
        Set the result value and notify about operation completion.
        Parameters:
        result - the result value
      • cancel

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

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

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

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

        public R 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<R>
        Throws:
        java.lang.InterruptedException
        java.util.concurrent.ExecutionException
        java.util.concurrent.TimeoutException
      • failure

        public void failure​(java.lang.Throwable failure)
        Notify about the failure, occured during asynchronous operation execution.
        Parameters:
        failure -
      • notifyHaveResult

        protected void notifyHaveResult()
        Notify blocked listeners threads about operation completion.