Class AsyncListenableFuture<V>

  • All Implemented Interfaces:
    java.io.Serializable

    public class AsyncListenableFuture<V>
    extends FiberAsync<V,​java.util.concurrent.ExecutionException>
    Turns Google Guava's ListenableFutures into a fiber-blocking operation.
    See Also:
    Serialized Form
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      static <V> V get​(com.google.common.util.concurrent.ListenableFuture<V> future)
      Blocks the current strand (either fiber or thread) until the given future completes, and returns its result.
      static <V> V get​(com.google.common.util.concurrent.ListenableFuture<V> future, long timeout, java.util.concurrent.TimeUnit unit)
      Blocks the current strand (either fiber or thread) until the given future completes - but no longer than the given timeout - and returns its result.
      static <V> V get​(com.google.common.util.concurrent.ListenableFuture<V> future, Timeout timeout)
      Blocks the current strand (either fiber or thread) until the given future completes - but no longer than the given timeout - and returns its result.
      protected void requestAsync()
      A user of this class must override this method to start the asynchronous operation and register the callback.
      protected V requestSync()
      Called if FiberAsync.run() is not being executed in a fiber.
      • Methods inherited from class java.lang.Object

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

      • get

        public static <V> V get​(com.google.common.util.concurrent.ListenableFuture<V> future)
                         throws java.util.concurrent.ExecutionException,
                                java.lang.InterruptedException,
                                SuspendExecution
        Blocks the current strand (either fiber or thread) until the given future completes, and returns its result.
        Parameters:
        future - the future
        Returns:
        the future's result
        Throws:
        java.util.concurrent.ExecutionException - if the future's computation threw an exception
        java.lang.InterruptedException - if the current thread was interrupted while waiting
        SuspendExecution
      • get

        public static <V> V get​(com.google.common.util.concurrent.ListenableFuture<V> future,
                                long timeout,
                                java.util.concurrent.TimeUnit unit)
                         throws java.util.concurrent.ExecutionException,
                                java.lang.InterruptedException,
                                SuspendExecution,
                                java.util.concurrent.TimeoutException
        Blocks the current strand (either fiber or thread) until the given future completes - but no longer than the given timeout - and returns its result.
        Parameters:
        future - the future
        timeout - the maximum duration to wait for the future's result
        unit - the timeout's time unit
        Returns:
        the future's result
        Throws:
        java.util.concurrent.ExecutionException - if the future's computation threw an exception
        java.util.concurrent.TimeoutException - if the timeout expired before the future completed
        java.lang.InterruptedException - if the current thread was interrupted while waiting
        SuspendExecution
      • get

        public static <V> V get​(com.google.common.util.concurrent.ListenableFuture<V> future,
                                Timeout timeout)
                         throws java.util.concurrent.ExecutionException,
                                java.lang.InterruptedException,
                                SuspendExecution,
                                java.util.concurrent.TimeoutException
        Blocks the current strand (either fiber or thread) until the given future completes - but no longer than the given timeout - and returns its result.
        Parameters:
        future - the future
        timeout - the method will not block for longer than the amount remaining in the Timeout
        Returns:
        the future's result
        Throws:
        java.util.concurrent.ExecutionException - if the future's computation threw an exception
        java.util.concurrent.TimeoutException - if the timeout expired before the future completed
        java.lang.InterruptedException - if the current thread was interrupted while waiting
        SuspendExecution
      • requestAsync

        protected void requestAsync()
        Description copied from class: FiberAsync
        A user of this class must override this method to start the asynchronous operation and register the callback. This method may not use any ThreadLocals.
        Specified by:
        requestAsync in class FiberAsync<V,​java.util.concurrent.ExecutionException>
      • requestSync

        protected V requestSync()
                         throws java.util.concurrent.ExecutionException,
                                java.lang.InterruptedException
        Description copied from class: FiberAsync
        Called if FiberAsync.run() is not being executed in a fiber. Should perform the operation synchronously and return its result. The default implementation of this method throws an `IllegalThreadStateException`.
        Overrides:
        requestSync in class FiberAsync<V,​java.util.concurrent.ExecutionException>
        Returns:
        The operation's result.
        Throws:
        java.lang.InterruptedException
        java.util.concurrent.ExecutionException