private void onChannelReadable(SelectionKey key) { try { // reads the incoming data in context of reactor main loop. Can this be improved? Object readObject = ((AbstractNioChannel) key.attachment()).read(key); dispatchReadEvent(key, readObject); } catch (IOException e) { try { key.channel().close(); } catch (IOException e1) { LOGGER.error("error closing channel", e1); } } }
/** * Stops the NIO reactor. This is a blocking call. * * @throws InterruptedException if interrupted while stopping the reactor. * @throws IOException if any I/O error occurs */ public void stop() throws InterruptedException, IOException { reactor.stop(); dispatcher.stop(); for (AbstractNioChannel channel : channels) { channel.getJavaChannel().close(); } }
private void closeStream() { if (isClosed.get()) { return; } try { isClosed.set(true); future.get().cancel(false); key.cancel(); key.channel().close(); } catch (final IOException ioe) { LOGGER.warn("Unable to cleanly close stream due to " + ioe); } finally { consumer.signalEndOfStream(); } }
private void handleIOException( SelectionKey key, WebSocket conn, IOException ex ) { // onWebsocketError( conn, ex );// conn may be null here if( conn != null ) { conn.closeConnection( CloseFrame.ABNORMAL_CLOSE, ex.getMessage() ); } else if( key != null ) { SelectableChannel channel = key.channel(); if( channel != null && channel.isOpen() ) { // this could be the case if the IOException ex is a SSLException try { channel.close(); } catch ( IOException e ) { // there is nothing that must be done here } log.trace("Connection closed because of exception",ex); } } }
private void processSelectedKeys() { Set<SelectionKey> selectionKeys = selector.selectedKeys(); for (SelectionKey key : selectionKeys) { if (stop || Thread.currentThread().isInterrupted()) { return; } try { processSelectedKey(key); } catch (Exception e) { logger.warn("error {} in processing key. Close channel {}", e.getMessage(), key.channel()); logger.debug("", e); try { key.channel().close(); } catch (IOException ioe) { LoggerUtils.errorAndDebugDetails(logger, "unable close bad channel", ioe); } } } selectionKeys.clear(); }
logger.trace("Closing SelectionKey's channel"); sk.channel().close();
@Override public void run() { if (key != null && key.isValid()) { SocketChannel channel = (SocketChannel) key.channel(); Beat beat = (Beat) key.attachment(); if (channel.isConnected()) { return; } try { channel.finishConnect(); } catch (Exception ignore) { } try { beat.finishCheck(false, false, beat.getTask().getCheckRTNormalized() * 2, "tcp:timeout"); key.cancel(); key.channel().close(); } catch (Exception ignore) { } } } }
key.cancel(); try { key.channel().close(); } catch (IOException e) { logger.warn("Failure while closing channel", e);
key.cancel(); try { key.channel().close(); } catch (IOException cex) {
try { if (key.isValid()) { key.channel().close();
/** * Create a new instance * * @param parent the parent {@link Channel} by which this instance was created. May be {@code null} * @param ch the underlying {@link SelectableChannel} on which it operates * @param readInterestOp the ops to set to receive data from the {@link SelectableChannel} */ protected AbstractNioChannel(Channel parent, SelectableChannel ch, int readInterestOp) { super(parent); this.ch = ch; this.readInterestOp = readInterestOp; try { ch.configureBlocking(false); } catch (IOException e) { try { ch.close(); } catch (IOException e2) { if (logger.isWarnEnabled()) { logger.warn( "Failed to close a partially initialized socket.", e2); } } throw new ChannelException("Failed to enter non-blocking mode.", e); } }
beatKey.key.channel().close();
/** * @param blockConnect {@code True} to block client reconnect. * @throws Exception If failed. */ public void closeSocket(boolean blockConnect) throws Exception { if (blockConnect) blockConnectLatch = new CountDownLatch(1); log.info("ZkTestClientCnxnSocketNIO closeSocket [node=" + nodeName + ", block=" + blockConnect + ']'); SelectionKey k = GridTestUtils.getFieldValue(this, ClientCnxnSocketNIO.class, "sockKey"); k.channel().close(); } }
/** * Create a new instance * * @param parent the parent {@link Channel} by which this instance was created. May be {@code null} * @param ch the underlying {@link SelectableChannel} on which it operates * @param readInterestOp the ops to set to receive data from the {@link SelectableChannel} */ protected AbstractNioChannel(Channel parent, SelectableChannel ch, int readInterestOp) { super(parent); this.ch = ch; this.readInterestOp = readInterestOp; try { ch.configureBlocking(false); } catch (IOException e) { try { ch.close(); } catch (IOException e2) { if (logger.isWarnEnabled()) { logger.warn( "Failed to close a partially initialized socket.", e2); } } throw new ChannelException("Failed to enter non-blocking mode.", e); } }
/** * Create a new instance * * @param parent the parent {@link Channel} by which this instance was created. May be {@code null} * @param ch the underlying {@link SelectableChannel} on which it operates * @param readInterestOp the ops to set to receive data from the {@link SelectableChannel} */ protected AbstractNioChannel(Channel parent, SelectableChannel ch, int readInterestOp) { super(parent); this.ch = ch; this.readInterestOp = readInterestOp; try { ch.configureBlocking(false); } catch (IOException e) { try { ch.close(); } catch (IOException e2) { if (logger.isWarnEnabled()) { logger.warn( "Failed to close a partially initialized socket.", e2); } } throw new ChannelException("Failed to enter non-blocking mode.", e); } }
public Futures.CloseFuture close() { try { javaChannel().close(); closeFuture.setSuccess(true); } catch (final IOException e) { if (LOGGER.isDebugEnabled()) { LOGGER.debug("caught connection exception", e); } closeFuture.setSuccess(false); closeFuture.setCause(e); eventHandler().exceptionCaught(this, e); } closeFuture.notifyListeners(); return closeFuture; }
public Futures.CloseFuture close() { try { javaChannel().close(); closeFuture.setSuccess(true); } catch (final IOException e) { if (LOGGER.isDebugEnabled()) { LOGGER.debug("caught connection exception", e); } closeFuture.setSuccess(false); closeFuture.setCause(e); eventHandler().exceptionCaught(this, e); } closeFuture.notifyListeners(); return closeFuture; }
channel.channel.close(); increaseCancelledKeys();