java.nio.channels.spi
Class AbstractSelectableChannel

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

public abstract class AbstractSelectableChannel
extends SelectableChannel sample code for java.nio.channels.SelectableChannel definition code for java.nio.channels.SelectableChannel

Base implementation class for selectable channels.

This class defines methods that handle the mechanics of channel registration, deregistration, and closing. It maintains the current blocking mode of this channel as well as its current set of selection keys. It performs all of the synchronization required to implement the SelectableChannel sample code for java.nio.channels.SelectableChannel definition code for java.nio.channels.SelectableChannel specification. Implementations of the abstract protected methods defined in this class need not synchronize against other threads that might be engaged in the same operations.

Since:
1.4

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

Constructor Detail

AbstractSelectableChannel sample code for java.nio.channels.spi.AbstractSelectableChannel(java.nio.channels.spi.SelectorProvider) definition code for java.nio.channels.spi.AbstractSelectableChannel(java.nio.channels.spi.SelectorProvider)

protected AbstractSelectableChannel(SelectorProvider sample code for java.nio.channels.spi.SelectorProvider definition code for java.nio.channels.spi.SelectorProvider  provider)
Initializes a new instance of this class.

Method Detail

provider sample code for java.nio.channels.spi.AbstractSelectableChannel.provider() definition code for java.nio.channels.spi.AbstractSelectableChannel.provider()

public final SelectorProvider sample code for java.nio.channels.spi.SelectorProvider definition code for java.nio.channels.spi.SelectorProvider  provider()
Returns the provider that created this channel.

Specified by:
provider sample code for java.nio.channels.SelectableChannel.provider() definition code for java.nio.channels.SelectableChannel.provider() in class SelectableChannel sample code for java.nio.channels.SelectableChannel definition code for java.nio.channels.SelectableChannel
Returns:
The provider that created this channel

isRegistered sample code for java.nio.channels.spi.AbstractSelectableChannel.isRegistered() definition code for java.nio.channels.spi.AbstractSelectableChannel.isRegistered()

public final boolean isRegistered()
Description copied from class: SelectableChannel sample code for java.nio.channels.SelectableChannel.isRegistered() definition code for java.nio.channels.SelectableChannel.isRegistered()
Tells whether or not this channel is currently registered with any selectors. A newly-created channel is not registered.

Due to the inherent delay between key cancellation and channel deregistration, a channel may remain registered for some time after all of its keys have been cancelled. A channel may also remain registered for some time after it is closed.

Specified by:
isRegistered sample code for java.nio.channels.SelectableChannel.isRegistered() definition code for java.nio.channels.SelectableChannel.isRegistered() in class SelectableChannel sample code for java.nio.channels.SelectableChannel definition code for java.nio.channels.SelectableChannel
Returns:
true if, and only if, this channel is registered

keyFor sample code for java.nio.channels.spi.AbstractSelectableChannel.keyFor(java.nio.channels.Selector) definition code for java.nio.channels.spi.AbstractSelectableChannel.keyFor(java.nio.channels.Selector)

public final SelectionKey sample code for java.nio.channels.SelectionKey definition code for java.nio.channels.SelectionKey  keyFor(Selector sample code for java.nio.channels.Selector definition code for java.nio.channels.Selector  sel)
Description copied from class: SelectableChannel sample code for java.nio.channels.SelectableChannel.keyFor(java.nio.channels.Selector) definition code for java.nio.channels.SelectableChannel.keyFor(java.nio.channels.Selector)
Retrieves the key representing the channel's registration with the given selector.

Specified by:
keyFor sample code for java.nio.channels.SelectableChannel.keyFor(java.nio.channels.Selector) definition code for java.nio.channels.SelectableChannel.keyFor(java.nio.channels.Selector) in class SelectableChannel sample code for java.nio.channels.SelectableChannel definition code for java.nio.channels.SelectableChannel
Returns:
The key returned when this channel was last registered with the given selector, or null if this channel is not currently registered with that selector

register sample code for java.nio.channels.spi.AbstractSelectableChannel.register(java.nio.channels.Selector, int, java.lang.Object) definition code for java.nio.channels.spi.AbstractSelectableChannel.register(java.nio.channels.Selector, int, java.lang.Object)

