try { final Connection connection = transport.getSelectionKeyHandler().getConnectionForKey(key); } else { final SelectableChannel channel = key.channel(); transport.getSelectionKeyHandler().cancel(key); channel.close();
private boolean iterateKeyEvents() throws IOException { final SelectionKey keyLocal = key; final SelectionKeyHandler selectionKeyHandler = transport.getSelectionKeyHandler(); final IOStrategy ioStrategy = transport.getIOStrategy(); final IOEvent[] ioEvents = selectionKeyHandler.getIOEvents(keyReadyOps); final NIOConnection connection = selectionKeyHandler.getConnectionForKey(keyLocal); for (IOEvent ioEvent : ioEvents) { NIOConnection.notifyIOEventReady(connection, ioEvent); final int interest = ioEvent.getSelectionKeyInterest(); keyReadyOps &= (~interest); if (selectionKeyHandler.onProcessInterest(keyLocal, interest)) { if (!ioStrategy.executeIoEvent(connection, ioEvent)) { return false; } } } return true; }
protected final void switchToNewSelector() throws IOException { final Selector oldSelector = selector; final Selector newSelector = Selectors.newSelector(transport.getSelectorProvider()); final Set<SelectionKey> keys = oldSelector.keys(); final SelectionKeyHandler selectionKeyHandler = transport.getSelectionKeyHandler(); for (final SelectionKey selectionKey : keys) { if (selectionKey.isValid()) { try { final NIOConnection nioConnection = selectionKeyHandler.getConnectionForKey(selectionKey); final SelectionKey newSelectionKey = selectionKey.channel().register(newSelector, selectionKey.interestOps(), selectionKey.attachment()); nioConnection.onSelectionKeyUpdated(newSelectionKey); } catch (Exception e) { LOGGER.log(Level.FINE, "Error switching channel to a new selector", e); } } } setSelector(newSelector); try { oldSelector.close(); } catch (Exception ignored) { } }
selectorRunner.getTransport().getSelectionKeyHandler().cancel(key); onKeyDeregistered(key);
onKeyRegistered(registeredSelectionKey);
protected final void switchToNewSelector() throws IOException { final Selector oldSelector = selector; final Selector newSelector = Selectors.newSelector(transport.getSelectorProvider()); final Set<SelectionKey> keys = oldSelector.keys(); final SelectionKeyHandler selectionKeyHandler = transport.getSelectionKeyHandler(); for (final SelectionKey selectionKey : keys) { if (selectionKey.isValid()) { try { final NIOConnection nioConnection = selectionKeyHandler.getConnectionForKey(selectionKey); final SelectionKey newSelectionKey = selectionKey.channel().register(newSelector, selectionKey.interestOps(), selectionKey.attachment()); nioConnection.onSelectionKeyUpdated(newSelectionKey); } catch (Exception e) { LOGGER.log(Level.FINE, "Error switching channel to a new selector", e); } } } setSelector(newSelector); try { oldSelector.close(); } catch (Exception ignored) { } }
selectorRunner.getTransport().getSelectionKeyHandler().cancel(key); onKeyDeregistered(key);
onKeyRegistered(registeredSelectionKey);
private boolean iterateKeyEvents() throws IOException { final SelectionKey keyLocal = key; final SelectionKeyHandler selectionKeyHandler = transport.getSelectionKeyHandler(); final IOStrategy ioStrategy = transport.getIOStrategy(); final IOEvent[] ioEvents = selectionKeyHandler.getIOEvents(keyReadyOps); final NIOConnection connection = selectionKeyHandler.getConnectionForKey(keyLocal); for (IOEvent ioEvent : ioEvents) { NIOConnection.notifyIOEventReady(connection, ioEvent); final int interest = ioEvent.getSelectionKeyInterest(); keyReadyOps &= (~interest); if (selectionKeyHandler.onProcessInterest(keyLocal, interest)) { if (!ioStrategy.executeIoEvent(connection, ioEvent)) { return false; } } } return true; }
protected final void switchToNewSelector() throws IOException { final Selector oldSelector = selector; final Selector newSelector = Selectors.newSelector(transport.getSelectorProvider()); final Set<SelectionKey> keys = oldSelector.keys(); final SelectionKeyHandler selectionKeyHandler = transport.getSelectionKeyHandler(); for (final SelectionKey selectionKey : keys) { if (selectionKey.isValid()) { try { final NIOConnection nioConnection = selectionKeyHandler.getConnectionForKey(selectionKey); final SelectionKey newSelectionKey = selectionKey.channel().register(newSelector, selectionKey.interestOps(), selectionKey.attachment()); nioConnection.onSelectionKeyUpdated(newSelectionKey); } catch (Exception e) { LOGGER.log(Level.FINE, "Error switching channel to a new selector", e); } } } setSelector(newSelector); try { oldSelector.close(); } catch (Exception ignored) { } }
selectorRunner.getTransport().getSelectionKeyHandler().cancel(key); onKeyDeregistered(key);
try { final Connection connection = transport.getSelectionKeyHandler().getConnectionForKey(key); } else { final SelectableChannel channel = key.channel(); transport.getSelectionKeyHandler().cancel(key); channel.close();
onKeyRegistered(registeredSelectionKey);
private boolean iterateKeyEvents() throws IOException { final SelectionKey keyLocal = key; final SelectionKeyHandler selectionKeyHandler = transport.getSelectionKeyHandler(); final IOStrategy ioStrategy = transport.getIOStrategy(); final IOEvent[] ioEvents = selectionKeyHandler.getIOEvents(keyReadyOps); final NIOConnection connection = selectionKeyHandler.getConnectionForKey(keyLocal); for (IOEvent ioEvent : ioEvents) { NIOConnection.notifyIOEventReady(connection, ioEvent); final int interest = ioEvent.getSelectionKeyInterest(); keyReadyOps &= (~interest); if (selectionKeyHandler.onProcessInterest(keyLocal, interest)) { if (!ioStrategy.executeIoEvent(connection, ioEvent)) { return false; } } } return true; }
protected final void switchToNewSelector() throws IOException { final Selector oldSelector = selector; final Selector newSelector = Selectors.newSelector(transport.getSelectorProvider()); final Set<SelectionKey> keys = oldSelector.keys(); final SelectionKeyHandler selectionKeyHandler = transport.getSelectionKeyHandler(); for (final SelectionKey selectionKey : keys) { if (selectionKey.isValid()) { try { final NIOConnection nioConnection = selectionKeyHandler.getConnectionForKey(selectionKey); final SelectionKey newSelectionKey = selectionKey.channel().register(newSelector, selectionKey.interestOps(), selectionKey.attachment()); nioConnection.onSelectionKeyUpdated(newSelectionKey); } catch (Exception e) { LOGGER.log(Level.FINE, "Error switching channel to a new selector", e); } } } setSelector(newSelector); try { oldSelector.close(); } catch (Exception ignored) { } }
selectorRunner.getTransport().getSelectionKeyHandler().cancel(key); onKeyDeregistered(key);
try { final Connection connection = transport.getSelectionKeyHandler().getConnectionForKey(key); } else { final SelectableChannel channel = key.channel(); transport.getSelectionKeyHandler().cancel(key); channel.close();
onKeyRegistered(registeredSelectionKey);
private boolean iterateKeyEvents() throws IOException { final SelectionKey keyLocal = key; final SelectionKeyHandler selectionKeyHandler = transport.getSelectionKeyHandler(); final IOStrategy ioStrategy = transport.getIOStrategy(); final IOEvent[] ioEvents = selectionKeyHandler.getIOEvents(keyReadyOps); final NIOConnection connection = selectionKeyHandler.getConnectionForKey(keyLocal); for (IOEvent ioEvent : ioEvents) { NIOConnection.notifyIOEventReady(connection, ioEvent); final int interest = ioEvent.getSelectionKeyInterest(); keyReadyOps &= (~interest); if (selectionKeyHandler.onProcessInterest(keyLocal, interest)) { if (!ioStrategy.executeIoEvent(connection, ioEvent)) { return false; } } } return true; }
@Override public void completed(RegisterChannelResult result) { final TCPNIOTransport transport = (TCPNIOTransport) TCPNIOConnectorHandler.this.transport; transport.selectorRegistrationHandler.completed(result); final SelectionKey selectionKey = result.getSelectionKey(); final SelectionKeyHandler selectionKeyHandler = transport.getSelectionKeyHandler(); final TCPNIOConnection connection = (TCPNIOConnection) selectionKeyHandler.getConnectionForKey(selectionKey); try { connection.onConnect(); } catch (Exception e) { LOGGER.log(Level.FINE, "Exception happened, when " + "trying to connect the channel", e); } } }