d8tltanc commented on a change in pull request #8683:
URL: https://github.com/apache/kafka/pull/8683#discussion_r443785134



##########
File path: 
clients/src/main/java/org/apache/kafka/clients/ClusterConnectionStates.java
##########
@@ -357,6 +398,36 @@ private NodeConnectionState nodeState(String id) {
         return state;
     }
 
+    /**
+     * Get the id set of nodes which are in CONNECTING state
+     */
+    public Set<String> connectingNodes() {
+        return this.connectingNodes;
+    }
+
+    /**
+     * Get the timestamp of the latest connection attempt of a given node
+     * @param id the connection to fetch the state for
+     */
+    public long lastConnectAttemptMs(String id) {
+        NodeConnectionState nodeState = this.nodeState.get(id);
+        return nodeState == null ? 0 : nodeState.lastConnectAttemptMs;
+    }
+
+    public long connectionSetupTimeoutMs(String id) {
+        NodeConnectionState nodeState = this.nodeState.get(id);
+        return nodeState.connectionSetupTimeoutMs;

Review comment:
       When `NetworkClient` initializes a connection to a given node 
(`NetworkClient::initiateConnect`), it's guaranteed that the `nodeState` will 
get initialized and won't be `null`. I think it's probably not reasonable if 
the caller wants to get the connection timeout of a given node before the 
connection initialization, which is the reason I prevent this kind of calling 
by throwing the exception.
   
   However, it might be reasonable for a caller to get the 
`lastConnectAttemptMs` before initializing the connection. For example, the 
node provider wants to provide a node with the least recent connection attempt. 
For those nodes haven't been connected yet, their `NodeConnectionState` does 
not exist. However, this implies that the node has the highest priority and we 
may assume their `lastConnectAttemptMs` is 0.




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

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


Reply via email to