@Override public void removeConnection(AsyncConnection conn) { connections.remove(conn); conn.close(); } }
ByteBuffer buffer2 = ByteBuffer.wrap(bytes); NioBuffer nioBuffer = new NioBuffer(DataBuffer.create(buffer2)); conn.handle(nioBuffer); } else { ByteBuffer buffer2 = ByteBuffer.allocate(remaining);
private void connectionEstablished(SelectionKey key, Object att) throws Exception { SocketChannel channel = (SocketChannel) key.channel(); if (!channel.isConnectionPending()) return; Attachment attachment = (Attachment) att; AsyncConnection conn; try { channel.finishConnect(); nioEventLoopAdapter.addSocketChannel(channel); NioWritableChannel writableChannel = new NioWritableChannel(channel, this); if (attachment.connectionManager != null) { conn = attachment.connectionManager.createConnection(writableChannel, false); } else { conn = new TcpClientConnection(writableChannel, this); } conn.setInetSocketAddress(attachment.inetSocketAddress); addConnection(attachment.inetSocketAddress, conn); channel.register(nioEventLoopAdapter.getSelector(), SelectionKey.OP_READ, conn); } finally { attachment.latch.countDown(); } }
private void read(SelectionKey key) { AsyncConnection conn = (AsyncConnection) key.attachment(); SocketChannel channel = (SocketChannel) key.channel(); try { while (true) { DataBuffer dataBuffer = DataBuffer.create(Transfer.BUFFER_SIZE); ByteBuffer buffer = dataBuffer.getBuffer(); int count = channel.read(buffer); if (count <= 0) break; buffer.flip(); NioBuffer nioBuffer = new NioBuffer(dataBuffer); conn.handle(nioBuffer); } } catch (IOException e) { closeChannel(channel); } }
@Override public void close() { if (!closed.compareAndSet(false, true)) return; opened.set(false); for (AsyncConnection conn : asyncConnections.values()) { try { conn.close(); } catch (Throwable e) { } } asyncConnections.clear(); closeInternal(); }
conn.handle(nioBuffer);