Class AbstractPartitionAssignor

java.lang.Object
org.apache.kafka.clients.consumer.internals.AbstractPartitionAssignor
All Implemented Interfaces:
ConsumerPartitionAssignor
Direct Known Subclasses:
AbstractStickyAssignor, RangeAssignor, RoundRobinAssignor

public abstract class AbstractPartitionAssignor extends Object implements ConsumerPartitionAssignor
Abstract assignor implementation which does some common grunt work (in particular collecting partition counts which are always needed in assignors).
  • Constructor Details

    • AbstractPartitionAssignor

      public AbstractPartitionAssignor()
  • Method Details

    • assign

      public abstract Map<String,List<org.apache.kafka.common.TopicPartition>> assign(Map<String,Integer> partitionsPerTopic, Map<String,ConsumerPartitionAssignor.Subscription> subscriptions)
      Perform the group assignment given the partition counts and member subscriptions
      Parameters:
      partitionsPerTopic - The number of partitions for each subscribed topic. Topics not in metadata will be excluded from this map.
      subscriptions - Map from the member id to their respective topic subscription
      Returns:
      Map from each member to the list of partitions assigned to them.
    • assignPartitions

      public Map<String,List<org.apache.kafka.common.TopicPartition>> assignPartitions(Map<String,List<org.apache.kafka.common.PartitionInfo>> partitionsPerTopic, Map<String,ConsumerPartitionAssignor.Subscription> subscriptions)
      Default implementation of assignPartitions() that does not include racks. This is only included to avoid breaking any custom implementation that extends AbstractPartitionAssignor. Note that this class is internal, but to be safe, we are maintaining compatibility.
    • assign

      public ConsumerPartitionAssignor.GroupAssignment assign(org.apache.kafka.common.Cluster metadata, ConsumerPartitionAssignor.GroupSubscription groupSubscription)
      Description copied from interface: ConsumerPartitionAssignor
      Perform the group assignment given the member subscriptions and current cluster metadata.
      Specified by:
      assign in interface ConsumerPartitionAssignor
      Parameters:
      metadata - Current topic/broker metadata known by consumer
      groupSubscription - Subscriptions from all members including metadata provided through ConsumerPartitionAssignor.subscriptionUserData(Set)
      Returns:
      A map from the members to their respective assignments. This should have one entry for each member in the input subscription map.
    • put

      protected static <K, V> void put(Map<K,List<V>> map, K key, V value)
    • partitions

      protected static List<org.apache.kafka.common.TopicPartition> partitions(String topic, int numPartitions)
    • partitionInfosWithoutRacks

      protected static Map<String,List<org.apache.kafka.common.PartitionInfo>> partitionInfosWithoutRacks(Map<String,Integer> partitionsPerTopic)
    • useRackAwareAssignment

      protected boolean useRackAwareAssignment(Set<String> consumerRacks, Set<String> partitionRacks, Map<org.apache.kafka.common.TopicPartition,Set<String>> racksPerPartition)