@ThreadSafe public class AsyncQueue<T> extends Object
Modifier and Type | Class and Description |
---|---|
static class |
AsyncQueue.BorrowResult<T,R> |
Constructor and Description |
---|
AsyncQueue(int targetQueueSize,
Executor executor) |
Modifier and Type | Method and Description |
---|---|
<O> com.google.common.util.concurrent.ListenableFuture<O> |
borrowBatchAsync(int maxSize,
Function<List<T>,AsyncQueue.BorrowResult<T,O>> function)
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. |
void |
finish() |
com.google.common.util.concurrent.ListenableFuture<List<T>> |
getBatchAsync(int maxSize) |
boolean |
isFinished()
Returns true if all future attempts to retrieve elements from this queue
are guaranteed to return empty.
|
com.google.common.util.concurrent.ListenableFuture<?> |
offer(T element) |
public AsyncQueue(int targetQueueSize, Executor executor)
public boolean isFinished()
public void finish()
public com.google.common.util.concurrent.ListenableFuture<?> offer(T element)
public com.google.common.util.concurrent.ListenableFuture<List<T>> getBatchAsync(int maxSize)
public <O> com.google.common.util.concurrent.ListenableFuture<O> borrowBatchAsync(int maxSize, Function<List<T>,AsyncQueue.BorrowResult<T,O>> function)
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 finish()
has been invoked.
When borrow (of a non-empty list) is ongoing, 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.
Copyright © 2012–2021. All rights reserved.