private void closeMaster() { if (null != this.socketChannel) { try { SelectionKey sk = this.socketChannel.keyFor(this.selector); if (sk != null) { sk.cancel(); } this.socketChannel.close(); this.socketChannel = null; } catch (IOException e) { log.warn("closeMaster exception. ", e); } this.lastWriteTimestamp = 0; this.dispatchPostion = 0; this.byteBufferBackup.position(0); this.byteBufferBackup.limit(READ_MAX_BUFFER_SIZE); this.byteBufferRead.position(0); this.byteBufferRead.limit(READ_MAX_BUFFER_SIZE); } }
private void connect() throws IOException { if (this.proxy.isOpen()) { if (this.proxy.finishConnect()) { this.proxy.register(this.selector, SelectionKey.OP_WRITE, this); SelectionKey clientKey = this.client.keyFor(this.selector); if (clientKey != null) { clientKey.cancel(); } this.state = HandlerState.WRITING; } else if (this.connectStartTime + Config.PROXY_CONNECT_TIMEOUT_MS < System.currentTimeMillis()) { LOG.warn("Proxy connect timed out for client {}", this.client); closeChannels(); } } }
/** * Take the list of the connections that want to write, and register them in the selector. */ private void registerWrites() { Iterator<SimpleServerRpcConnection> it = writingCons.iterator(); while (it.hasNext()) { SimpleServerRpcConnection c = it.next(); it.remove(); SelectionKey sk = c.channel.keyFor(writeSelector); try { if (sk == null) { try { c.channel.register(writeSelector, SelectionKey.OP_WRITE, c); } catch (ClosedChannelException e) { // ignore: the client went away. if (SimpleRpcServer.LOG.isTraceEnabled()) SimpleRpcServer.LOG.trace("ignored", e); } } else { sk.interestOps(SelectionKey.OP_WRITE); } } catch (CancelledKeyException e) { // ignore: the client went away. if (SimpleRpcServer.LOG.isTraceEnabled()) SimpleRpcServer.LOG.trace("ignored", e); } } }
protected void closeInternal() { if(logger.isDebugEnabled()) logger.debug("Closing remote connection from " + socketChannel.socket()); try { socketChannel.socket().close(); } catch(IOException e) { if(logger.isEnabledFor(Level.WARN)) logger.warn(e.getMessage(), e); } try { socketChannel.close(); } catch(IOException e) { if(logger.isEnabledFor(Level.WARN)) logger.warn(e.getMessage(), e); } SelectionKey selectionKey = socketChannel.keyFor(selector); if(selectionKey != null) { try { selectionKey.attach(null); selectionKey.cancel(); } catch(Exception e) { if(logger.isEnabledFor(Level.WARN)) logger.warn(e.getMessage(), e); } } // close the streams, so we account for comm buffer frees IOUtils.closeQuietly(inputStream); IOUtils.closeQuietly(outputStream); }
public Futures.WriteFuture writeAndFlush(NioChannel channel, Object msg) { SelectionKey key = channel.socketChannel().keyFor(selectorLoop.selector()); if(key != null && key.isValid()){ key.interestOps(SelectionKey.OP_WRITE); } return write(channel, msg, true); }
public Futures.WriteFuture writeAndFlush(NioChannel channel, Object msg) { SelectionKey key = channel.socketChannel().keyFor(selectorLoop.selector()); if(key != null && key.isValid()){ key.interestOps(SelectionKey.OP_WRITE); } return write(channel, msg, true); }
SelectionKey selectionKey = socketChannel.keyFor(selector);
continue; SelectionKey key = socketChannel.keyFor(selector); if (key == null) { logger.warn("unable to find key for channel {}", socketChannel);
public void run() { try { SelectionKey selectionKey = socketChannel.keyFor(selector);
SelectionKey sk = this.socketChannel.keyFor(this.selector); if (sk != null) { sk.cancel();
SelectionKey sk = this.socketChannel.keyFor(this.selector); if (sk != null) { sk.cancel();
SelectionKey key = channel.socketChannel().keyFor(selectorLoop.selector()); if(key != null && key.isValid()){ key.interestOps(SelectionKey.OP_READ);
SelectionKey key = channel.socketChannel().keyFor(selectorLoop.selector()); if(key != null && key.isValid()){ key.interestOps(SelectionKey.OP_READ);
private void closeMaster() { if (null != this.socketChannel) { try { SelectionKey sk = this.socketChannel.keyFor(this.selector); if (sk != null) { sk.cancel(); } this.socketChannel.close(); this.socketChannel = null; } catch (IOException e) { log.warn("closeMaster exception. ", e); } this.lastWriteTimestamp = 0; this.dispatchPostion = 0; this.byteBufferBackup.position(0); this.byteBufferBackup.limit(READ_MAX_BUFFER_SIZE); this.byteBufferRead.position(0); this.byteBufferRead.limit(READ_MAX_BUFFER_SIZE); } }
SelectionKey sk = this.socketChannel.keyFor(this.selector); if (sk != null) { sk.cancel();
if (sc == null) continue; SelectionKey sk = sc.keyFor(selector);
if (sc == null) continue; SelectionKey sk = sc.keyFor(selector);
SelectionKey sk = this.socketChannel.keyFor(this.selector); if (sk != null) { sk.cancel();