Name
SelectableChannel
Synopsis
This abstract class defines the API for
channels that can be used with a Selector object
to allow a thread to block while waiting for activity on any of a
group of channels. All channel classes in the
java.nio.channels package except for
FileChannel are subclasses of
SelectableChannel.
A selectable channel may only be registered with a
Selector if it is nonblocking, so this class
defines the configureBlocking(
)
method. Pass false to this method to put a channel
into nonblocking mode, or pass true to make calls
to its read( )
and/or write( )
methods block. Use isBlocking( ) to determine the
current blocking mode of a selectable channel.
Register a SelectableChannel with a
Selector by calling the register(
)
method of the channel (not
of the selector). There are two versions of this method: both take a
Selector object and a bitmask that specifies the
set of channel operations that are to be
“selected” on that channel. (see
SelectionKey for the constants that can be OR-ed
together to form this bitmask). Both methods return a
SelectionKey object that represents the
registration of the channel with the selector. One version of the
register( ) method also takes an arbitrary object
argument which serves as an
“attachment” to the
SelectionKey and allows you to associate arbitrary
data with it. The validOps( ) method returns a
bitmask that specifies the set of operations that a particular
channel object allows to be selected. The bitmask
passed to register( ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access