Class: Rdkafka::Consumer::TopicPartitionList
- Inherits:
-
Object
- Object
- Rdkafka::Consumer::TopicPartitionList
- Defined in:
- lib/rdkafka/consumer/topic_partition_list.rb
Overview
A list of topics with their partition information
Instance Method Summary collapse
- #==(other) ⇒ Object
-
#add_topic(topic, partitions = nil) ⇒ nil
Add a topic with optionally partitions to the list.
-
#add_topic_and_partitions_with_offsets(topic, partitions_with_offsets) ⇒ nil
Add a topic with partitions and offsets set to the list Calling this method multiple times for the same topic will overwrite the previous configuraton.
-
#count ⇒ Integer
Number of items in the list.
-
#empty? ⇒ Boolean
Whether this list is empty.
-
#initialize(data = nil) ⇒ TopicPartitionList
constructor
Create a topic partition list.
-
#to_h ⇒ Hash{String => Array<Partition>,nil}
Return a
Hash
with the topics as keys and and an array of partition information as the value if present. -
#to_s ⇒ String
Human readable representation of this list.
Constructor Details
#initialize(data = nil) ⇒ TopicPartitionList
Create a topic partition list.
10 11 12 |
# File 'lib/rdkafka/consumer/topic_partition_list.rb', line 10 def initialize(data=nil) @data = data || {} end |
Instance Method Details
#==(other) ⇒ Object
85 86 87 |
# File 'lib/rdkafka/consumer/topic_partition_list.rb', line 85 def ==(other) self.to_h == other.to_h end |
#add_topic(topic, partitions = nil) ⇒ nil
Add a topic with optionally partitions to the list. Calling this method multiple times for the same topic will overwrite the previous configuraton.
50 51 52 53 54 55 56 57 58 59 |
# File 'lib/rdkafka/consumer/topic_partition_list.rb', line 50 def add_topic(topic, partitions=nil) if partitions.nil? @data[topic.to_s] = nil else if partitions.is_a? Integer partitions = (0..partitions - 1) end @data[topic.to_s] = partitions.map { |p| Partition.new(p, nil, 0) } end end |
#add_topic_and_partitions_with_offsets(topic, partitions_with_offsets) ⇒ nil
Add a topic with partitions and offsets set to the list Calling this method multiple times for the same topic will overwrite the previous configuraton.
68 69 70 |
# File 'lib/rdkafka/consumer/topic_partition_list.rb', line 68 def add_topic_and_partitions_with_offsets(topic, partitions_with_offsets) @data[topic.to_s] = partitions_with_offsets.map { |p, o| Partition.new(p, o) } end |
#count ⇒ Integer
Number of items in the list
16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/rdkafka/consumer/topic_partition_list.rb', line 16 def count i = 0 @data.each do |_topic, partitions| if partitions i += partitions.count else i+= 1 end end i end |
#empty? ⇒ Boolean
Whether this list is empty
30 31 32 |
# File 'lib/rdkafka/consumer/topic_partition_list.rb', line 30 def empty? @data.empty? end |
#to_h ⇒ Hash{String => Array<Partition>,nil}
Return a Hash
with the topics as keys and and an array of partition information as the value if present.
75 76 77 |
# File 'lib/rdkafka/consumer/topic_partition_list.rb', line 75 def to_h @data end |
#to_s ⇒ String
Human readable representation of this list.
81 82 83 |
# File 'lib/rdkafka/consumer/topic_partition_list.rb', line 81 def to_s "<TopicPartitionList: #{to_h}>" end |