Package org.apache.hadoop.ipc
Class FairCallQueue<E extends Schedulable>
java.lang.Object
java.util.AbstractCollection<E>
java.util.AbstractQueue<E>
org.apache.hadoop.ipc.FairCallQueue<E>
- All Implemented Interfaces:
Iterable<E>,Collection<E>,BlockingQueue<E>,Queue<E>
public class FairCallQueue<E extends Schedulable>
extends AbstractQueue<E>
implements BlockingQueue<E>
A queue with multiple levels for each priority.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intDeprecated.static final StringDeprecated.static final org.slf4j.Logger -
Constructor Summary
ConstructorsConstructorDescriptionFairCallQueue(int priorityLevels, int capacity, String ns, boolean serverFailOverEnabled, Configuration conf) FairCallQueue(int priorityLevels, int capacity, String ns, int[] capacityWeights, boolean serverFailOverEnabled, Configuration conf) Create a FairCallQueue.FairCallQueue(int priorityLevels, int capacity, String ns, Configuration conf) -
Method Summary
Modifier and TypeMethodDescriptionbooleanAdd, put, and offer follow the same pattern: 1.intdrainTo(Collection<? super E> c) intdrainTo(Collection<? super E> c, int maxElements) drainTo defers to each sub-queue.long[]int[]booleaniterator()Iterator is not implemented, as it is not needed.booleanbooleanpeek()Peek, like poll, provides no strict consistency.poll()poll() provides no strict consistency: it is possible for poll to return null even though an element is in the queue.voidintReturns maximum remaining capacity.voidsetMultiplexer(RpcMultiplexer newMux) intsize()Size returns the sum of all sub-queue sizes, so it may be greater than capacity.take()Methods inherited from class java.util.AbstractQueue
addAll, clear, element, removeMethods inherited from class java.util.AbstractCollection
contains, containsAll, isEmpty, remove, removeAll, retainAll, toArray, toArray, toStringMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface java.util.concurrent.BlockingQueue
contains, removeMethods inherited from interface java.util.Collection
addAll, clear, containsAll, equals, hashCode, isEmpty, parallelStream, removeAll, removeIf, retainAll, spliterator, stream, toArray, toArray, toArray
-
Field Details
-
IPC_CALLQUEUE_PRIORITY_LEVELS_DEFAULT
Deprecated.- See Also:
-
IPC_CALLQUEUE_PRIORITY_LEVELS_KEY
Deprecated.- See Also:
-
LOG
public static final org.slf4j.Logger LOG
-
-
Constructor Details
-
FairCallQueue
@VisibleForTesting public FairCallQueue(int priorityLevels, int capacity, String ns, Configuration conf) -
FairCallQueue
@VisibleForTesting public FairCallQueue(int priorityLevels, int capacity, String ns, boolean serverFailOverEnabled, Configuration conf) -
FairCallQueue
public FairCallQueue(int priorityLevels, int capacity, String ns, int[] capacityWeights, boolean serverFailOverEnabled, Configuration conf) Create a FairCallQueue.- Parameters:
priorityLevels- the total size of all multi-level queue priority policiescapacity- the total size of all sub-queuesns- the prefix to use for configurationcapacityWeights- the weights array for capacity allocation among subqueuesserverFailOverEnabled- whether or not to enable callqueue overflow trigger failover for stateless servers when RPC call queue is filledconf- the configuration to read from Notes: Each sub-queue has a capacity of `capacity / numSubqueues`. The first or the highest priority sub-queue has an excess capacity of `capacity % numSubqueues`
-
-
Method Details
-
add
Add, put, and offer follow the same pattern: 1. Get the assigned priorityLevel from the call by scheduler 2. Get the nth sub-queue matching this priorityLevel 3. delegate the call to this sub-queue. But differ in how they handle overflow: - Add will move on to the next queue, throw on last queue overflow - Put will move on to the next queue, block on last queue overflow - Offer does not attempt other queues on overflow- Specified by:
addin interfaceBlockingQueue<E extends Schedulable>- Specified by:
addin interfaceCollection<E extends Schedulable>- Specified by:
addin interfaceQueue<E extends Schedulable>- Overrides:
addin classAbstractQueue<E extends Schedulable>
-
put
- Specified by:
putin interfaceBlockingQueue<E extends Schedulable>- Throws:
InterruptedException
-
offer
- Specified by:
offerin interfaceBlockingQueue<E extends Schedulable>- Throws:
InterruptedException
-
offer
- Specified by:
offerin interfaceBlockingQueue<E extends Schedulable>- Specified by:
offerin interfaceQueue<E extends Schedulable>
-
take
- Specified by:
takein interfaceBlockingQueue<E extends Schedulable>- Throws:
InterruptedException
-
poll
- Specified by:
pollin interfaceBlockingQueue<E extends Schedulable>- Throws:
InterruptedException
-
poll
poll() provides no strict consistency: it is possible for poll to return null even though an element is in the queue.- Specified by:
pollin interfaceQueue<E extends Schedulable>
-
peek
Peek, like poll, provides no strict consistency.- Specified by:
peekin interfaceQueue<E extends Schedulable>
-
size
public int size()Size returns the sum of all sub-queue sizes, so it may be greater than capacity. Note: size provides no strict consistency, and should not be used to control queue IO.- Specified by:
sizein interfaceCollection<E extends Schedulable>- Specified by:
sizein classAbstractCollection<E extends Schedulable>
-
iterator
Iterator is not implemented, as it is not needed.- Specified by:
iteratorin interfaceCollection<E extends Schedulable>- Specified by:
iteratorin interfaceIterable<E extends Schedulable>- Specified by:
iteratorin classAbstractCollection<E extends Schedulable>
-
drainTo
drainTo defers to each sub-queue. Note that draining from a FairCallQueue to another FairCallQueue will likely fail, since the incoming calls may be scheduled differently in the new FairCallQueue. Nonetheless this method is provided for completeness.- Specified by:
drainToin interfaceBlockingQueue<E extends Schedulable>
-
drainTo
- Specified by:
drainToin interfaceBlockingQueue<E extends Schedulable>
-
remainingCapacity
public int remainingCapacity()Returns maximum remaining capacity. This does not reflect how much you can ideally fit in this FairCallQueue, as that would depend on the scheduler's decisions.- Specified by:
remainingCapacityin interfaceBlockingQueue<E extends Schedulable>
-
getQueueSizes
public int[] getQueueSizes() -
getOverflowedCalls
public long[] getOverflowedCalls() -
setMultiplexer
-
isServerFailOverEnabled
@VisibleForTesting public boolean isServerFailOverEnabled()
-