Class: Kafka::FFI::TopicPartitionList
- Inherits:
-
FFI::Struct
- Object
- FFI::Struct
- Kafka::FFI::TopicPartitionList
- Defined in:
- lib/kafka/ffi/topic_partition_list.rb
Class Method Summary collapse
-
.new(count = 0) ⇒ TopicPartitionList
New initializes a new TopicPartitionList with an initial capacity to hold
count
items.
Instance Method Summary collapse
-
#add(topic, partition = -1)) ⇒ TopicPartition
Add a topic + partition combination to the list.
-
#add_range(topic, range_or_lower, upper = nil) ⇒ Object
Add a range of TopicPartitions to the list.
-
#copy ⇒ TopicPartitionList
Duplicate the TopicPartitionList as a new TopicPartitionList that is identical to the current one.
-
#del(topic, partition) ⇒ Boolean
(also: #delete)
Remove a TopicPartition by partition.
-
#del_by_idx(idx) ⇒ Boolean
(also: #delete_by_index)
Remove a TopicPartition by index.
-
#destroy ⇒ Object
Free all resources used by the list and the list itself.
-
#elements ⇒ Array<TopicPartition>
Retrieves the set of TopicPartitions for the list.
-
#empty? ⇒ Boolean
Returns true when the TopicPartitionList is empty.
-
#find(topic, partition) ⇒ TopicPartition?
Find the TopicPartition in the set for the given topic + partition.
-
#set_offset(topic, partition, offset) ⇒ Integer
Set the consumed offset for topic and partition.
-
#size ⇒ Integer
Returns the number of elements in the TopicPartitionList.
-
#sort(&block) ⇒ Object
Sort the TopicPartitionList.
Class Method Details
.new(count = 0) ⇒ TopicPartitionList
New initializes a new TopicPartitionList with an initial capacity to hold
count
items.
20 21 22 23 24 25 26 27 28 |
# File 'lib/kafka/ffi/topic_partition_list.rb', line 20 def self.new(count = 0) # Handle initialization through FFI. This will be called by # rd_kafka_topic_partition_list_new. if count.is_a?(::FFI::Pointer) return super(count) end ::Kafka::FFI.rd_kafka_topic_partition_list_new(count) end |
Instance Method Details
#add(topic, partition = -1)) ⇒ TopicPartition
Add a topic + partition combination to the list
51 52 53 |
# File 'lib/kafka/ffi/topic_partition_list.rb', line 51 def add(topic, partition = -1) ::Kafka::FFI.rd_kafka_topic_partition_list_add(self, topic.to_s, partition) end |
#add_range(topic, range_or_lower, upper = nil) ⇒ Object
Add a range of TopicPartitions to the list.
63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/kafka/ffi/topic_partition_list.rb', line 63 def add_range(topic, range_or_lower, upper = nil) lower = range_or_lower # Allows passing a Range for convenience. if range_or_lower.is_a?(Range) lower = range_or_lower.min upper = range_or_lower.max elsif upper.nil? raise ArgumentError, "upper was nil but must be provided when lower is not a Range" end ::Kafka::FFI.rd_kafka_topic_partition_list_add_range(self, topic.to_s, lower.to_i, upper.to_i) end |
#copy ⇒ TopicPartitionList
Duplicate the TopicPartitionList as a new TopicPartitionList that is identical to the current one.
103 104 105 |
# File 'lib/kafka/ffi/topic_partition_list.rb', line 103 def copy ::Kafka::FFI.rd_kafka_topic_partition_list_copy(self) end |
#del(topic, partition) ⇒ Boolean Also known as: delete
Remove a TopicPartition by partition
83 84 85 |
# File 'lib/kafka/ffi/topic_partition_list.rb', line 83 def del(topic, partition) ::Kafka::FFI.rd_kafka_topic_partition_list_del(self, topic.to_s, partition) == 1 end |
#del_by_idx(idx) ⇒ Boolean Also known as: delete_by_index
Remove a TopicPartition by index
92 93 94 |
# File 'lib/kafka/ffi/topic_partition_list.rb', line 92 def del_by_idx(idx) ::Kafka::FFI.rd_kafka_topic_partition_list_del_by_idx(self, idx) == 1 end |
#destroy ⇒ Object
Free all resources used by the list and the list itself. Usage it dependent on the semantics of librdkafka, so make sure to only call on TopicPartitionLists that are not owned by objects. Generally, if you constructed the object it should be safe to destroy.
161 162 163 164 165 |
# File 'lib/kafka/ffi/topic_partition_list.rb', line 161 def destroy if !null? ::Kafka::FFI.rd_kafka_topic_partition_list_destroy(self) end end |
#elements ⇒ Array<TopicPartition>
Retrieves the set of TopicPartitions for the list.
151 152 153 154 155 |
# File 'lib/kafka/ffi/topic_partition_list.rb', line 151 def elements self[:cnt].times.map do |i| TopicPartition.new(self[:elems] + (i * TopicPartition.size)) end end |
#empty? ⇒ Boolean
Returns true when the TopicPartitionList is empty
40 41 42 |
# File 'lib/kafka/ffi/topic_partition_list.rb', line 40 def empty? size == 0 end |
#find(topic, partition) ⇒ TopicPartition?
Find the TopicPartition in the set for the given topic + partition. Will return nil if the list does not include the combination.
138 139 140 141 142 143 144 145 146 |
# File 'lib/kafka/ffi/topic_partition_list.rb', line 138 def find(topic, partition) result = ::Kafka::FFI.rd_kafka_topic_partition_list_find(self, topic, partition) if result.null? return nil end result end |
#set_offset(topic, partition, offset) ⇒ Integer
Set the consumed offset for topic and partition
114 115 116 |
# File 'lib/kafka/ffi/topic_partition_list.rb', line 114 def set_offset(topic, partition, offset) ::Kafka::FFI.rd_kafka_topic_partition_list_set_offset(self, topic, partition, offset) end |
#size ⇒ Integer
Returns the number of elements in the TopicPartitionList.
33 34 35 |
# File 'lib/kafka/ffi/topic_partition_list.rb', line 33 def size self[:cnt] end |
#sort(&block) ⇒ Object
Sort the TopicPartitionList. Sort can take a block that should implement a standard comparison function that returns -1, 0, or 1 depending on if left is less than, equal to, or greater than the right argument.
126 127 128 |
# File 'lib/kafka/ffi/topic_partition_list.rb', line 126 def sort(&block) ::Kafka::FFI.rd_kafka_topic_partition_list_sort(self, block, nil) end |