Class MPMCBlockingQueue<E>
- java.lang.Object
-
- com.conversantmedia.util.concurrent.MPMCConcurrentQueue<E>
-
- com.conversantmedia.util.concurrent.MPMCBlockingQueue<E>
-
- All Implemented Interfaces:
ConcurrentQueue<E>,java.io.Serializable,java.lang.Iterable<E>,java.util.Collection<E>,java.util.concurrent.BlockingQueue<E>,java.util.Queue<E>
public final class MPMCBlockingQueue<E> extends MPMCConcurrentQueue<E> implements java.io.Serializable, java.lang.Iterable<E>, java.util.Collection<E>, java.util.concurrent.BlockingQueue<E>, java.util.Queue<E>, ConcurrentQueue<E>
Alternative implementation for benchmarking purposes- See Also:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private classMPMCBlockingQueue.QueueNotEmptyprivate classMPMCBlockingQueue.QueueNotFullprivate classMPMCBlockingQueue.RingIterprivate classMPMCBlockingQueue.SpinningQueueNotEmptyprivate classMPMCBlockingQueue.SpinningQueueNotFullprivate classMPMCBlockingQueue.WaitingQueueNotEmptyprivate classMPMCBlockingQueue.WaitingQueueNotFull-
Nested classes/interfaces inherited from class com.conversantmedia.util.concurrent.MPMCConcurrentQueue
MPMCConcurrentQueue.Cell<R>
-
-
Field Summary
Fields Modifier and Type Field Description protected ConditionqueueNotEmptyConditionprotected ConditionqueueNotFullCondition
-
Constructor Summary
Constructors Constructor Description MPMCBlockingQueue(int capacity)Construct a blocking queue of the given fixed capacity.MPMCBlockingQueue(int capacity, SpinPolicy spinPolicy)Construct a blocking queue with a given fixed capacityMPMCBlockingQueue(int capacity, java.util.Collection<? extends E> c)Construct a blocking queue of the given fixed capacity
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanadd(E e)booleanaddAll(java.util.Collection<? extends E> c)voidclear()clear the queue of all elementsbooleancontainsAll(java.util.Collection<?> c)intdrainTo(java.util.Collection<? super E> c)intdrainTo(java.util.Collection<? super E> c, int maxElements)Eelement()private booleanisFull()java.util.Iterator<E>iterator()booleanoffer(E e)Add element t to the ringbooleanoffer(E e, long timeout, java.util.concurrent.TimeUnit unit)Epoll()remove the first element from the queue and return itEpoll(long timeout, java.util.concurrent.TimeUnit unit)voidput(E e)intremainingCapacity()Eremove()intremove(E[] e)return all elements in the queue to the provided array, up to the size of the provided array.booleanremove(java.lang.Object o)booleanremoveAll(java.util.Collection<?> c)booleanretainAll(java.util.Collection<?> c)Etake()java.lang.Object[]toArray()<T> T[]toArray(T[] a)-
Methods inherited from class com.conversantmedia.util.concurrent.MPMCConcurrentQueue
capacity, contains, isEmpty, peek, size
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface java.util.Collection
equals, hashCode, isEmpty, parallelStream, removeIf, size, spliterator, stream, toArray
-
-
-
-
Constructor Detail
-
MPMCBlockingQueue
public MPMCBlockingQueue(int capacity)
Construct a blocking queue of the given fixed capacity.
Note: actual capacity will be the next power of two larger than capacity.- Parameters:
capacity- maximum capacity of this queue
-
MPMCBlockingQueue
public MPMCBlockingQueue(int capacity, SpinPolicy spinPolicy)Construct a blocking queue with a given fixed capacity
Note: actual capacity will be the next power of two larger than capacity. Waiting locking may be used in servers that are tuned for it, waiting locking provides a high performance locking implementation which is approximately a factor of 2 improvement in throughput (40M/s for 1-1 thread transfers) However waiting locking is more CPU aggressive and causes servers that may be configured with far too many threads to show very high load averages. This is probably not as detrimental as it is annoying.- Parameters:
capacity- - the queue capacity, suggest using a power of 2spinPolicy- - determine the level of cpu aggressiveness in waiting
-
MPMCBlockingQueue
public MPMCBlockingQueue(int capacity, java.util.Collection<? extends E> c)Construct a blocking queue of the given fixed capacity
Note: actual capacity will be the next power of two larger than capacity.
The values from the collection, c, are appended to the queue in iteration order. If the number of elements in the collection exceeds the actual capacity, then the additional elements overwrite the previous ones until all elements have been written once.- Parameters:
capacity- maximum capacity of this queuec- A collection to use to populate inital values
-
-
Method Detail
-
offer
public final boolean offer(E e)
Description copied from interface:ConcurrentQueueAdd element t to the ring- Specified by:
offerin interfacejava.util.concurrent.BlockingQueue<E>- Specified by:
offerin interfaceConcurrentQueue<E>- Specified by:
offerin interfacejava.util.Queue<E>- Overrides:
offerin classMPMCConcurrentQueue<E>- Parameters:
e- - element to offer- Returns:
- boolean - true if the operation succeeded
-
poll
public final E poll()
Description copied from interface:ConcurrentQueueremove the first element from the queue and return it- Specified by:
pollin interfaceConcurrentQueue<E>- Specified by:
pollin interfacejava.util.Queue<E>- Overrides:
pollin classMPMCConcurrentQueue<E>- Returns:
- T
-
remove
public int remove(E[] e)
Description copied from interface:ConcurrentQueuereturn all elements in the queue to the provided array, up to the size of the provided array.- Specified by:
removein interfaceConcurrentQueue<E>- Overrides:
removein classMPMCConcurrentQueue<E>- Parameters:
e- - The element array- Returns:
- int - the number of elements added to t
-
put
public void put(E e) throws java.lang.InterruptedException
- Specified by:
putin interfacejava.util.concurrent.BlockingQueue<E>- Throws:
java.lang.InterruptedException
-
offer
public boolean offer(E e, long timeout, java.util.concurrent.TimeUnit unit) throws java.lang.InterruptedException
- Specified by:
offerin interfacejava.util.concurrent.BlockingQueue<E>- Throws:
java.lang.InterruptedException
-
take
public E take() throws java.lang.InterruptedException
- Specified by:
takein interfacejava.util.concurrent.BlockingQueue<E>- Throws:
java.lang.InterruptedException
-
poll
public E poll(long timeout, java.util.concurrent.TimeUnit unit) throws java.lang.InterruptedException
- Specified by:
pollin interfacejava.util.concurrent.BlockingQueue<E>- Throws:
java.lang.InterruptedException
-
clear
public void clear()
Description copied from interface:ConcurrentQueueclear the queue of all elements- Specified by:
clearin interfacejava.util.Collection<E>- Specified by:
clearin interfaceConcurrentQueue<E>- Overrides:
clearin classMPMCConcurrentQueue<E>
-
remainingCapacity
public int remainingCapacity()
- Specified by:
remainingCapacityin interfacejava.util.concurrent.BlockingQueue<E>
-
drainTo
public int drainTo(java.util.Collection<? super E> c)
- Specified by:
drainToin interfacejava.util.concurrent.BlockingQueue<E>
-
drainTo
public int drainTo(java.util.Collection<? super E> c, int maxElements)
- Specified by:
drainToin interfacejava.util.concurrent.BlockingQueue<E>
-
toArray
public java.lang.Object[] toArray()
- Specified by:
toArrayin interfacejava.util.Collection<E>
-
toArray
public <T> T[] toArray(T[] a)
- Specified by:
toArrayin interfacejava.util.Collection<E>
-
add
public boolean add(E e)
-
remove
public boolean remove(java.lang.Object o)
-
containsAll
public boolean containsAll(java.util.Collection<?> c)
- Specified by:
containsAllin interfacejava.util.Collection<E>
-
addAll
public boolean addAll(java.util.Collection<? extends E> c)
- Specified by:
addAllin interfacejava.util.Collection<E>
-
removeAll
public boolean removeAll(java.util.Collection<?> c)
- Specified by:
removeAllin interfacejava.util.Collection<E>
-
retainAll
public boolean retainAll(java.util.Collection<?> c)
- Specified by:
retainAllin interfacejava.util.Collection<E>
-
iterator
public java.util.Iterator<E> iterator()
-
isFull
private final boolean isFull()
-
-