private boolean isInterestRegistered ( SelectableChannel channel , int operation ) { SelectionKey key = channel . keyFor ( selector ) ; return key != null && ( key . interestOps ( ) & operation ) != 0 ; }
Check whether an operation interest was registered on a SelectableChannel There are two cases that interest is not registered 1 . The whole key does not exist ; no interests ever registered for this channel 2 . The key exists due to other interests registered but not the one we are adding If the key exists the key for SelectableChannel has to be valid . Otherwise InvalidValid Exception would throw .