Class ThrottledAsyncQueue<T>

  • Type Parameters:
    T - The type of elements accepted by the queue.

    @ThreadSafe
    public class ThrottledAsyncQueue<T>
    extends AsyncQueue<T>
    An asynchronous queue that limits the rate at which batches will be made available as well as the number of elements they will contain.
    • Constructor Detail

      • ThrottledAsyncQueue

        public ThrottledAsyncQueue​(int maxBatchSizePerSec,
                                   int targetQueueSize,
                                   Executor executor)
    • Method Detail

      • borrowBatchAsync

        public <O> com.google.common.util.concurrent.ListenableFuture<O> borrowBatchAsync​(int maxSize,
                                                                                          Function<List<T>,​AsyncQueue.BorrowResult<T,​O>> function)
        Description copied from class: AsyncQueue
        Invoke function with up to maxSize elements removed from the head of the queue, and insert elements in the return value to the tail of the queue.

        If no element is currently available, invocation of function will be deferred until some element is available, or no more elements will be. Spurious invocation of function is possible.

        Insertion through return value of function will be effective even if AsyncQueue.finish() has been invoked. When borrow (of a non-empty list) is ongoing, AsyncQueue.isFinished() will return false. If an empty list is supplied to function, it must not return a result indicating intention to insert elements into the queue.

        Overrides:
        borrowBatchAsync in class AsyncQueue<T>