java.nio.channels.spi
Class AbstractSelectableChannel

java.lang.Object
  extended by java.nio.channels.spi.AbstractInterruptibleChannel
      extended by java.nio.channels.SelectableChannel
          extended by java.nio.channels.spi.AbstractSelectableChannel
All Implemented Interfaces:
Closeable, Channel, InterruptibleChannel
Direct Known Subclasses:
DatagramChannel, Pipe.SinkChannel, Pipe.SourceChannel, ServerSocketChannel, SocketChannel

public abstract class AbstractSelectableChannel
extends SelectableChannel


Constructor Summary
protected AbstractSelectableChannel(SelectorProvider provider)
          Initializes the channel
 
Method Summary
 Object blockingLock()
          Retrieves the object upon which the configureBlocking and register methods synchronize.
 SelectableChannel configureBlocking(boolean blocking)
          Adjusts this channel's blocking mode.
protected  void implCloseChannel()
          Closes this channel.
protected abstract  void implCloseSelectableChannel()
          Closes this selectable channel.
protected abstract  void implConfigureBlocking(boolean blocking)
          Adjusts this channel's blocking mode.
 boolean isBlocking()
          Tells whether or not every I/O operation on this channel will block until it completes.
 boolean isRegistered()
          Tells whether or not this channel is currently registered with any selectors.
 SelectionKey keyFor(Selector selector)
          Retrieves the key representing the channel's registration with the given selector.
 SelectorProvider provider()
          Returns the provider that created this channel.
 SelectionKey register(Selector selin, int ops, Object att)
          Registers this channel with the given selector, returning a selection key.
 
Methods inherited from class java.nio.channels.SelectableChannel
register, validOps
 
Methods inherited from class java.nio.channels.spi.AbstractInterruptibleChannel
begin, close, end, isOpen
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AbstractSelectableChannel

protected AbstractSelectableChannel(SelectorProvider provider)
Initializes the channel

Parameters:
provider - the provider that created this channel
Method Detail

blockingLock

public final Object blockingLock()
Retrieves the object upon which the configureBlocking and register methods synchronize.

Specified by:
blockingLock in class SelectableChannel
Returns:
the blocking lock

configureBlocking

public final SelectableChannel configureBlocking(boolean blocking)
                                          throws IOException
Adjusts this channel's blocking mode.

Specified by:
configureBlocking in class SelectableChannel
Parameters:
blocking - true if blocking should be enabled, false otherwise
Returns:
this channel
Throws:
IOException - If an error occurs

implCloseChannel

protected final void implCloseChannel()
                               throws IOException
Closes this channel.

Specified by:
implCloseChannel in class AbstractInterruptibleChannel
Throws:
IOException - If an error occurs

implCloseSelectableChannel

protected abstract void implCloseSelectableChannel()
                                            throws IOException
Closes this selectable channel.

Throws:
IOException - If an error occurs

implConfigureBlocking

protected abstract void implConfigureBlocking(boolean blocking)
                                       throws IOException
Adjusts this channel's blocking mode.

Parameters:
blocking - true if blocking should be enabled, false otherwise
Throws:
IOException - If an error occurs

isBlocking

public final boolean isBlocking()
Tells whether or not every I/O operation on this channel will block until it completes.

Specified by:
isBlocking in class SelectableChannel
Returns:
true of this channel is blocking, false otherwise

isRegistered

public final boolean isRegistered()
Tells whether or not this channel is currently registered with any selectors.

Specified by:
isRegistered in class SelectableChannel
Returns:
true if this channel is registered, false otherwise

keyFor

public final SelectionKey keyFor(Selector selector)
Retrieves the key representing the channel's registration with the given selector.

Specified by:
keyFor in class SelectableChannel
Parameters:
selector - the selector to get a selection key for
Returns:
the selection key this channel is registered with

provider

public final SelectorProvider provider()
Returns the provider that created this channel.

Specified by:
provider in class SelectableChannel
Returns:
the selector provider that created this channel

register

public final SelectionKey register(Selector selin,
                                   int ops,
                                   Object att)
                            throws ClosedChannelException
Registers this channel with the given selector, returning a selection key.

Specified by:
register in class SelectableChannel
Parameters:
selin - the seletor to use
ops - the interested operations
att - an attachment for the returned selection key
Returns:
the registered selection key
Throws:
ClosedChannelException - If the channel is already closed.
IllegalBlockingModeException - If the channel is configured in blocking mode.