Build 1.0_r1(from source)

java.nio.channels
Class SelectableChannel

java.lang.Object
  extended by java.nio.channels.spi.AbstractInterruptibleChannel
      extended by java.nio.channels.SelectableChannel
All Implemented Interfaces:
Closeable, Channel, InterruptibleChannel
Direct Known Subclasses:
AbstractSelectableChannel

public abstract class SelectableChannel
extends AbstractInterruptibleChannel
implements Channel

A channel that can be detected by a selector. The channel can be registered with some selectors, and when invoke select method of the selectors, the channel can be checked if it is readable, writable, connectable or acceptable according to its interesting operation.


Constructor Summary
protected SelectableChannel()
          Default constructor, can be overridden.
 
Method Summary
abstract  Object blockingLock()
          Gets the blocking lock which synchronizes the configureBlocking and register methods.
abstract  SelectableChannel configureBlocking(boolean block)
          Sets blocking mode of the channel.
abstract  boolean isBlocking()
          Returns if channel is in blocking mode.
abstract  boolean isRegistered()
          Returns if channel is registered.
abstract  SelectionKey keyFor(Selector sel)
          Gets the selection key for the channel with the given selector.
abstract  SelectorProvider provider()
          Gets the provider of the channel.
 SelectionKey register(Selector selector, int operations)
          Registers with the given selector with a certain interesting operation.
abstract  SelectionKey register(Selector sel, int ops, Object att)
          Registers with the given selector with a certain interesting operation and an attached object.
abstract  int validOps()
          Gets the possible interesting operation of the channel.
 
Methods inherited from class java.nio.channels.spi.AbstractInterruptibleChannel
begin, close, end, implCloseChannel, isOpen
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface java.nio.channels.Channel
close, isOpen
 

Constructor Detail

SelectableChannel

protected SelectableChannel()
Default constructor, can be overridden.

Method Detail

blockingLock

public abstract Object blockingLock()
Gets the blocking lock which synchronizes the configureBlocking and register methods.

Returns:
the blocking object as lock

configureBlocking

public abstract SelectableChannel configureBlocking(boolean block)
                                             throws IOException
Sets blocking mode of the channel.

Parameters:
block - true as blocking, false as non-blocking
Returns:
this channel
Throws:
ClosedChannelException - If this channel has been closed
IllegalBlockingModeException - If the channel has been registered
IOException - if I/O error occurs

isBlocking

public abstract boolean isBlocking()
Returns if channel is in blocking mode.

Returns:
true if channel is blocking

isRegistered

public abstract boolean isRegistered()
Returns if channel is registered.

Returns:
true if channel is registered

keyFor

public abstract SelectionKey keyFor(Selector sel)
Gets the selection key for the channel with the given selector.

Parameters:
sel - the selector with which this channel may register
Returns:
the selection key for the channel according to the given selector

provider

public abstract SelectorProvider provider()
Gets the provider of the channel.

Returns:
the provider of the channel

register

public final SelectionKey register(Selector selector,
                                   int operations)
                            throws ClosedChannelException
Registers with the given selector with a certain interesting operation.

Parameters:
selector - the selector with which this channel shall be registered
operations - the interesting operation
Returns:
the selection key indicates the channel
Throws:
ClosedChannelException - if the channel is closed
IllegalBlockingModeException - If the channel is in blocking mode
IllegalSelectorException - If this channel does not have the same provider as the given selector
CancelledKeyException - If this channel is registered but its key has been cancelled
IllegalArgumentException - If the operation given is unsupported by this channel

register

public abstract SelectionKey register(Selector sel,
                                      int ops,
                                      Object att)
                               throws ClosedChannelException
Registers with the given selector with a certain interesting operation and an attached object.

Parameters:
sel - the selector with which this channel shall be registered
ops - the interesting operation
att - The attached object, which can be null
Returns:
the selection key indicates the channel
Throws:
ClosedChannelException - if the channel is closed
IllegalBlockingModeException - If the channel is in blocking mode
IllegalSelectorException - If this channel does not have the same provider with the given selector
CancelledKeyException - If this channel is registered but its key has been cancelled
IllegalArgumentException - If the operation given is unsupported by this channel

validOps

public abstract int validOps()
Gets the possible interesting operation of the channel.

Returns:
the possible interesting operation of the channel

Build 1.0_r1(from source)

Please submit a feedback, bug or feature