Skip to content

Commit a4532ed

Browse files
author
Alexander Damian
committed
Use erase directly
Added revoke() member function
1 parent 68ae525 commit a4532ed

File tree

2 files changed

+17
-16
lines changed

2 files changed

+17
-16
lines changed

include/cppkafka/utils/poll_strategy_base.h

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -102,10 +102,17 @@ class CPPKAFKA_API PollStrategyBase : public PollInterface {
102102
* belonging to the provided partition list and calls reset_state().
103103
* To be used with static consumers.
104104
*
105-
* \param partitions Revoked topic partitions. If the partition list is empty
106-
* all partitions will be revoked.
105+
* \param partitions Revoked topic partitions.
107106
*/
108-
virtual void revoke(const TopicPartitionList& partitions = {});
107+
virtual void revoke(const TopicPartitionList& partitions);
108+
109+
/**
110+
* \brief Removes all partitions queues associated with the supplied partitions.
111+
*
112+
* This method contains a default implementation. It removes all the queues
113+
* currently assigned and calls reset_state(). To be used with static consumers.
114+
*/
115+
virtual void revoke();
109116

110117
protected:
111118
/**

src/utils/poll_strategy_base.cpp

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -99,23 +99,17 @@ void PollStrategyBase::assign(TopicPartitionList& partitions) {
9999
}
100100

101101
void PollStrategyBase::revoke(const TopicPartitionList& partitions) {
102-
if (partitions.empty()) {
103-
//revoke everything
104-
partition_queues_.clear();
105-
}
106-
else {
107-
for (const auto &partition : partitions) {
108-
// get the queue associated with this partition
109-
auto toppar_it = partition_queues_.find(partition);
110-
if (toppar_it != partition_queues_.end()) {
111-
// remove this queue from the list
112-
partition_queues_.erase(toppar_it);
113-
}
114-
}
102+
for (const auto &partition : partitions) {
103+
partition_queues_.erase(partition);
115104
}
116105
reset_state();
117106
}
118107

108+
void PollStrategyBase::revoke() {
109+
partition_queues_.clear();
110+
reset_state();
111+
}
112+
119113
void PollStrategyBase::on_assignment(TopicPartitionList& partitions) {
120114
assign(partitions);
121115
// call original consumer callback if any

0 commit comments

Comments
 (0)