@Override protected void doProcessing() { SocketChannel socketChannel; while ((socketChannel = accepted.poll()) != null) { U.debug("incoming connection", "address", socketChannel.socket().getRemoteSocketAddress()); try { SelectionKey newKey = socketChannel.register(selector, SelectionKey.OP_READ); RapidoidConnection conn = connections.get(); conn.key = newKey; if (isProtocolListener) { conn.setListener((ConnectionListener) protocol); } newKey.attach(conn); } catch (ClosedChannelException e) { U.warn("Closed channel", e); } } synchronized (done) { for (int i = 0; i < done.size(); i++) { RapidoidConnection conn = done.get(i); if (conn.key != null && conn.key.isValid()) { conn.key.interestOps(SelectionKey.OP_WRITE); } } done.clear(); } }
private void wantToWriteAsync(RapidoidConnection conn) { synchronized (done) { done.add(conn); } selector.wakeup(); }