public final class QueueUtil extends Object
Modifier and Type | Method and Description |
---|---|
static int |
drainQueue(Queue<?> queue)
Drains the provided queue by the size of the queue as it is known
upfront draining.
|
static <E> int |
drainQueue(Queue<E> queue,
int elementsToDrain,
Predicate<E> drainedCountFilter)
Drains the provided queue by the count provided in
elementsToDrain . |
static <E> int |
drainQueue(Queue<E> queue,
Predicate<E> drainedCountFilter)
Drains the provided queue by the size of the queue as it is known
upfront draining.
|
public static int drainQueue(Queue<?> queue)
The rational for using this method is the same as for using
Collection.clear()
: to remove all the elements from the queue.
There are two major differences to highlight:
Collection.clear()
doesn't.
These points makes this method more applicable than
Collection.clear()
is in conditions where the queue is written
concurrently without blocking the writer threads for the time of
draining the queue and the caller needs to know the number of
elements removed from the queue.
queue
- The queue to be drainedpublic static <E> int drainQueue(Queue<E> queue, Predicate<E> drainedCountFilter)
The rational for using this method is the same as for using
Collection.clear()
: to remove all the elements from the queue.
There are two major differences to highlight:
Collection.clear()
doesn't.
These points makes this method more applicable than
Collection.clear()
is in conditions where the queue is written
concurrently without blocking the writer threads for the time of
draining the queue and the caller needs to know the number of
elements removed from the queue.
You may provide a predicate which will allow some elements to be drained but not be counted against the returned number of drained events.
E
- the type of the elements in the queuequeue
- The queue to be draineddrainedCountFilter
- filter which determines if the drained element
is counted against the returned count. The filter
may be null
in which case all elements
matchpublic static <E> int drainQueue(Queue<E> queue, int elementsToDrain, Predicate<E> drainedCountFilter)
elementsToDrain
.
You may provide a predicate which will allow some elements to be drained
but not be counted against the returned number of drained events.E
- the type of the elements in the queuequeue
- The queue to be drainedelementsToDrain
- The number of elements to be drained from
the queuedrainedCountFilter
- filter which determines if the drained element
is counted against the returned count. The filter
may be null
in which case all elements
matchCopyright © 2019 Hazelcast, Inc.. All Rights Reserved.