selector.wakeup();
int interestOps;
synchronized (asyncKey) {
SelectionKey key = asyncKey.key;
if (key == null || (!key.isValid())) {
throw new ClosedAsynchronousChannelException();
}
try {
interestOps = key.interestOps();
} catch (CancelledKeyException e) {
throw new ClosedAsynchronousChannelException();
}
SelectableChannel channel = asyncKey.channel();
// These precondition checks don't belong here; they
// should be refactored to AsyncSocketChannelImpl.
// However, they need to occur inside the asyncKey
// lock after we know the interest ops won't change,
// so here they are.
// Only SocketChannel has any extra checks to do.
if (channel instanceof SocketChannel) {
switch (op) {
case OP_READ:
case OP_WRITE:
if (!((SocketChannel) channel).isConnected()) {
throw new NotYetConnectedException();
}
break;
case OP_CONNECT:
if (((SocketChannel) channel).isConnected()) {
throw new AlreadyConnectedException();
}
break;
default:
break;
}
}
// Check that op isn't already in the interest set
assert (interestOps & op) == 0;
interestOps |= op;
try {
key.interestOps(interestOps);
} catch (CancelledKeyException e) {
throw new ClosedAsynchronousChannelException();
}
}
if (log.isLoggable(Level.FINEST)) {
log.log(Level.FINEST,