NetworkClient is a KafkaClient.
Node leastLoadedNode( long now)
leastLoadedNode generates a random number to offset the first node to start checking node candidates from.
leastLoadedNode finds three nodes:
foundReadythat is ready (perhaps with some in-flight requests)
foundConnectingwith a connection already being established (using the
foundCanConnectthat can be connected
When a node is found that is ready and has no in-flight requests,
leastLoadedNode prints out the following TRACE message to the logs and returns the node immediately:
Found least loaded node [node] connected with no in-flight requests
When a node candidate does not meet any of the above requirements,
leastLoadedNode prints out the following TRACE message to the logs:
Removing node [node] from least loaded node selection since it is neither ready for sending nor connecting
leastLoadedNode prefers the
foundReady node over the
foundConnecting with the
foundCanConnect as the last resort.
When no node could be found,
leastLoadedNode prints out the following TRACE message to the logs (and returns
Least loaded node selection failed to find an available node
leastLoadedNode is part of the KafkaClient abstraction.