Class WeightedQueue<T>
java.lang.Object
org.apache.cassandra.utils.concurrent.WeightedQueue<T>
- All Implemented Interfaces:
Iterable<T>,Collection<T>,BlockingQueue<T>,Queue<T>
Weighted queue is a wrapper around any blocking queue that turns it into a blocking weighted queue. The queue
will weigh each element being added and removed. Adding to the queue is blocked if adding would violate
the weight bound.
If an element weighs in at larger than the capacity of the queue then exactly one such element will be allowed
into the queue at a time.
If the weight of an object changes after it is added you are going to have a bad time. Checking weight should be
cheap so memoize expensive to compute weights. If weight throws that can also result in leaked permits so it's
always a good idea to memoize weight so it doesn't throw.
In the interests of not writing unit tests for methods no one uses there is a lot of UnsupportedOperationException.
If you need them then add them and add proper unit tests to WeightedQueueTest. "Good" tests. 100% coverage including
exception paths and resource leaks.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interfacestatic interface -
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionWeightedQueue(int maxWeight) WeightedQueue(int maxWeight, BlockingQueue<T> queue, WeightedQueue.Weigher<T> weigher) -
Method Summary
Modifier and TypeMethodDescriptionbooleanbooleanaddAll(Collection<? extends T> c) voidclear()booleanbooleancontainsAll(Collection<?> c) intdrainTo(Collection<? super T> c) intdrainTo(Collection<? super T> c, int maxElements) element()booleanisEmpty()iterator()booleanbooleanpeek()poll()voidintremove()booleanbooleanremoveAll(Collection<?> c) booleanretainAll(Collection<?> c) intsize()take()Object[]toArray()<T1> T1[]toArray(T1[] 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
-
NATURAL_WEIGHER
-
-
Constructor Details
-
WeightedQueue
public WeightedQueue(int maxWeight) -
WeightedQueue
-
-
Method Details
-
add
- Specified by:
addin interfaceBlockingQueue<T>- Specified by:
addin interfaceCollection<T>- Specified by:
addin interfaceQueue<T>
-
offer
-
remove
-
poll
-
element
-
peek
-
put
- Specified by:
putin interfaceBlockingQueue<T>- Throws:
InterruptedException
-
offer
- Specified by:
offerin interfaceBlockingQueue<T>- Throws:
InterruptedException
-
take
- Specified by:
takein interfaceBlockingQueue<T>- Throws:
InterruptedException
-
poll
- Specified by:
pollin interfaceBlockingQueue<T>- Throws:
InterruptedException
-
remainingCapacity
public int remainingCapacity()- Specified by:
remainingCapacityin interfaceBlockingQueue<T>
-
remove
- Specified by:
removein interfaceBlockingQueue<T>- Specified by:
removein interfaceCollection<T>
-
containsAll
- Specified by:
containsAllin interfaceCollection<T>
-
addAll
- Specified by:
addAllin interfaceCollection<T>
-
removeAll
- Specified by:
removeAllin interfaceCollection<T>
-
retainAll
- Specified by:
retainAllin interfaceCollection<T>
-
clear
public void clear()- Specified by:
clearin interfaceCollection<T>
-
size
public int size()- Specified by:
sizein interfaceCollection<T>
-
isEmpty
public boolean isEmpty()- Specified by:
isEmptyin interfaceCollection<T>
-
contains
- Specified by:
containsin interfaceBlockingQueue<T>- Specified by:
containsin interfaceCollection<T>
-
iterator
-
toArray
- Specified by:
toArrayin interfaceCollection<T>
-
toArray
public <T1> T1[] toArray(T1[] a) - Specified by:
toArrayin interfaceCollection<T>
-
drainTo
- Specified by:
drainToin interfaceBlockingQueue<T>
-
drainTo
- Specified by:
drainToin interfaceBlockingQueue<T>
-