philipnee commented on code in PR #14406:
URL: https://github.com/apache/kafka/pull/14406#discussion_r1349221937


##########
clients/src/main/java/org/apache/kafka/clients/consumer/internals/ConsumerNetworkThread.java:
##########
@@ -0,0 +1,252 @@
+/*
+ * 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.internals;
+
+import org.apache.kafka.clients.KafkaClient;
+import org.apache.kafka.clients.consumer.internals.events.ApplicationEvent;
+import 
org.apache.kafka.clients.consumer.internals.events.ApplicationEventProcessor;
+import org.apache.kafka.clients.consumer.internals.events.BackgroundEvent;
+import org.apache.kafka.common.KafkaException;
+import org.apache.kafka.common.errors.InterruptException;
+import org.apache.kafka.common.errors.WakeupException;
+import org.apache.kafka.common.internals.IdempotentCloser;
+import org.apache.kafka.common.requests.AbstractRequest;
+import org.apache.kafka.common.utils.KafkaThread;
+import org.apache.kafka.common.utils.LogContext;
+import org.apache.kafka.common.utils.Time;
+import org.apache.kafka.common.utils.Timer;
+import org.slf4j.Logger;
+
+import java.io.Closeable;
+import java.time.Duration;
+import java.util.Collection;
+import java.util.List;
+import java.util.Optional;
+import java.util.concurrent.Future;
+import java.util.function.Supplier;
+import java.util.stream.Collectors;
+
+import static org.apache.kafka.common.utils.Utils.closeQuietly;
+
+/**
+ * Background thread runnable that consumes {@link ApplicationEvent} and 
produces {@link BackgroundEvent}. It
+ * uses an event loop to consume and produce events, and poll the network 
client to handle network IO.
+ */
+public class ConsumerNetworkThread extends KafkaThread implements Closeable {
+
+    private static final long MAX_POLL_TIMEOUT_MS = 5000;
+    private static final String BACKGROUND_THREAD_NAME = 
"consumer_background_thread";
+    private final Time time;
+    private final Logger log;
+    private final Supplier<ApplicationEventProcessor> 
applicationEventProcessorSupplier;
+    private final Supplier<NetworkClientDelegate> 
networkClientDelegateSupplier;
+    private final Supplier<RequestManagers> requestManagersSupplier;
+    private ApplicationEventProcessor applicationEventProcessor;
+    private NetworkClientDelegate networkClientDelegate;
+    private RequestManagers requestManagers;
+    private volatile boolean running;
+    private final IdempotentCloser closer = new IdempotentCloser();
+
+    public ConsumerNetworkThread(LogContext logContext,
+                                 Time time,
+                                 Supplier<ApplicationEventProcessor> 
applicationEventProcessorSupplier,
+                                 Supplier<NetworkClientDelegate> 
networkClientDelegateSupplier,
+                                 Supplier<RequestManagers> 
requestManagersSupplier) {
+        super(BACKGROUND_THREAD_NAME, true);
+        this.time = time;
+        this.log = logContext.logger(getClass());
+        this.applicationEventProcessorSupplier = 
applicationEventProcessorSupplier;
+        this.networkClientDelegateSupplier = networkClientDelegateSupplier;
+        this.requestManagersSupplier = requestManagersSupplier;
+    }
+
+    @Override
+    public void run() {
+        closer.assertOpen("Consumer network thread is already closed");
+        running = true;
+
+        try {
+            log.debug("Consumer network thread started");
+
+            // Wait until we're securely in the background network thread to 
initialize these objects...

Review Comment:
   hi jun - I think we mostly use "background thread" in lieu of network 
thread, so maybe just use background thread?



-- 
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

Reply via email to