satishd commented on a change in pull request #10579: URL: https://github.com/apache/kafka/pull/10579#discussion_r663808257
########## File path: storage/src/main/java/org/apache/kafka/server/log/remote/metadata/storage/ConsumerManager.java ########## @@ -0,0 +1,130 @@ +/* + * 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.server.log.remote.metadata.storage; + +import org.apache.kafka.clients.consumer.KafkaConsumer; +import org.apache.kafka.clients.producer.RecordMetadata; +import org.apache.kafka.common.KafkaException; +import org.apache.kafka.common.TopicIdPartition; +import org.apache.kafka.common.utils.KafkaThread; +import org.apache.kafka.common.utils.Time; +import org.apache.kafka.common.utils.Utils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.io.Closeable; +import java.io.IOException; +import java.util.Optional; +import java.util.Set; + +/** + * This class manages the consumer thread viz {@link ConsumerTask} that polls messages from the assigned metadata topic partitions. + * It also provides a way to wait until the given record is received by the consumer before it is timed out with an interval of + * {@link TopicBasedRemoteLogMetadataManagerConfig#consumeWaitMs()}. + */ +public class ConsumerManager implements Closeable { + + private static final Logger log = LoggerFactory.getLogger(ConsumerManager.class); + private static final long CONSUME_RECHECK_INTERVAL_MS = 50L; + + private final TopicBasedRemoteLogMetadataManagerConfig rlmmConfig; + private final Time time; + private final ConsumerTask consumerTask; + private final Thread consumerTaskThread; + + public ConsumerManager(TopicBasedRemoteLogMetadataManagerConfig rlmmConfig, + RemotePartitionMetadataEventHandler remotePartitionMetadataEventHandler, + RemoteLogMetadataTopicPartitioner rlmmTopicPartitioner, + Time time) { + this.rlmmConfig = rlmmConfig; + this.time = time; + + //Create a task to consume messages and submit the respective events to RemotePartitionMetadataEventHandler. + KafkaConsumer<byte[], byte[]> consumer = new KafkaConsumer<>(rlmmConfig.consumerProperties()); + consumerTask = new ConsumerTask(consumer, remotePartitionMetadataEventHandler, rlmmTopicPartitioner); + consumerTaskThread = KafkaThread.daemon("RLMMConsumerTask", consumerTask); Review comment: Good catch, updated it. -- 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