Package org.agrona.concurrent
Class AbstractConcurrentArrayQueue<E>
java.lang.Object
org.agrona.concurrent.AbstractConcurrentArrayQueue<E>
- Type Parameters:
E- type of the queue elements.
- All Implemented Interfaces:
Iterable<E>,Collection<E>,Queue<E>,Pipe<E>,QueuedPipe<E>
- Direct Known Subclasses:
ManyToManyConcurrentArrayQueue,ManyToOneConcurrentArrayQueue,OneToOneConcurrentArrayQueue
Left over immutable queue fields.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final E[]Backing array.protected static final intArray base.protected final intQueue capacity.protected longHead index.protected static final longOffset of theheadfield.protected longCached head index.protected static final longOffset of thesharedHeadCachefield.protected longShared cached head index.protected static final intShift for scale.protected longTail index.protected static final longOffset of thetailfield. -
Constructor Summary
ConstructorsConstructorDescriptionAbstractConcurrentArrayQueue(int requestedCapacity) Constructs a queue with the requested capacity. -
Method Summary
Modifier and TypeMethodDescriptionbooleanbooleanaddAll(Collection<? extends E> c) longThe number of items added to this container since creation.intcapacity()The maximum capacity of this container to hold items.voidclear()booleanbooleancontainsAll(Collection<?> c) element()booleanisEmpty()iterator()peek()intGet the remaining capacity for elements in the container given the current size.remove()booleanbooleanremoveAll(Collection<?> c) longThe number of items removed from this container since creation.booleanretainAll(Collection<?> c) static longsequenceToBufferOffset(long sequence, long mask) Compute buffer offset based on the given sequence and the mask.intsize()The number of items currently in the container.Object[]toArray()<T> T[]toArray(T[] a) Methods 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
-
TAIL_OFFSET
protected static final long TAIL_OFFSETOffset of thetailfield. -
SHARED_HEAD_CACHE_OFFSET
protected static final long SHARED_HEAD_CACHE_OFFSETOffset of thesharedHeadCachefield. -
HEAD_OFFSET
protected static final long HEAD_OFFSETOffset of theheadfield. -
BUFFER_ARRAY_BASE
protected static final int BUFFER_ARRAY_BASEArray base. -
SHIFT_FOR_SCALE
protected static final int SHIFT_FOR_SCALEShift for scale. -
capacity
protected final int capacityQueue capacity. -
buffer
Backing array. -
head
protected volatile long headHead index. -
tail
protected volatile long tailTail index. -
headCache
protected long headCacheCached head index.
-
-
Constructor Details
-
AbstractConcurrentArrayQueue
public AbstractConcurrentArrayQueue(int requestedCapacity) Constructs a queue with the requested capacity.- Parameters:
requestedCapacity- of the queue.
-
-
Method Details
-
addedCount
public long addedCount()The number of items added to this container since creation.- Specified by:
addedCountin interfacePipe<E>- Returns:
- the number of items added.
-
removedCount
public long removedCount()The number of items removed from this container since creation.- Specified by:
removedCountin interfacePipe<E>- Returns:
- the number of items removed.
-
capacity
public int capacity()The maximum capacity of this container to hold items. -
remainingCapacity
public int remainingCapacity()Get the remaining capacity for elements in the container given the current size.- Specified by:
remainingCapacityin interfacePipe<E>- Returns:
- remaining capacity of the container.
-
peek
-
add
-
remove
-
element
-
contains
- Specified by:
containsin interfaceCollection<E>
-
iterator
-
toArray
- Specified by:
toArrayin interfaceCollection<E>
-
toArray
public <T> T[] toArray(T[] a) - Specified by:
toArrayin interfaceCollection<E>
-
remove
- Specified by:
removein interfaceCollection<E>
-
containsAll
- Specified by:
containsAllin interfaceCollection<E>
-
addAll
- Specified by:
addAllin interfaceCollection<E>
-
removeAll
- Specified by:
removeAllin interfaceCollection<E>
-
retainAll
- Specified by:
retainAllin interfaceCollection<E>
-
clear
public void clear()- Specified by:
clearin interfaceCollection<E>
-
isEmpty
public boolean isEmpty()- Specified by:
isEmptyin interfaceCollection<E>
-
size
public int size()The number of items currently in the container. -
sequenceToBufferOffset
public static long sequenceToBufferOffset(long sequence, long mask) Compute buffer offset based on the given sequence and the mask.- Parameters:
sequence- to compute the offset from.mask- to apply.- Returns:
- buffer offset.
-