Class FutureConjunction

  • All Implemented Interfaces:
    com.google.common.util.concurrent.ListenableFuture<java.lang.Boolean>, java.util.concurrent.Future<java.lang.Boolean>

    public final class FutureConjunction
    extends java.lang.Object
    implements com.google.common.util.concurrent.ListenableFuture<java.lang.Boolean>

    This class implements a Future<Boolean> that is conjunction of zero or more other Future<Boolean>s, i.e. it evaluates to true if, and only if, all its operands evaluate to true. To use this class, simply create an instance of it and add operands to it using the addOperand(ListenableFuture) method.

    TODO: consider rewriting usage of FutureConjunction to use CompletableFuture instead.
    Author:
    Simon Thoresen Hult
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void addListener​(java.lang.Runnable listener, java.util.concurrent.Executor executor)  
      void addOperand​(com.google.common.util.concurrent.ListenableFuture<java.lang.Boolean> operand)
      Adds a ListenableFuture<Boolean> to this conjunction.
      boolean cancel​(boolean mayInterruptIfRunning)  
      java.lang.Boolean get()  
      java.lang.Boolean 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, toString, wait, wait, wait
    • Constructor Detail

      • FutureConjunction

        public FutureConjunction()
    • Method Detail

      • addOperand

        public void addOperand​(com.google.common.util.concurrent.ListenableFuture<java.lang.Boolean> operand)

        Adds a ListenableFuture<Boolean> to this conjunction. This can be called at any time, even after having called get() previously.

        Parameters:
        operand - The operand to add to this conjunction.
      • addListener

        public void addListener​(java.lang.Runnable listener,
                                java.util.concurrent.Executor executor)
        Specified by:
        addListener in interface com.google.common.util.concurrent.ListenableFuture<java.lang.Boolean>
      • cancel

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

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

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

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

        public final java.lang.Boolean 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<java.lang.Boolean>
        Throws:
        java.lang.InterruptedException
        java.util.concurrent.ExecutionException
        java.util.concurrent.TimeoutException