Source:
private List<NetworkSend> prepareSends(List<ResponseInfo> responseInfoList) { long prepareSendStartTimeInMs = System.currentTimeMillis(); List<NetworkSend> sends = new ArrayList<NetworkSend>(); ListIterator<RequestMetadata> iter = pendingRequests.listIterator(); while (iter.hasNext()) { RequestMetadata requestMetadata = iter.next(); if (time.milliseconds() - requestMetadata.requestQueuedTimeMs > checkoutTimeoutMs) { responseInfoList.add( new ResponseInfo(requestMetadata.requestInfo.getRequest(), NetworkClientErrorCode.ConnectionUnavailable, null)); iter.remove(); networkMetrics.updateConnectionTimedOutMetrics(requestMetadata.connectionCheckOutAttempts); numPendingConnections.set(pendingRequests.size()); } else { iter.previous(); break; } } while (iter.hasNext()) { RequestMetadata requestMetadata = iter.next(); try { String host = requestMetadata.requestInfo.getHost(); Port port = requestMetadata.requestInfo.getPort(); String connId = connectionTracker.checkOutConnection(host, port); if (connId == null) { if (connectionTracker.mayCreateNewConnection(host, port)) { connId = selector.connect(new InetSocketAddress(host, port.getPort()), networkConfig.socketSendBufferBytes, networkConfig.socketReceiveBufferBytes, port.getPortType()); connectionTracker.startTrackingInitiatedConnection(host, port, connId); requestMetadata.connectionCheckOutAttempts++; } } else { sends.add(new NetworkSend(connId, requestMetadata.requestInfo.getRequest(), requestMetadata.clientNetworkRequestMetrics, time)); connectionIdToRequestInFlight.put(connId, requestMetadata); iter.remove(); numPendingConnections.set(pendingRequests.size()); requestMetadata.onRequestDequeue(); } } catch (IOException e) { networkMetrics.networkClientIOError.inc(); logger.error("Received exception while checking out a connection", e); } } networkMetrics.prepareSendTime.update(System.currentTimeMillis() - prepareSendStartTimeInMs); return sends; }

Target:
private List<NetworkSend> prepareSends(List<ResponseInfo> responseInfoList) { List<NetworkSend> sends = new ArrayList<NetworkSend>(); ListIterator<RequestMetadata> iter = pendingRequests.listIterator(); while (iter.hasNext()) { RequestMetadata requestMetadata = iter.next(); if (time.milliseconds() - requestMetadata.requestQueuedAtMs > checkoutTimeoutMs) { responseInfoList.add( new ResponseInfo(requestMetadata.requestInfo.getRequest(), NetworkClientErrorCode.ConnectionUnavailable, null)); iter.remove(); networkMetrics.connectionTimeOutError.inc(); } else { iter.previous(); break; } } while (iter.hasNext()) { RequestMetadata requestMetadata = iter.next(); try { String host = requestMetadata.requestInfo.getHost(); Port port = requestMetadata.requestInfo.getPort(); String connId = connectionTracker.checkOutConnection(host, port); if (connId == null) { if (connectionTracker.mayCreateNewConnection(host, port)) { connId = selector.connect(new InetSocketAddress(host, port.getPort()), networkConfig.socketSendBufferBytes, networkConfig.socketReceiveBufferBytes, port.getPortType()); connectionTracker.startTrackingInitiatedConnection(host, port, connId); } } else { sends.add(new NetworkSend(connId, requestMetadata.requestInfo.getRequest(), requestMetadata.clientNetworkRequestMetrics, time)); connectionIdToRequestInFlight.put(connId, requestMetadata); iter.remove(); requestMetadata.onRequestDequeue(); } } catch (IOException e) { networkMetrics.networkClientIOError.inc(); logger.error("Received exception while checking out a connection", e); } } return sends; }