Class FairBlockingQueue.ItemFuture<T>

  • Type Parameters:
    T - the type of the item
    All Implemented Interfaces:
    java.util.concurrent.Future<T>
    Enclosing class:
    FairBlockingQueue<E>

    protected class FairBlockingQueue.ItemFuture<T>
    extends java.lang.Object
    implements java.util.concurrent.Future<T>
    A future used to check if a connection has been made available. Cancelling the future deregisters its waiter from the queue, as long as the item has not already been handed over to the future.
    A get(long, TimeUnit) call that times out deregisters the waiter in the same way, and additionally fails the future terminally: no offer can reach the deregistered latch anymore, so the future reports isDone() true without ever being cancelled, keeps failing every later get(long, TimeUnit) with a TimeoutException and every later get() with an ExecutionException caused by one, and can no longer be cancelled.
    • Field Detail

      • item

        protected volatile T item
        The item directly available in the future.
      • canceled

        protected volatile boolean canceled
        Whether this future has been cancelled.
      • abandoned

        protected volatile boolean abandoned
        Whether a get(long, TimeUnit) call on this future timed out. Its waiter was then deregistered from the queue, so no item can ever be handed over to this future anymore; the future is terminally failed and its get() methods fail fast instead of parking on a latch that nothing can count down again.
    • Constructor Detail

      • ItemFuture

        public ItemFuture​(T item)
        Creates an ItemFuture with the given item already available.
        Parameters:
        item - the item
    • Method Detail

      • cancel

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

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

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

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

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