use of org.webpieces.nio.api.testutil.nioapi.Select in project webpieces by deanhiller.
the class Helper method unregisterSelectableChannel.
static void unregisterSelectableChannel(RegisterableChannelImpl channel, int ops) {
SelectorManager2 mgr = channel.getSelectorManager();
if (!Thread.currentThread().equals(mgr.getThread()))
throw new RuntimeException(channel + "Bug, changing selector keys can only be done " + "on registration thread because there is not synchronization");
//this could be dangerous and result in deadlock....may want
//to move this to the selector thread from jdk bugs!!!
//but alas, follow KISS, move on...
Select select = channel.getSelectorManager().getSelector();
SelectionKey key = channel.keyFor(select);
if (//no need to unregister, key is cancelled
key == null || !key.isValid())
return;
int previous = key.interestOps();
//subtract out the operation
int opsNow = previous & ~ops;
key.interestOps(opsNow);
//make sure we remove the appropriate listener and clean up
if (key.attachment() != null) {
WrapperAndListener struct = (WrapperAndListener) key.attachment();
struct.removeListener(ops);
}
}
Aggregations