public final SelectionKey sample code for java.nio.channels.SelectionKey definition code for java.nio.channels.SelectionKey  register(Selector sample code for java.nio.channels.Selector definition code for java.nio.channels.Selector  sel,
                                   int ops,
                                   Object sample code for java.lang.Object definition code for java.lang.Object  att)
                            throws ClosedChannelException sample code for java.nio.channels.ClosedChannelException definition code for java.nio.channels.ClosedChannelException 
Registers this channel with the given selector, returning a selection key.

This method first verifies that this channel is open and that the given initial interest set is valid.

If this channel is already registered with the given selector then the selection key representing that registration is returned after setting its interest set to the given value.

Otherwise this channel has not yet been registered with the given selector, so the register sample code for java.nio.channels.spi.AbstractSelector.register(java.nio.channels.spi.AbstractSelectableChannel, int, java.lang.Object) definition code for java.nio.channels.spi.AbstractSelector.register(java.nio.channels.spi.AbstractSelectableChannel, int, java.lang.Object) method of the selector is invoked while holding the appropriate locks. The resulting key is added to this channel's key set before being returned.

Specified by:
register sample code for java.nio.channels.SelectableChannel.register(java.nio.channels.Selector, int, java.lang.Object) definition code for java.nio.channels.SelectableChannel.register(java.nio.channels.Selector, int, java.lang.Object) in class SelectableChannel sample code for java.nio.channels.SelectableChannel definition code for java.nio.channels.SelectableChannel
Parameters:
sel - The selector with which this channel is to be registered
ops - The interest set for the resulting key
att - The attachment for the resulting key; may be null
Returns:
A key representing the registration of this channel with the given selector
Throws:
ClosedChannelException sample code for java.nio.channels.ClosedChannelException definition code for java.nio.channels.ClosedChannelException - If this channel is closed

implCloseChannel sample code for java.nio.channels.spi.AbstractSelectableChannel.implCloseChannel() definition code for java.nio.channels.spi.AbstractSelectableChannel.implCloseChannel()

protected final void implCloseChannel()
                               throws IOException sample code for java.io.IOException definition code for java.io.IOException 
Closes this channel.

This method, which is specified in the AbstractInterruptibleChannel sample code for java.nio.channels.spi.AbstractInterruptibleChannel definition code for java.nio.channels.spi.AbstractInterruptibleChannel class and is invoked by the close sample code for java.nio.channels.Channel.close() definition code for java.nio.channels.Channel.close() method, in turn invokes the implCloseSelectableChannel sample code for java.nio.channels.spi.AbstractSelectableChannel.implCloseSelectableChannel() definition code for java.nio.channels.spi.AbstractSelectableChannel.implCloseSelectableChannel() method in order to perform the actual work of closing this channel. It then cancels all of this channel's keys.

Specified by:
implCloseChannel sample code for java.nio.channels.spi.AbstractInterruptibleChannel.implCloseChannel() definition code for java.nio.channels.spi.AbstractInterruptibleChannel.implCloseChannel() in class AbstractInterruptibleChannel sample code for java.nio.channels.spi.AbstractInterruptibleChannel definition code for java.nio.channels.spi.AbstractInterruptibleChannel
Throws:
IOException sample code for java.io.IOException definition code for java.io.IOException - If an I/O error occurs while closing the channel

implCloseSelectableChannel sample code for java.nio.channels.spi.AbstractSelectableChannel.implCloseSelectableChannel() definition code for java.nio.channels.spi.AbstractSelectableChannel.implCloseSelectableChannel()

protected abstract void implCloseSelectableChannel()
                                            throws IOException sample code for java.io.IOException definition code for java.io.IOException 
Closes this selectable channel.

This method is invoked by the close sample code for java.nio.channels.Channel.close() definition code for java.nio.channels.Channel.close() method in order to perform the actual work of closing the channel. This method is only invoked if the channel has not yet been closed, and it is never invoked more than once.

An implementation of this method must arrange for any other thread that is blocked in an I/O operation upon this channel to return immediately, either by throwing an exception or by returning normally.

Throws:
IOException sample code for java.io.IOException definition code for java.io.IOException

isBlocking sample code for java.nio.channels.spi.AbstractSelectableChannel.isBlocking() definition code for java.nio.channels.spi.AbstractSelectableChannel.isBlocking()

