Skip to content
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -333,30 +332,22 @@ protected Collection<NewTopic> newTopics() {
Map<String, NewTopic> topicsForRetry = newTopicsMap.entrySet().stream()
.filter(entry -> entry.getValue() instanceof TopicForRetryable)
.collect(Collectors.toMap(Entry::getKey, Entry::getValue));
Map<String, String> topicNameToMapKey = new HashMap<>();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I still don't believe in this extra map.
More over its name does not reflect reality.
That this.applicationContext.getBeansOfType() returns for us a map of bean names to beans.
Doesn't look like we deal with bean names over here in this method at all.
So, we could simplify the logic just to deal with a List<NewTopic> in this method.
Then those topicsForRetry could be just topic names, since according to its logic we deliberately aware that those names are only for TopicForRetryable.
And so on from here, down to a single removeIf() in the end.

for (Entry<String, NewTopic> entry : newTopicsMap.entrySet()) {
topicNameToMapKey.put(entry.getValue().name(), entry.getKey());
}

for (Entry<String, NewTopic> entry : topicsForRetry.entrySet()) {
Iterator<Entry<String, NewTopic>> iterator = newTopicsMap.entrySet().iterator();
boolean remove = false;
while (iterator.hasNext()) {
Entry<String, NewTopic> nt = iterator.next();
// if we have a NewTopic and TopicForRetry with the same name, remove the latter
if (nt.getValue().name().equals(entry.getValue().name())
&& !(nt.getValue() instanceof TopicForRetryable)) {

remove = true;
break;
String retryTopicName = entry.getValue().name();
String keyInNewTopicsMap = topicNameToMapKey.get(retryTopicName);
if (keyInNewTopicsMap != null) {
NewTopic existing = newTopicsMap.get(keyInNewTopicsMap);
if (!(existing instanceof TopicForRetryable)) {
newTopicsMap.remove(keyInNewTopicsMap);
}
}
if (remove) {
newTopicsMap.remove(entry.getKey());
}
}
Iterator<Entry<String, NewTopic>> iterator = newTopicsMap.entrySet().iterator();
while (iterator.hasNext()) {
Entry<String, NewTopic> next = iterator.next();
if (!this.createOrModifyTopic.test(next.getValue())) {
iterator.remove();
}
}
newTopicsMap.entrySet().removeIf(entry -> !this.createOrModifyTopic.test(entry.getValue()));
return new ArrayList<>(newTopicsMap.values());
}

Expand Down
Loading