Class DiscardingBlockingQueue<E>
java.lang.Object
java.util.AbstractCollection<E>
java.util.AbstractQueue<E>
java.util.concurrent.ArrayBlockingQueue<E>
org.jmxtrans.embedded.util.concurrent.DiscardingBlockingQueue<E>
- All Implemented Interfaces:
Serializable,Iterable<E>,Collection<E>,BlockingQueue<E>,Queue<E>,DiscardingBlockingQueueMBean
public class DiscardingBlockingQueue<E> extends ArrayBlockingQueue<E> implements DiscardingBlockingQueueMBean
Automatically discard the oldest element if the queue is full.
- Author:
- Cyrille Le Clerc
- See Also:
- Serialized Form
-
Constructor Summary
Constructors Constructor Description DiscardingBlockingQueue(int capacity)Creates aDiscardingBlockingQueuewith the given (fixed) capacity and default access policy.DiscardingBlockingQueue(int capacity, boolean fair)Creates aDiscardingBlockingQueuewith the given (fixed) capacity and the specified access policy.DiscardingBlockingQueue(int capacity, boolean fair, Collection<? extends E> c)Creates anDiscardingBlockingQueuewith the given (fixed) capacity, the specified access policy and initially containing the elements of the given collection, added in traversal order of the collection's iterator. -
Method Summary
Modifier and Type Method Description booleanadd(E e)Add the given element to the BlockingQueue removing elements if necessary (ie if the queue is full).booleanaddAll(Collection<? extends E> c)Offer the given elements to the BlockingQueue removing elements if necessary (ie if the queue is full).protected voiddiscardingOffer(E e)Offer the given element to the BlockingQueue removing elements if necessary (ie if the queue is full).intgetDiscardedElementCount()booleanoffer(E e)Offer the given element to the BlockingQueue removing elements if necessary (ie if the queue is full).booleanoffer(E e, long timeout, TimeUnit unit)Offer the given element to the BlockingQueue removing elements if necessary (ie if the queue is full).voidput(E e)Add the given element to the BlockingQueue removing elements if necessary (ie if the queue is full).Methods inherited from class java.util.concurrent.ArrayBlockingQueue
clear, contains, drainTo, drainTo, forEach, iterator, peek, poll, poll, remainingCapacity, remove, removeAll, removeIf, retainAll, size, spliterator, take, toArray, toArray, toStringMethods inherited from class java.util.AbstractQueue
element, removeMethods inherited from class java.util.AbstractCollection
containsAll, isEmptyMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface java.util.Collection
containsAll, equals, hashCode, isEmpty, parallelStream, stream, toArray
-
Constructor Details
-
DiscardingBlockingQueue
public DiscardingBlockingQueue(int capacity)Creates aDiscardingBlockingQueuewith the given (fixed) capacity and default access policy.- Parameters:
capacity- the capacity of this queue- Throws:
IllegalArgumentException- ifcapacity < 1
-
DiscardingBlockingQueue
public DiscardingBlockingQueue(int capacity, boolean fair)Creates aDiscardingBlockingQueuewith the given (fixed) capacity and the specified access policy.- Parameters:
capacity- the capacity of this queuefair- iftruethen queue accesses for threads blocked on insertion or removal, are processed in FIFO order; iffalsethe access order is unspecified.- Throws:
IllegalArgumentException- ifcapacity < 1
-
DiscardingBlockingQueue
Creates anDiscardingBlockingQueuewith the given (fixed) capacity, the specified access policy and initially containing the elements of the given collection, added in traversal order of the collection's iterator.- Parameters:
capacity- the capacity of this queuefair- iftruethen queue accesses for threads blocked on insertion or removal, are processed in FIFO order; iffalsethe access order is unspecified.c- the collection of elements to initially contain- Throws:
IllegalArgumentException- ifcapacityis less thanc.size(), or less than 1.NullPointerException- if the specified collection or any
-
-
Method Details
-
discardingOffer
Offer the given element to the BlockingQueue removing elements if necessary (ie if the queue is full).- Parameters:
e- the element to add to the queue
-
add
Add the given element to the BlockingQueue removing elements if necessary (ie if the queue is full).- Specified by:
addin interfaceBlockingQueue<E>- Specified by:
addin interfaceCollection<E>- Specified by:
addin interfaceQueue<E>- Overrides:
addin classArrayBlockingQueue<E>- Parameters:
e- the element to add to the queue- Returns:
- {$code true}
-
offer
Offer the given element to the BlockingQueue removing elements if necessary (ie if the queue is full).- Specified by:
offerin interfaceBlockingQueue<E>- Specified by:
offerin interfaceQueue<E>- Overrides:
offerin classArrayBlockingQueue<E>- Parameters:
e- the element to add to the queue- Returns:
- {$code true}
-
put
Add the given element to the BlockingQueue removing elements if necessary (ie if the queue is full).- Specified by:
putin interfaceBlockingQueue<E>- Overrides:
putin classArrayBlockingQueue<E>- Parameters:
e- the element to add to the queue- Throws:
InterruptedException
-
offer
Offer the given element to the BlockingQueue removing elements if necessary (ie if the queue is full).- Specified by:
offerin interfaceBlockingQueue<E>- Overrides:
offerin classArrayBlockingQueue<E>- Parameters:
e- the element to add to the queue- Returns:
- {$code true}
- Throws:
InterruptedException
-
addAll
Offer the given elements to the BlockingQueue removing elements if necessary (ie if the queue is full).- Specified by:
addAllin interfaceCollection<E>- Overrides:
addAllin classAbstractQueue<E>- Parameters:
c- the element to add to the queue- Returns:
- {$code true} if the given elements collection is not empty
-
getDiscardedElementCount
public int getDiscardedElementCount()- Specified by:
getDiscardedElementCountin interfaceDiscardingBlockingQueueMBean
-