Class ForwardingFuture<V extends @Nullable java.lang.Object>

  • All Implemented Interfaces:
    java.util.concurrent.Future<V>
    Direct Known Subclasses:
    ForwardingFuture.SimpleForwardingFuture, ForwardingListenableFuture

    @GwtCompatible
    public abstract class ForwardingFuture<V extends @Nullable java.lang.Object>
    extends ForwardingObject
    implements java.util.concurrent.Future<V>
    A Future which forwards all its method calls to another future. Subclasses should override one or more methods to modify the behavior of the backing future as desired per the decorator pattern.

    Warning: The methods of ForwardingFuture forward indiscriminately to the methods of the delegate. For example, overriding get(long, TimeUnit) alone will not change the behavior of get(), which can lead to unexpected behavior. In this case, you should override get() as well.

    default method warning: This class does not forward calls to default methods. Instead, it inherits their default implementations. When those implementations invoke methods, they invoke methods on the ForwardingFuture.

    Most subclasses can just use ForwardingFuture.SimpleForwardingFuture.

    Since:
    1.0
    Author:
    Sven Mawson
    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      static class  ForwardingFuture.SimpleForwardingFuture<V extends @Nullable java.lang.Object>
      A simplified version of ForwardingFuture where subclasses can pass in an already constructed Future as the delegate.
    • Constructor Summary

      Constructors 
      Modifier Constructor Description
      protected ForwardingFuture()
      Constructor for use by subclasses.
    • Method Summary

      All Methods Instance Methods Abstract Methods Concrete Methods 
      Modifier and Type Method Description
      boolean cancel​(boolean mayInterruptIfRunning)  
      protected abstract java.util.concurrent.Future<? extends V> delegate()
      Returns the backing delegate instance that methods are forwarded to.
      V get()  
      V get​(long timeout, java.util.concurrent.TimeUnit unit)  
      boolean isCancelled()  
      boolean isDone()  
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
    • Constructor Detail

      • ForwardingFuture

        protected ForwardingFuture()
        Constructor for use by subclasses.
    • Method Detail

      • delegate

        protected abstract java.util.concurrent.Future<? extends V> delegate()
        Description copied from class: ForwardingObject
        Returns the backing delegate instance that methods are forwarded to. Abstract subclasses generally override this method with an abstract method that has a more specific return type, such as ForwardingSet.delegate(). Concrete subclasses override this method to supply the instance being decorated.
        Specified by:
        delegate in class ForwardingObject
      • cancel

        @CanIgnoreReturnValue
        public boolean cancel​(boolean mayInterruptIfRunning)
        Specified by:
        cancel in interface java.util.concurrent.Future<V extends @Nullable java.lang.Object>
      • isCancelled

        public boolean isCancelled()
        Specified by:
        isCancelled in interface java.util.concurrent.Future<V extends @Nullable java.lang.Object>
      • isDone

        public boolean isDone()
        Specified by:
        isDone in interface java.util.concurrent.Future<V extends @Nullable java.lang.Object>
      • get

        @CanIgnoreReturnValue
        public V get()
              throws java.lang.InterruptedException,
                     java.util.concurrent.ExecutionException
        Specified by:
        get in interface java.util.concurrent.Future<V extends @Nullable java.lang.Object>
        Throws:
        java.lang.InterruptedException
        java.util.concurrent.ExecutionException
      • get

        @CanIgnoreReturnValue
        public V 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<V extends @Nullable java.lang.Object>
        Throws:
        java.lang.InterruptedException
        java.util.concurrent.ExecutionException
        java.util.concurrent.TimeoutException