public final boolean isBlocking()
Description copied from class: SelectableChannel sample code for java.nio.channels.SelectableChannel.isBlocking() definition code for java.nio.channels.SelectableChannel.isBlocking()
Tells whether or not every I/O operation on this channel will block until it completes. A newly-created channel is always in blocking mode.

If this channel is closed then the value returned by this method is not specified.

Specified by:
isBlocking sample code for java.nio.channels.SelectableChannel.isBlocking() definition code for java.nio.channels.SelectableChannel.isBlocking() in class SelectableChannel sample code for java.nio.channels.SelectableChannel definition code for java.nio.channels.SelectableChannel
Returns:
true if, and only if, this channel is in blocking mode

blockingLock sample code for java.nio.channels.spi.AbstractSelectableChannel.blockingLock() definition code for java.nio.channels.spi.AbstractSelectableChannel.blockingLock()

public final Object sample code for java.lang.Object definition code for java.lang.Object  blockingLock()
Description copied from class: SelectableChannel sample code for java.nio.channels.SelectableChannel.blockingLock() definition code for java.nio.channels.SelectableChannel.blockingLock()
Retrieves the object upon which the configureBlocking sample code for java.nio.channels.SelectableChannel.configureBlocking(boolean) definition code for java.nio.channels.SelectableChannel.configureBlocking(boolean) and register sample code for java.nio.channels.SelectableChannel.register(java.nio.channels.Selector, int, java.lang.Object) definition code for java.nio.channels.SelectableChannel.register(java.nio.channels.Selector, int, java.lang.Object) methods synchronize. This is often useful in the implementation of adaptors that require a specific blocking mode to be maintained for a short period of time.

Specified by:
blockingLock sample code for java.nio.channels.SelectableChannel.blockingLock() definition code for java.nio.channels.SelectableChannel.blockingLock() in class SelectableChannel sample code for java.nio.channels.SelectableChannel definition code for java.nio.channels.SelectableChannel
Returns:
The blocking-mode lock object

configureBlocking sample code for java.nio.channels.spi.AbstractSelectableChannel.configureBlocking(boolean) definition code for java.nio.channels.spi.AbstractSelectableChannel.configureBlocking(boolean)

public final SelectableChannel sample code for java.nio.channels.SelectableChannel definition code for java.nio.channels.SelectableChannel  configureBlocking(boolean block)
                                          throws IOException sample code for java.io.IOException definition code for java.io.IOException 
Adjusts this channel's blocking mode.

If the given blocking mode is different from the current blocking mode then this method invokes the implConfigureBlocking sample code for java.nio.channels.spi.AbstractSelectableChannel.implConfigureBlocking(boolean) definition code for java.nio.channels.spi.AbstractSelectableChannel.implConfigureBlocking(boolean) method, while holding the appropriate locks, in order to change the mode.

Specified by:
configureBlocking sample code for java.nio.channels.SelectableChannel.configureBlocking(boolean) definition code for java.nio.channels.SelectableChannel.configureBlocking(boolean) in class SelectableChannel sample code for java.nio.channels.SelectableChannel definition code for java.nio.channels.SelectableChannel
Parameters:
block - If true then this channel will be placed in blocking mode; if false then it will be placed non-blocking mode
Returns:
This selectable channel
Throws:
ClosedChannelException sample code for java.nio.channels.ClosedChannelException definition code for java.nio.channels.ClosedChannelException - If this channel is closed
IOException sample code for java.io.IOException definition code for java.io.IOException - If an I/O error occurs

implConfigureBlocking sample code for java.nio.channels.spi.AbstractSelectableChannel.implConfigureBlocking(boolean) definition code for java.nio.channels.spi.AbstractSelectableChannel.implConfigureBlocking(boolean)

protected abstract void implConfigureBlocking(boolean block)
                                       throws IOException sample code for java.io.IOException definition code for java.io.IOException 
Adjusts this channel's blocking mode.

This method is invoked by the configureBlocking sample code for java.nio.channels.spi.AbstractSelectableChannel.configureBlocking(boolean) definition code for java.nio.channels.spi.AbstractSelectableChannel.configureBlocking(boolean) method in order to perform the actual work of changing the blocking mode. This method is only invoked if the new mode is different from the current mode.

Throws:
IOException sample code for java.io.IOException definition code for java.io.IOException - If an I/O error occurs