- Description
- Constructor Summary
- Method Summary
- Constructor Details
- Method Details
- offer(T)
- add(T)
- peek()
- element()
- poll()
- remove()
- remove(Object)
- addAll(Collection)
- removeAll(Collection)
- retainAll(Collection)
- containsAll(Collection)
- contains(Object)
- iterator()
- isEmpty()
- size()
- toArray()
- toArray(E[])
- clear()
- getBatch()
- nextBatch()
- clearToBatch(long)
- exportMessagesToBatch(Queue, long)
- toString()
Class BatchArrayQueue<T>
- Type Parameters:
T
- the type of elements
- All Implemented Interfaces:
Iterable<T>
,Collection<T>
,Queue<T>
A concurrent queue that groups elements in batches.
The elements are stored in a growable circular array along with their batch number:
head tail
| |
elements: [E1, E2, E3, E4, E5]
batches : [ 1, 1, 2, 3, 3]
Elements E1
and E2
belong to batch 1
,
only element E3
belongs to batch 2
, etc.
The batch can be "closed" and a new one "opened" by calling
nextBatch()
.
The elements can be copied with exportMessagesToBatch(Queue, long)
into a different queue, and removed with clearToBatch(long)
.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionboolean
boolean
addAll
(Collection<? extends T> items) void
clear()
Removes all the elements from this queue and resets the batch number to1
.void
clearToBatch
(long batch) Removes all the elements up to the given batch number.boolean
boolean
containsAll
(Collection<?> items) element()
void
exportMessagesToBatch
(Queue<T> target, long batch) Copies the elements of this queue into the given queue, up to the given batch number.long
getBatch()
boolean
isEmpty()
iterator()
void
Closes the current batch and starts a new batch.boolean
Adds the given element to this queue, under the current batch as returned bygetBatch()
.peek()
poll()
remove()
boolean
boolean
removeAll
(Collection<?> c) boolean
retainAll
(Collection<?> c) int
size()
Object[]
toArray()
<E> E[]
toArray
(E[] a) toString()
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
Methods inherited from interface java.util.Collection
equals, hashCode, parallelStream, removeIf, spliterator, stream, toArray
-
Constructor Details
-
Method Details
-
offer
Adds the given element to this queue, under the current batch as returned by
getBatch()
. -
add
-
peek
-
element
-
poll
-
remove
-
remove
- Specified by:
remove
in interfaceCollection<T>
-
addAll
- Specified by:
addAll
in interfaceCollection<T>
-
removeAll
- Specified by:
removeAll
in interfaceCollection<T>
-
retainAll
- Specified by:
retainAll
in interfaceCollection<T>
-
containsAll
- Specified by:
containsAll
in interfaceCollection<T>
-
contains
- Specified by:
contains
in interfaceCollection<T>
-
iterator
-
isEmpty
public boolean isEmpty()- Specified by:
isEmpty
in interfaceCollection<T>
-
size
public int size()- Specified by:
size
in interfaceCollection<T>
-
toArray
- Specified by:
toArray
in interfaceCollection<T>
-
toArray
public <E> E[] toArray(E[] a) - Specified by:
toArray
in interfaceCollection<T>
-
clear
public void clear()Removes all the elements from this queue and resets the batch number to
1
.- Specified by:
clear
in interfaceCollection<T>
-
getBatch
public long getBatch()- Returns:
- the current batch number
-
nextBatch
public void nextBatch()Closes the current batch and starts a new batch.
The next element offered to this queue will belong to the new batch.
-
clearToBatch
public void clearToBatch(long batch) Removes all the elements up to the given batch number.
For example, given:
head tail | | elements: [E1, E2, E3, E4, E5] batches : [ 1, 1, 2, 3, 3]
then calling
clearToBatch(1)
would leave the queue in this state:head tail | | elements: [null, null, E3, E4, E5] batches : [ 0, 0, 2, 3, 3]
- Parameters:
batch
- the batch number- See Also:
-
exportMessagesToBatch
Copies the elements of this queue into the given queue, up to the given batch number.
For example, given:
this queue: head tail | | elements: [E1, E2, E3, E4, E5] batches : [ 1, 1, 2, 3, 3] target queue: []
then calling
exportMessagesToBatch(2)
would copy the elements belonging to batches up to2
into the target queue, leaving this queue unchanged:this queue: head tail | | elements: [E1, E2, E3, E4, E5] batches : [ 1, 1, 2, 3, 3] target queue: [E1, E2, E3]
- Parameters:
target
- the target queuebatch
- the batch number- See Also:
-
toString
-