public abstract SelectionKey register (Selector sel, int ops, Object att) throws ClosedChannelException

Registers this channel with the given selector, returning a selection key.

If this channel is currently registered with the given selector then the selection key representing that registration is returned. The key's interest set will have been changed to ops, as if by invoking the interestOps(int) method. If the att argument is not null then the key's attachment will have been set to that value. A CancelledKeyException will be thrown if the key has already been cancelled.

Otherwise this channel has not yet been registered with the given selector, so it is registered and the resulting new key is returned. The key's initial interest set will be ops and its attachment will be att.

This method may be invoked at any time. If this method is invoked while another invocation of this method or of the configureBlocking method is in progress then it will first block until the other operation is complete. This method will then synchronize on the selector's key set and therefore may block if invoked concurrently with another registration or selection operation involving the same selector.

If this channel is closed while this operation is in progress then the key returned by this method will have been cancelled and will therefore be invalid.

sel     The selector with which this channel is to be registered
ops     The interest set for the resulting key
att     The attachment for the resulting key; may be null

Returns:  A key representing the registration of this channel with the given selector

ClosedChannelException     If this channel is closed
ClosedSelectorException     If the selector is closed
IllegalBlockingModeException     If this channel is in blocking mode
IllegalSelectorException     If this channel was not created by the same provider as the given selector
CancelledKeyException     If this channel is currently registered with the given selector but the corresponding key has already been cancelled
IllegalArgumentException     If a bit in the ops set does not correspond to an operation that is supported by this channel, that is, if set & ~validOps() != 0