adikou commented on code in PR #22271:
URL: https://github.com/apache/kafka/pull/22271#discussion_r3520566151
##########
clients/src/main/java/org/apache/kafka/clients/consumer/internals/SubscriptionState.java:
##########
@@ -328,8 +362,30 @@ public synchronized void
assignFromSubscribed(Collection<TopicPartition> assignm
this.assignment.set(assignedPartitionStates);
}
- private void registerRebalanceListener(Optional<ConsumerRebalanceListener>
listener) {
- this.rebalanceListener = Objects.requireNonNull(listener,
"RebalanceListener cannot be null");
+ /**
+ * Visible for tests only. Used when a consumer instance is unavailable
for registration such as in simple
+ * tests or membership management.
+ * @param listener the listener; must not be null
+ */
+ public void setRebalanceListener(RebalanceListener listener) {
+ Objects.requireNonNull(listener, "Listener must not be null when
setting a rebalance listener");
+ this.rebalanceListener.set(listener);
+ }
+
+ /**
+ * Sets the current rebalance listener for this subscription.
+ * @param listener the listener
+ * @param consumer the consumer instance to orchestrate callbacks in
{@link RebalanceConsumer}. must not be null
+ */
+ public void setRebalanceListener(RebalanceListener listener, Consumer<?,
?> consumer) {
+ if (listener != null) {
+ Objects.requireNonNull(consumer, "Consumer must not be null when a
listener is provided");
+ this.rebalanceListener.set(listener);
+ this.rebalanceConsumer.set(consumer);
+ } else {
Review Comment:
We need to support explicitly setting the rebalanceListener to `null`
through the existing flow.
https://github.com/apache/kafka/pull/22271/changes#diff-4537fba2845d55d73736763b6f555e04fb21cd56f183320eda45c92a3a52f11dR784
--
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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]