Package org.agrona.concurrent
Class OneToOneConcurrentArrayQueue<E>
java.lang.Object
org.agrona.concurrent.AbstractConcurrentArrayQueue<E>
org.agrona.concurrent.OneToOneConcurrentArrayQueue<E>
- Type Parameters:
E- type of the elements stored in theQueue.
- All Implemented Interfaces:
Iterable<E>,Collection<E>,Queue<E>,Pipe<E>,QueuedPipe<E>
One producer to one consumer concurrent queue that is array backed. The algorithm is a variation of Fast Flow
adapted to work with the Java Memory Model on arrays by using
Unsafe.-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected longHead index.protected longCached head index.protected longShared cached head index.protected longTail index.Fields inherited from class org.agrona.concurrent.AbstractConcurrentArrayQueue
buffer, BUFFER_ARRAY_BASE, capacity, HEAD_OFFSET, SHARED_HEAD_CACHE_OFFSET, SHIFT_FOR_SCALE, TAIL_OFFSET -
Constructor Summary
ConstructorsConstructorDescriptionOneToOneConcurrentArrayQueue(int requestedCapacity) Constructs queue with the requested capacity. -
Method Summary
Modifier and TypeMethodDescriptionintDrain the number of elements present in a collection at the time the operation starts.intDrain the minimum of a limit and the number of elements present in a collection at the time the operation starts.intdrainTo(Collection<? super E> target, int limit) Drain available elements into the providedCollectionup to a provided maximum limit of elements.booleanpoll()Methods inherited from class org.agrona.concurrent.AbstractConcurrentArrayQueue
add, addAll, addedCount, capacity, clear, contains, containsAll, element, isEmpty, iterator, peek, remainingCapacity, remove, remove, removeAll, removedCount, retainAll, sequenceToBufferOffset, size, toArray, toArrayMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface java.util.Collection
equals, hashCode, parallelStream, removeIf, spliterator, stream, toArray
-
Field Details
-
head
protected volatile long headHead index. -
tail
protected volatile long tailTail index. -
headCache
protected long headCacheCached head index.
-
-
Constructor Details
-
OneToOneConcurrentArrayQueue
public OneToOneConcurrentArrayQueue(int requestedCapacity) Constructs queue with the requested capacity.- Parameters:
requestedCapacity- of the queue.
-
-
Method Details
-
offer
-
poll
-
drain
Drain the number of elements present in a collection at the time the operation starts.If possible, implementations should use smart batching to best handle burst traffic.
- Parameters:
elementConsumer-Consumerfor processing elements.- Returns:
- the number of elements drained.
-
drain
Drain the minimum of a limit and the number of elements present in a collection at the time the operation starts.If possible, implementations should use smart batching to best handle burst traffic.
- Parameters:
elementConsumer-Consumerfor processing elements.limit- maximum number of elements to be drained in a drain operation.- Returns:
- the number of elements drained.
-
drainTo
Drain available elements into the providedCollectionup to a provided maximum limit of elements.If possible, implementations should use smart batching to best handle burst traffic.
- Parameters:
target- in to which elements are drained.limit- maximum number of elements to be drained in a drain operation.- Returns:
- the number of elements actually drained.
-