Package org.apache.pulsar.broker.service
Class ConsistentHashingStickyKeyConsumerSelector
java.lang.Object
org.apache.pulsar.broker.service.ConsistentHashingStickyKeyConsumerSelector
- All Implemented Interfaces:
StickyKeyConsumerSelector
public class ConsistentHashingStickyKeyConsumerSelector
extends Object
implements StickyKeyConsumerSelector
This is a consumer selector using consistent hashing to evenly split
the number of keys assigned to each consumer.
-
Field Summary
Fields inherited from interface org.apache.pulsar.broker.service.StickyKeyConsumerSelector
DEFAULT_RANGE_SIZE, STICKY_KEY_HASH_NOT_SET -
Constructor Summary
ConstructorsConstructorDescriptionConsistentHashingStickyKeyConsumerSelector(int numberOfPoints) ConsistentHashingStickyKeyConsumerSelector(int numberOfPoints, boolean addOrRemoveReturnsImpactedConsumersResult) ConsistentHashingStickyKeyConsumerSelector(int numberOfPoints, boolean addOrRemoveReturnsImpactedConsumersResult, int rangeMaxValue) -
Method Summary
Modifier and TypeMethodDescriptionaddConsumer(Consumer consumer) Add a new consumer.Get the current mappings of hash range to consumer.org.apache.pulsar.client.api.RangeGet the full range of hash values used by this selector.removeConsumer(Consumer consumer) Remove the consumer.select(int hash) Select a consumer by hash.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.apache.pulsar.broker.service.StickyKeyConsumerSelector
getConsumerKeyHashRanges, makeStickyKeyHash, select
-
Constructor Details
-
ConsistentHashingStickyKeyConsumerSelector
public ConsistentHashingStickyKeyConsumerSelector(int numberOfPoints) -
ConsistentHashingStickyKeyConsumerSelector
public ConsistentHashingStickyKeyConsumerSelector(int numberOfPoints, boolean addOrRemoveReturnsImpactedConsumersResult) -
ConsistentHashingStickyKeyConsumerSelector
public ConsistentHashingStickyKeyConsumerSelector(int numberOfPoints, boolean addOrRemoveReturnsImpactedConsumersResult, int rangeMaxValue)
-
-
Method Details
-
addConsumer
Description copied from interface:StickyKeyConsumerSelectorAdd a new consumer.- Specified by:
addConsumerin interfaceStickyKeyConsumerSelector- Parameters:
consumer- the new consumer to be added- Returns:
- a CompletableFuture that completes with the result of impacted consumers. The result contains information about the existing consumers whose hash ranges were affected by the addition of the new consumer.
-
removeConsumer
Description copied from interface:StickyKeyConsumerSelectorRemove the consumer.- Specified by:
removeConsumerin interfaceStickyKeyConsumerSelector- Parameters:
consumer- the consumer to be removed- Returns:
- the result of impacted consumers. The result contains information about the existing consumers whose hash ranges were affected by the removal of the consumer.
-
select
Description copied from interface:StickyKeyConsumerSelectorSelect a consumer by hash.- Specified by:
selectin interfaceStickyKeyConsumerSelector- Parameters:
hash- the hash corresponding to the sticky key- Returns:
- the selected consumer
-
getKeyHashRange
public org.apache.pulsar.client.api.Range getKeyHashRange()Description copied from interface:StickyKeyConsumerSelectorGet the full range of hash values used by this selector. The upper bound is exclusive.- Specified by:
getKeyHashRangein interfaceStickyKeyConsumerSelector- Returns:
- the full range of hash values
-
getConsumerHashAssignmentsSnapshot
Description copied from interface:StickyKeyConsumerSelectorGet the current mappings of hash range to consumer.- Specified by:
getConsumerHashAssignmentsSnapshotin interfaceStickyKeyConsumerSelector- Returns:
- a snapshot of the consumer hash assignments
-