Source:
public void poll(long timeoutMs, List<NetworkSend> sends) throws IOException { clear(); if (sends != null) { for (NetworkSend networkSend : sends) { send(networkSend); } } long startSelect = time.milliseconds(); int readyKeys = select(timeoutMs); long endSelect = time.milliseconds(); this.metrics.selectorSelectTime.update(endSelect - startSelect); this.metrics.selectorSelectRate.inc(); if (readyKeys > 0) { Set<SelectionKey> keys = nioSelector.selectedKeys(); Iterator<SelectionKey> iter = keys.iterator(); while (iter.hasNext()) { SelectionKey key = iter.next(); iter.remove(); Transmissions transmissions = transmissions(key); metrics.initializeSelectorNodeMetricIfRequired(transmissions.remoteHostName, transmissions.remotePort); try { if (key.isConnectable()) { handleConnect(key, transmissions); } else if (key.isReadable()) { read(key, transmissions); } else if (key.isWritable()) { write(key, transmissions); } else if (!key.isValid()) { close(key); } else { throw new IllegalStateException("Unrecognized key state for processor thread."); } } catch (IOException e) { String socketDescription = socketDescription(channel(key)); if (e instanceof EOFException || e instanceof ConnectException) { logger.error("Connection disconnected", socketDescription, e); } else { logger.warn("Error in I/O with connection to {}", socketDescription, e); } close(key); } catch (Exception e) { logger.error("closing key on exception remote host {}", channel(key).socket().getRemoteSocketAddress(), e); close(key); } } this.metrics.selectorIORate.inc(); } long endIo = time.milliseconds(); this.metrics.selectorIOTime.update(endIo); }

Target:
public void poll(long timeoutMs, List<NetworkSend> sends) throws IOException { clear(); if (sends != null) { for (NetworkSend networkSend : sends) { send(networkSend); } } long startSelect = time.milliseconds(); int readyKeys = select(timeoutMs); long endSelect = time.milliseconds(); this.metrics.selectorSelectTime.update(endSelect - startSelect); this.metrics.selectorSelectRate.inc(); if (readyKeys > 0) { Set<SelectionKey> keys = nioSelector.selectedKeys(); Iterator<SelectionKey> iter = keys.iterator(); while (iter.hasNext()) { SelectionKey key = iter.next(); iter.remove(); Transmissions transmissions = transmissions(key); metrics.initializeSelectorNodeMetricIfRequired(transmissions.remoteHostName, transmissions.remotePort); try { if (key.isConnectable()) { handleConnect(key, transmissions); } else if (key.isReadable()) { read(key, transmissions); } else if (key.isWritable()) { write(key, transmissions); } else if (!key.isValid()) { close(key); } else { throw new IllegalStateException("Unrecognized key state for processor thread."); } } catch (IOException e) { String socketDescription = socketDescription(channel(key)); if (e instanceof EOFException || e instanceof ConnectException) { logger.error("Connection disconnected", socketDescription, e); } else { logger.warn("Error in I/O with connection to {}", socketDescription, e); } close(key); } catch (Exception e) { logger.error("closing key on exception remote host {}", channel(key).socket().getRemoteSocketAddress(), e); close(key); } } this.metrics.selectorIORate.inc(); } long endIo = time.milliseconds(); this.metrics.selectorIOTime.update(endIo - endSelect); }