Class AbstractDispatcherMultipleConsumers
- java.lang.Object
-
- org.apache.pulsar.broker.service.AbstractBaseDispatcher
-
- org.apache.pulsar.broker.service.AbstractDispatcherMultipleConsumers
-
- All Implemented Interfaces:
Dispatcher
- Direct Known Subclasses:
NonPersistentDispatcherMultipleConsumers,PersistentDispatcherMultipleConsumers
public abstract class AbstractDispatcherMultipleConsumers extends AbstractBaseDispatcher
-
-
Field Summary
Fields Modifier and Type Field Description protected java.util.concurrent.CopyOnWriteArrayList<Consumer>consumerListprotected com.carrotsearch.hppc.ObjectSet<Consumer>consumerSetprotected intcurrentConsumerRoundRobinIndexprotected static intFALSEprotected static java.util.concurrent.atomic.AtomicIntegerFieldUpdater<AbstractDispatcherMultipleConsumers>IS_CLOSED_UPDATERprotected static intTRUE-
Fields inherited from class org.apache.pulsar.broker.service.AbstractBaseDispatcher
serviceConfig, subscription
-
-
Constructor Summary
Constructors Modifier Constructor Description protectedAbstractDispatcherMultipleConsumers(Subscription subscription, org.apache.pulsar.broker.ServiceConfiguration serviceConfig)
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected voidcancelPendingRead()booleancanUnsubscribe(Consumer consumer)java.util.concurrent.CopyOnWriteArrayList<Consumer>getConsumers()ConsumergetNextConsumer()Broker gives more priority while dispatching messages.ConsumergetRandomConsumer()Get random consumer from consumerList.org.apache.pulsar.common.api.proto.CommandSubscribe.SubTypegetType()booleanisClosed()abstract booleanisConsumerAvailable(Consumer consumer)booleanisConsumerConnected()-
Methods inherited from class org.apache.pulsar.broker.service.AbstractBaseDispatcher
computeReadLimits, filterEntriesForConsumer, filterEntriesForConsumer, isConsumersExceededOnSubscription, isConsumersExceededOnSubscription, peekStickyKey, resetCloseFuture, updateEntryWrapperWithMetadata
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.apache.pulsar.broker.service.Dispatcher
addConsumer, addUnAckedMessages, checkAndUnblockIfStuck, clearDelayedMessages, close, consumerFlow, cursorIsReset, disconnectActiveConsumers, disconnectAllConsumers, disconnectAllConsumers, getNumberOfDelayedMessages, getRateLimiter, getRedeliveryTracker, initializeDispatchRateLimiterIfNeeded, markDeletePositionMoveForward, redeliverUnacknowledgedMessages, redeliverUnacknowledgedMessages, removeConsumer, reset, trackDelayedDelivery, updateRateLimiter
-
-
-
-
Field Detail
-
consumerList
protected final java.util.concurrent.CopyOnWriteArrayList<Consumer> consumerList
-
consumerSet
protected final com.carrotsearch.hppc.ObjectSet<Consumer> consumerSet
-
currentConsumerRoundRobinIndex
protected volatile int currentConsumerRoundRobinIndex
-
FALSE
protected static final int FALSE
- See Also:
- Constant Field Values
-
TRUE
protected static final int TRUE
- See Also:
- Constant Field Values
-
IS_CLOSED_UPDATER
protected static final java.util.concurrent.atomic.AtomicIntegerFieldUpdater<AbstractDispatcherMultipleConsumers> IS_CLOSED_UPDATER
-
-
Constructor Detail
-
AbstractDispatcherMultipleConsumers
protected AbstractDispatcherMultipleConsumers(Subscription subscription, org.apache.pulsar.broker.ServiceConfiguration serviceConfig)
-
-
Method Detail
-
isConsumerConnected
public boolean isConsumerConnected()
-
getConsumers
public java.util.concurrent.CopyOnWriteArrayList<Consumer> getConsumers()
-
canUnsubscribe
public boolean canUnsubscribe(Consumer consumer)
-
isClosed
public boolean isClosed()
-
getType
public org.apache.pulsar.common.api.proto.CommandSubscribe.SubType getType()
-
isConsumerAvailable
public abstract boolean isConsumerAvailable(Consumer consumer)
-
cancelPendingRead
protected void cancelPendingRead()
-
getNextConsumer
public Consumer getNextConsumer()
Broker gives more priority while dispatching messages. Here, broker follows descending priorities. (eg: 0=max-priority, 1, 2,..)
Broker will first dispatch messages to max priority-level consumers if they have permits, else broker will consider next priority level consumers. Also on the same priority-level, it selects consumer in round-robin manner.
If subscription has consumer-A with priorityLevel 1 and Consumer-B with priorityLevel 2 then broker will dispatch messages to only consumer-A until it runs out permit and then broker starts dispatching messages to Consumer-B.
Consumer PriorityLevel Permits C1 0 2 C2 0 1 C3 0 1 C4 1 2 C5 1 1 Result of getNextConsumer(): C1, C2, C3, C1, C4, C5, C4
Algorithm: 1. consumerList: it stores consumers in sorted-list: max-priority stored first 2. currentConsumerRoundRobinIndex: it always stores last served consumer-index Each time getNextConsumer() is called:
1. It always starts to traverse from the max-priority consumer (first element) from sorted-list 2. Consumers on same priority-level will be treated equally and it tries to pick one of them in round-robin manner 3. If consumer is not available on given priority-level then only it will go to the next lower priority-level consumers 4. Returns null in case it doesn't find any available consumer
- Returns:
- nextAvailableConsumer
-
getRandomConsumer
public Consumer getRandomConsumer()
Get random consumer from consumerList.- Returns:
- null if no consumer available, else return random consumer from consumerList
-
-