public abstract class AbstractSelectableChannel extends SelectableChannel
AbstractSelectableChannel is the base implementation class for
selectable channels. It declares methods for registering, unregistering and
closing selectable channels. It is thread-safe.| Modifier | Constructor and Description |
|---|---|
protected |
AbstractSelectableChannel(SelectorProvider selectorProvider)
Constructs a new
AbstractSelectableChannel. |
| Modifier and Type | Method and Description |
|---|---|
Object |
blockingLock()
Gets the object used for the synchronization of
register and
configureBlocking. |
SelectableChannel |
configureBlocking(boolean blockingMode)
Sets the blocking mode of this channel.
|
protected void |
implCloseChannel()
Implements the channel closing behavior.
|
protected abstract void |
implCloseSelectableChannel()
Implements the closing function of the SelectableChannel.
|
protected abstract void |
implConfigureBlocking(boolean blocking)
Implements the configuration of blocking/non-blocking mode.
|
boolean |
isBlocking()
Indicates whether this channel is in blocking mode.
|
boolean |
isRegistered()
Indicates whether this channel is registered with one or more selectors.
|
SelectionKey |
keyFor(Selector selector)
Gets this channel's selection key for the specified selector.
|
SelectorProvider |
provider()
Returns the selector provider that has created this channel.
|
SelectionKey |
register(Selector selector,
int interestSet,
Object attachment)
Registers this channel with the specified selector for the specified
interest set.
|
register, validOpsbegin, close, end, isOpenprotected AbstractSelectableChannel(SelectorProvider selectorProvider)
AbstractSelectableChannel.selectorProvider - the selector provider that creates this channel.public final SelectorProvider provider()
provider in class SelectableChannelSelectableChannel.provider()public final boolean isRegistered()
isRegistered in class SelectableChanneltrue if this channel is registered with a selector,
false otherwise.public final SelectionKey keyFor(Selector selector)
keyFor in class SelectableChannelselector - the selector with which this channel has been registered.null if this channel
has not been registered with selector.public final SelectionKey register(Selector selector, int interestSet, Object attachment) throws ClosedChannelException
interest set is updated to interestSet and
the corresponding selection key is returned. If the channel is not yet
registered, this method calls the register method of
selector and adds the selection key to this channel's key set.register in class SelectableChannelselector - the selector with which to register this channel.interestSet - this channel's interest set.attachment - the object to attach, can be null.CancelledKeyException - if this channel is registered but its key has been canceled.ClosedChannelException - if this channel is closed.IllegalArgumentException - if interestSet is not supported by this channel.IllegalBlockingModeException - if this channel is in blocking mode.IllegalSelectorException - if this channel does not have the same provider as the given
selector.protected final void implCloseChannel()
throws IOException
implCloseSelectableChannel() first, then loops through the list
of selection keys and cancels them, which unregisters this channel from
all selectors it is registered with.implCloseChannel in class AbstractInterruptibleChannelIOException - if a problem occurs while closing the channel.protected abstract void implCloseSelectableChannel()
throws IOException
implCloseChannel().IOException - if an I/O exception occurs.public final boolean isBlocking()
isBlocking in class SelectableChanneltrue if this channel is blocking, false
otherwise.public final Object blockingLock()
register and
configureBlocking.blockingLock in class SelectableChannelpublic final SelectableChannel configureBlocking(boolean blockingMode) throws IOException
register are executing. The
actual setting of the mode is done by calling
implConfigureBlocking(boolean).configureBlocking in class SelectableChannelblockingMode - true for setting this channel's mode to blocking,
false to set it to non-blocking.ClosedChannelException - if this channel is closed.IllegalBlockingModeException - if block is true and this channel has been
registered with at least one selector.IOException - if an I/O error occurs.SelectableChannel.configureBlocking(boolean)protected abstract void implConfigureBlocking(boolean blocking)
throws IOException
blocking - true for blocking, false for non-blocking.IOException - if an I/O error occurs.