dimitarndimitrov commented on code in PR #13856:
URL: https://github.com/apache/kafka/pull/13856#discussion_r1233880362


##########
server-common/src/main/java/org/apache/kafka/server/util/InterBrokerSendThread.java:
##########
@@ -0,0 +1,253 @@
+/*
+ * 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.util;
+
+import java.io.IOException;
+import java.util.ArrayDeque;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Map.Entry;
+import java.util.Set;
+import org.apache.kafka.clients.ClientRequest;
+import org.apache.kafka.clients.ClientResponse;
+import org.apache.kafka.clients.KafkaClient;
+import org.apache.kafka.clients.RequestCompletionHandler;
+import org.apache.kafka.common.Node;
+import org.apache.kafka.common.errors.AuthenticationException;
+import org.apache.kafka.common.errors.DisconnectException;
+import org.apache.kafka.common.internals.FatalExitError;
+import org.apache.kafka.common.utils.Time;
+
+/**
+ * An inter-broker send thread that utilizes a non-blocking network client.
+ */
+public abstract class InterBrokerSendThread extends ShutdownableThread {
+
+    protected volatile KafkaClient networkClient;
+
+    private final int requestTimeoutMs;
+    private final Time time;
+    private final UnsentRequests unsentRequests;
+
+    public InterBrokerSendThread(
+        String name,
+        KafkaClient networkClient,
+        int requestTimeoutMs,
+        Time time
+    ) {
+        this(name, networkClient, requestTimeoutMs, time, true);
+    }
+
+    public InterBrokerSendThread(
+        String name,
+        KafkaClient networkClient,
+        int requestTimeoutMs,
+        Time time,
+        boolean isInterruptible
+    ) {
+        super(name, isInterruptible);
+        this.networkClient = networkClient;
+        this.requestTimeoutMs = requestTimeoutMs;
+        this.time = time;
+        this.unsentRequests = new UnsentRequests();
+    }
+
+    public abstract Collection<RequestAndCompletionHandler> generateRequests();
+
+    public boolean hasUnsentRequests() {
+        return unsentRequests.iterator().hasNext();
+    }
+
+    @Override
+    public void shutdown() throws InterruptedException {
+        initiateShutdown();
+        networkClient.initiateClose();
+        awaitShutdown();
+        try {
+            networkClient.close();
+        } catch (IOException e) {

Review Comment:
   Nice, I didn't know about `closeQuietly` - I'll just integrate it here.
   As for the reasoning - I wasn't sure whether it's OK to suppress the 
exception (as in theory it's not currently guaranteed that it strictly can't be 
thrown) so I decided to be overly conservative.



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