Skip to content

Most visited

Recently visited

navigation
Added in API level 1

AbstractSelectableChannel

public abstract class AbstractSelectableChannel
extends SelectableChannel

java.lang.Object
   ↳ java.nio.channels.spi.AbstractInterruptibleChannel
     ↳ java.nio.channels.SelectableChannel
       ↳ java.nio.channels.spi.AbstractSelectableChannel
Known Direct Subclasses


AbstractSelectableChannel is the base implementation class for selectable channels. It declares methods for registering, unregistering and closing selectable channels. It is thread-safe.

Summary

Protected constructors

AbstractSelectableChannel(SelectorProvider selectorProvider)

Constructs a new AbstractSelectableChannel.

Public methods

final Object blockingLock()

Gets the object used for the synchronization of register and configureBlocking.

final SelectableChannel configureBlocking(boolean blockingMode)

Sets the blocking mode of this channel.

final boolean isBlocking()

Indicates whether this channel is in blocking mode.

final boolean isRegistered()

Indicates whether this channel is registered with one or more selectors.

final SelectionKey keyFor(Selector selector)

Gets this channel's selection key for the specified selector.

final SelectorProvider provider()

Returns the selector provider that has created this channel.

final SelectionKey register(Selector selector, int interestSet, Object attachment)

Registers this channel with the specified selector for the specified interest set.

Protected methods

final void implCloseChannel()

Implements the channel closing behavior.

abstract void implCloseSelectableChannel()

Implements the closing function of the SelectableChannel.

abstract void implConfigureBlocking(boolean blocking)

Implements the configuration of blocking/non-blocking mode.

Inherited methods

From class java.nio.channels.SelectableChannel
From class java.nio.channels.spi.AbstractInterruptibleChannel
From class java.lang.Object
From interface java.nio.channels.Channel
From interface java.nio.channels.InterruptibleChannel
From interface java.io.Closeable
From interface java.lang.AutoCloseable

Protected constructors

AbstractSelectableChannel

Added in API level 1
AbstractSelectableChannel (SelectorProvider selectorProvider)

Constructs a new AbstractSelectableChannel.

Parameters
selectorProvider SelectorProvider: the selector provider that creates this channel.

Public methods

blockingLock

Added in API level 1
Object blockingLock ()

Gets the object used for the synchronization of register and configureBlocking.

Returns
Object the synchronization object.

configureBlocking

Added in API level 1
SelectableChannel configureBlocking (boolean blockingMode)

Sets the blocking mode of this channel. A call to this method blocks if other calls to this method or to register are executing. The actual setting of the mode is done by calling implConfigureBlocking(boolean).

Parameters
blockingMode boolean: true for setting this channel's mode to blocking, false to set it to non-blocking.
Returns
SelectableChannel this channel.
Throws
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.

See also:

isBlocking

Added in API level 1
boolean isBlocking ()

Indicates whether this channel is in blocking mode.

Returns
boolean true if this channel is blocking, false otherwise.

isRegistered

Added in API level 1
boolean isRegistered ()

Indicates whether this channel is registered with one or more selectors.

Returns
boolean true if this channel is registered with a selector, false otherwise.

keyFor

Added in API level 1
SelectionKey keyFor (Selector selector)

Gets this channel's selection key for the specified selector.

Parameters
selector Selector: the selector with which this channel has been registered.
Returns
SelectionKey the selection key for the channel or null if this channel has not been registered with selector.

provider

Added in API level 1
SelectorProvider provider ()

Returns the selector provider that has created this channel.

Returns
SelectorProvider this channel's selector provider.

See also:

register

Added in API level 1
SelectionKey register (Selector selector, 
                int interestSet, 
                Object attachment)

Registers this channel with the specified selector for the specified interest set. If the channel is already registered with the selector, the 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.

Parameters
selector Selector: the selector with which to register this channel.
interestSet int: this channel's interest set.
attachment Object: the object to attach, can be null.
Returns
SelectionKey the selection key for this registration.
Throws
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 methods

implCloseChannel

Added in API level 1
void implCloseChannel ()

Implements the channel closing behavior. Calls implCloseSelectableChannel() first, then loops through the list of selection keys and cancels them, which unregisters this channel from all selectors it is registered with.

Throws
IOException if a problem occurs while closing the channel.

implCloseSelectableChannel

Added in API level 1
void implCloseSelectableChannel ()

Implements the closing function of the SelectableChannel. This method is called from implCloseChannel().

Throws
IOException if an I/O exception occurs.

implConfigureBlocking

Added in API level 1
void implConfigureBlocking (boolean blocking)

Implements the configuration of blocking/non-blocking mode.

Parameters
blocking boolean: true for blocking, false for non-blocking.
Throws
IOException if an I/O error occurs.
This site uses cookies to store your preferences for site-specific language and display options.

Hooray!

This class requires API level or higher

This doc is hidden because your selected API level for the documentation is . You can change the documentation API level with the selector above the left navigation.

For more information about specifying the API level your app requires, read Supporting Different Platform Versions.