/** * Cleans up the contents of the selector, closing any server socket channels that might be * associated with it. Any connections that might have been established through those channels * should not be impacted. */ private void cleanUpSelector() { try { for (SelectionKey key : selector.keys()) { try { key.cancel(); } catch (Exception e) { logger.traceException(e); } try { key.channel().close(); } catch (Exception e) { logger.traceException(e); } } } catch (Exception e) { logger.traceException(e); } }
static void releaseTemporarySelector(Selector sel) throws IOException { // Selector should be empty sel.selectNow(); // Flush cancelled keys assert sel.keys().isEmpty() : "Temporary selector not empty"; localSelectorWrapper.set(null); }