Class PushPullBlockingQueue<E>
java.lang.Object
com.conversantmedia.util.concurrent.PushPullConcurrentQueue<E>
com.conversantmedia.util.concurrent.PushPullBlockingQueue<E>
- All Implemented Interfaces:
ConcurrentQueue<E>
,Serializable
,Iterable<E>
,Collection<E>
,BlockingQueue<E>
,Queue<E>
public final class PushPullBlockingQueue<E>
extends PushPullConcurrentQueue<E>
implements Serializable, Iterable<E>, Collection<E>, BlockingQueue<E>, Queue<E>
Single thread implementation of disruptor
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate final class
private final class
private final class
private final class
private final class
private final class
private final class
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionPushPullBlockingQueue
(int capacity) Construct a blocking queue of the given fixed capacity.PushPullBlockingQueue
(int capacity, SpinPolicy spinPolicy) Construct a blocking queue with a given fixed capacityPushPullBlockingQueue
(int capacity, Collection<? extends E> c) Construct a blocking queue of the given fixed capacity -
Method Summary
Modifier and TypeMethodDescriptionboolean
boolean
addAll
(Collection<? extends E> c) void
clear()
clear the queue of all elementsboolean
containsAll
(Collection<?> c) int
drainTo
(Collection<? super E> c) int
drainTo
(Collection<? super E> c, int maxElements) element()
private boolean
isFull()
iterator()
final boolean
Add element t to the ringboolean
final E
poll()
remove the first element from the queue and return itvoid
int
remove()
int
return all elements in the queue to the provided array, up to the size of the provided array.boolean
boolean
removeAll
(Collection<?> c) boolean
retainAll
(Collection<?> c) take()
Object[]
toArray()
<T> T[]
toArray
(T[] a) Methods inherited from class com.conversantmedia.util.concurrent.PushPullConcurrentQueue
capacity, contains, isEmpty, peek, size, sumToAvoidOptimization
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface java.util.concurrent.BlockingQueue
contains
Methods inherited from interface java.util.Collection
equals, hashCode, isEmpty, parallelStream, removeIf, size, spliterator, stream, toArray
-
Field Details
-
queueNotFullCondition
-
queueNotEmptyCondition
-
-
Constructor Details
-
PushPullBlockingQueue
public PushPullBlockingQueue(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
-
PushPullBlockingQueue
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, power of two is suggestedspinPolicy
- - determine the level of cpu aggressiveness in waiting
-
PushPullBlockingQueue
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 Details
-
offer
Description copied from interface:ConcurrentQueue
Add element t to the ring- Specified by:
offer
in interfaceBlockingQueue<E>
- Specified by:
offer
in interfaceConcurrentQueue<E>
- Specified by:
offer
in interfaceQueue<E>
- Overrides:
offer
in classPushPullConcurrentQueue<E>
- Parameters:
e
- - element to offer- Returns:
- boolean - true if the operation succeeded
-
poll
Description copied from interface:ConcurrentQueue
remove the first element from the queue and return it- Specified by:
poll
in interfaceConcurrentQueue<E>
- Specified by:
poll
in interfaceQueue<E>
- Overrides:
poll
in classPushPullConcurrentQueue<E>
- Returns:
- T
-
remove
Description copied from interface:ConcurrentQueue
return all elements in the queue to the provided array, up to the size of the provided array.- Specified by:
remove
in interfaceConcurrentQueue<E>
- Overrides:
remove
in classPushPullConcurrentQueue<E>
- Parameters:
e
- - The element array- Returns:
- int - the number of elements added to t
-
remove
-
element
-
put
- Specified by:
put
in interfaceBlockingQueue<E>
- Throws:
InterruptedException
-
offer
- Specified by:
offer
in interfaceBlockingQueue<E>
- Throws:
InterruptedException
-
take
- Specified by:
take
in interfaceBlockingQueue<E>
- Throws:
InterruptedException
-
poll
- Specified by:
poll
in interfaceBlockingQueue<E>
- Throws:
InterruptedException
-
clear
public void clear()Description copied from interface:ConcurrentQueue
clear the queue of all elements- Specified by:
clear
in interfaceCollection<E>
- Specified by:
clear
in interfaceConcurrentQueue<E>
- Overrides:
clear
in classPushPullConcurrentQueue<E>
-
remainingCapacity
public int remainingCapacity()- Specified by:
remainingCapacity
in interfaceBlockingQueue<E>
-
drainTo
- Specified by:
drainTo
in interfaceBlockingQueue<E>
-
drainTo
- Specified by:
drainTo
in interfaceBlockingQueue<E>
-
toArray
- Specified by:
toArray
in interfaceCollection<E>
-
toArray
public <T> T[] toArray(T[] a) - Specified by:
toArray
in interfaceCollection<E>
-
add
- Specified by:
add
in interfaceBlockingQueue<E>
- Specified by:
add
in interfaceCollection<E>
- Specified by:
add
in interfaceQueue<E>
-
remove
- Specified by:
remove
in interfaceBlockingQueue<E>
- Specified by:
remove
in interfaceCollection<E>
-
containsAll
- Specified by:
containsAll
in interfaceCollection<E>
-
addAll
- Specified by:
addAll
in interfaceCollection<E>
-
removeAll
- Specified by:
removeAll
in interfaceCollection<E>
-
retainAll
- Specified by:
retainAll
in interfaceCollection<E>
-
iterator
-
isFull
private boolean isFull()
-