Android APIs
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

Class Overview

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.
synchronized final boolean isRegistered()
Indicates whether this channel is registered with one or more selectors.
synchronized 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
synchronized 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.
[Expand]
Inherited Methods
From class java.nio.channels.SelectableChannel
From class java.nio.channels.spi.AbstractInterruptibleChannel
From class java.lang.Object
From interface java.io.Closeable
From interface java.lang.AutoCloseable
From interface java.nio.channels.Channel
From interface java.nio.channels.InterruptibleChannel

Protected Constructors

protected AbstractSelectableChannel (SelectorProvider selectorProvider)

Added in API level 1

Constructs a new AbstractSelectableChannel.

Parameters
selectorProvider the selector provider that creates this channel.

Public Methods

public final Object blockingLock ()

Added in API level 1

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

Returns
  • the synchronization object.

public final SelectableChannel configureBlocking (boolean blockingMode)

Added in API level 1

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 true for setting this channel's mode to blocking, false to set it to non-blocking.
Returns
  • 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.

public final boolean isBlocking ()

Added in API level 1

Indicates whether this channel is in blocking mode.

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

public final synchronized boolean isRegistered ()

Added in API level 1

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

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

public final synchronized SelectionKey keyFor (Selector selector)

Added in API level 1

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

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

public final SelectorProvider provider ()

Added in API level 1

Returns the selector provider that has created this channel.

Returns
  • this channel's selector provider.
See Also

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

Added in API level 1

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 the selector with which to register this channel.
interestSet this channel's interest set.
attachment the object to attach, can be null.
Returns
  • 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

protected final synchronized void implCloseChannel ()

Added in API level 1

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.

protected abstract void implCloseSelectableChannel ()

Added in API level 1

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

Throws
IOException if an I/O exception occurs.

protected abstract void implConfigureBlocking (boolean blocking)

Added in API level 1

Implements the configuration of blocking/non-blocking mode.

Parameters
blocking true for blocking, false for non-blocking.
Throws
IOException if an I/O error occurs.