public void registerChannelNow(SelectableChannel channel, int selectionKeys, SelectorHandler handlerInfo) throws IOException {
if (Thread.currentThread() != selectorThread) {
throw new IOException("Method can only be called from selector thread");
}
if (!channel.isOpen()) {
throw new IOException("Channel is not open.");
}
try {
if (channel.isRegistered()) {
SelectionKey sk = channel.keyFor(selector);
sk.interestOps(selectionKeys);
Object previousAttach = sk.attach(handlerInfo);
} else {
channel.configureBlocking(false);
channel.register(selector, selectionKeys, handlerInfo);
}
} catch (ClosedChannelException e) {
IOException ioe = new IOException("Error registering channel.");
ioe.initCause(e);
throw ioe;
}
}