@Override public void update(Selectable selectable) { if (selectable.getChannel() != null) { int interestedOps = 0; if (selectable.getChannel() instanceof SocketChannel && ((SocketChannel)selectable.getChannel()).isConnectionPending()) { interestedOps |= SelectionKey.OP_CONNECT; } else { if (selectable.isReading()) { if (selectable.getChannel() instanceof ServerSocketChannel) { interestedOps |= SelectionKey.OP_ACCEPT; } else { interestedOps |= SelectionKey.OP_READ; } } if (selectable.isWriting()) interestedOps |= SelectionKey.OP_WRITE; } SelectionKey key = selectable.getChannel().keyFor(selector); key.interestOps(interestedOps); } }
@Override public void update(Selectable selectable) { if (selectable.getChannel() != null) { int interestedOps = 0; if (selectable.getChannel() instanceof SocketChannel && ((SocketChannel)selectable.getChannel()).isConnectionPending()) { interestedOps |= SelectionKey.OP_CONNECT; } else { if (selectable.isReading()) { if (selectable.getChannel() instanceof ServerSocketChannel) { interestedOps |= SelectionKey.OP_ACCEPT; } else { interestedOps |= SelectionKey.OP_READ; } } if (selectable.isWriting()) interestedOps |= SelectionKey.OP_WRITE; } SelectionKey key = selectable.getChannel().keyFor(selector); key.interestOps(interestedOps); } }