jsancio commented on a change in pull request #11109: URL: https://github.com/apache/kafka/pull/11109#discussion_r675915832
########## File path: raft/src/main/java/org/apache/kafka/raft/KafkaRaftClient.java ########## @@ -2381,25 +2396,51 @@ public void complete() { } } - private final class ListenerContext implements CloseListener<BatchReader<T>> { + private static enum RegistrationOps { + REGISTER, UNREGISTER + } + + private final class Registration { + private final RegistrationOps ops; + private final Listener<T> listener; + + private Registration(RegistrationOps ops, Listener<T> listener) { + this.ops = ops; + this.listener = listener; + } + + private void update(Map<Listener<T>, KafkaListenerContext> contexts) { + if (ops == RegistrationOps.REGISTER) { + if (contexts.putIfAbsent(listener, new KafkaListenerContext(listener)) != null) { + logger.error("Attempting to add a listener that already exists: {}", listenerName(listener)); + } + } else { + if (contexts.remove(listener) == null) { + logger.error("Attempting to remove a listener context that doesn't exists: {}", listenerName(listener)); + } + } + } + } + + private final class KafkaListenerContext implements CloseListener<BatchReader<T>> { Review comment: Done. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: jira-unsubscr...@kafka.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org