int selectNow() throws IOException { try { return selector.selectNow(); } finally { // restore wakeup state if needed if (wakenUp.get()) { selector.wakeup(); } } }
protected final boolean cleanUpCancelledKeys() throws IOException { if (cancelledKeys >= CLEANUP_INTERVAL) { cancelledKeys = 0; selector.selectNow(); return true; } return false; }
int selectNow() throws IOException { try { return selector.selectNow(); } finally { // restore wakeup state if needed if (wakenUp.get()) { selector.wakeup(); } } }
/** * Check for data, waiting up to the given timeout. * * @param timeoutMs Length of time to wait, in milliseconds, which must be non-negative * @return The number of keys ready */ private int select(long timeoutMs) throws IOException { if (timeoutMs < 0L) throw new IllegalArgumentException("timeout should be >= 0"); if (timeoutMs == 0L) return this.nioSelector.selectNow(); else return this.nioSelector.select(timeoutMs); }
public void run() { try { selector.selectNow(); } catch (IOException ignored) { } done = true; unpark(thread); } }
private void selectAgain() { needsToSelectAgain = false; try { selector.selectNow(); } catch (Throwable t) { logger.warn("Failed to update SelectionKeys.", t); } } }
@Override public int selectNow() throws IOException { selectionKeys.reset(); return delegate.selectNow(); }
int selectNow() throws IOException { try { return selector.selectNow(); } finally { // restore wakeup state if needed if (wakenUp.get()) { selector.wakeup(); } } }
@Override public int selectNow() throws IOException { selectionKeys.reset(); return delegate.selectNow(); }
private void selectAgain() { needsToSelectAgain = false; try { selector.selectNow(); } catch (Throwable t) { logger.warn("Failed to update SelectionKeys.", t); } } }
private void selectAgain() { needsToSelectAgain = false; try { selector.selectNow(); } catch (Throwable t) { logger.warn("Failed to update SelectionKeys.", t); } } }
private Selector selectRebuildSelector(int selectCnt) throws IOException { // The selector returned prematurely many times in a row. // Rebuild the selector to work around the problem. logger.warn( "Selector.select() returned prematurely {} times in a row; rebuilding Selector {}.", selectCnt, selector); rebuildSelector(); Selector selector = this.selector; // Select again to populate selectedKeys. selector.selectNow(); return selector; }
@Override public int selectNow() throws IOException { selectionKeys.reset(); return delegate.selectNow(); }
public void close () { super.close(); synchronized (updateLock) { // Blocks to avoid a select while the selector is used to bind the server connection. } // Select one last time to complete closing the socket. if (!isClosed) { isClosed = true; selector.wakeup(); try { selector.selectNow(); } catch (IOException ignored) { } } }
private Selector selectRebuildSelector(int selectCnt) throws IOException { // The selector returned prematurely many times in a row. // Rebuild the selector to work around the problem. logger.warn( "Selector.select() returned prematurely {} times in a row; rebuilding Selector {}.", selectCnt, selector); rebuildSelector(); Selector selector = this.selector; // Select again to populate selectedKeys. selector.selectNow(); return selector; }
@Override public void run() { while (true) { try { processTask(); int readyCount = selector.selectNow(); if (readyCount <= 0) { continue; } Iterator<SelectionKey> iter = selector.selectedKeys().iterator(); while (iter.hasNext()) { SelectionKey key = iter.next(); iter.remove(); NIO_EXECUTOR.execute(new PostProcessor(key)); } } catch (Throwable e) { SRV_LOG.error("[HEALTH-CHECK] error while processing NIO task", e); } } }
while (selector.selectNow() == 0)
/** * Explicit call to selectNow but without processing of selected keys. */ public void selectNowWithoutProcessing() { try { selector.selectNow(); selectedKeySet.reset(); } catch (final IOException ex) { LangUtil.rethrowUnchecked(ex); } } }
public int pollTransports() { int bytesReceived = 0; try { if (channelAndTransports.length <= ITERATION_THRESHOLD) { for (final ChannelAndTransport channelAndTransport : channelAndTransports) { bytesReceived += poll(channelAndTransport); } } else { selector.selectNow(); final SelectionKey[] keys = selectedKeySet.keys(); for (int i = 0, length = selectedKeySet.size(); i < length; i++) { bytesReceived += poll((ChannelAndTransport)keys[i].attachment()); } selectedKeySet.reset(); } } catch (final IOException ex) { LangUtil.rethrowUnchecked(ex); } return bytesReceived; }