dajac commented on code in PR #17897: URL: https://github.com/apache/kafka/pull/17897#discussion_r1853693229
########## clients/src/main/java/org/apache/kafka/clients/consumer/SubscriptionPattern.java: ########## @@ -0,0 +1,41 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.kafka.clients.consumer; + +/** + * Represents a regular expression compatible with Google RE2/J, used to subscribe to topics . + * This just keeps the String representation of the pattern, and all validations to ensure + * it is RE2/J compatible are delegated to the broker. + */ +public class SubscriptionPattern { + + /** + * String representation the regular expression, compatible with RE2/J. + */ + private final String pattern; + + public SubscriptionPattern(String pattern) { + this.pattern = pattern; + } + + /** + * @return Regular expression pattern compatible with RE2/J. + */ + public String pattern() { + return this.pattern; + } Review Comment: nit: Should we implement toString (and perhaps equals, hashcode)? ########## clients/src/main/java/org/apache/kafka/clients/consumer/SubscriptionPattern.java: ########## @@ -0,0 +1,41 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.kafka.clients.consumer; + +/** + * Represents a regular expression compatible with Google RE2/J, used to subscribe to topics . Review Comment: nit: There is an extra space before the `.`. ########## clients/src/main/java/org/apache/kafka/clients/consumer/internals/AsyncKafkaConsumer.java: ########## @@ -1855,6 +1866,29 @@ private void subscribeInternal(Pattern pattern, Optional<ConsumerRebalanceListen } } + /** + * Subscribe to the RE2/J pattern. This will generate an event to update the pattern in the + * subscription, so it's included in a next heartbeat request sent to the broker. No validation of the pattern is + * performed by the client. + */ + private void subscribeToRegex(SubscriptionPattern pattern, + Optional<ConsumerRebalanceListener> listener) { + maybeThrowInvalidGroupIdException(); + throwIfNullOrEmpty(pattern); + log.info("Subscribing to regular expression {}", pattern); Review Comment: We need toString for this one :) ########## clients/src/main/java/org/apache/kafka/clients/consumer/internals/AsyncKafkaConsumer.java: ########## @@ -1855,6 +1866,29 @@ private void subscribeInternal(Pattern pattern, Optional<ConsumerRebalanceListen } } + /** + * Subscribe to the RE2/J pattern. This will generate an event to update the pattern in the + * subscription, so it's included in a next heartbeat request sent to the broker. No validation of the pattern is + * performed by the client. + */ + private void subscribeToRegex(SubscriptionPattern pattern, + Optional<ConsumerRebalanceListener> listener) { + maybeThrowInvalidGroupIdException(); + throwIfNullOrEmpty(pattern); + log.info("Subscribing to regular expression {}", pattern); + + // TODO: generate event to update subscribed regex so it's included in the next HB. + } + + private void throwIfNullOrEmpty(SubscriptionPattern subscriptionPattern) { Review Comment: nit: `throwIfSubscriptionPatternIsInvalid` to make it more specific? -- 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]
