Build 1.0_r1(from source)

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

Abstract class for selectable channels.

In this class, there are methods about registering/deregistering a channel, about channel closing. It realize the multi-thread safe.


Field Summary
(package private)  boolean isBlocking
           
 
Fields inherited from class java.nio.channels.spi.AbstractInterruptibleChannel
interrupted, setInterruptAction
 
Constructor Summary
protected AbstractSelectableChannel(SelectorProvider selectorProvider)
          Constructor for this class.
 
Method Summary
 Object blockingLock()
          Gets the blocking lock which synchronizes the configureBlocking and register methods.
 SelectableChannel configureBlocking(boolean blockingMode)
          Set the blocking mode of this channel.
(package private)  void deregister(SelectionKey k)
           
protected  void implCloseChannel()
          Implement the closing function.
protected abstract  void implCloseSelectableChannel()
          Implement the closing function of the SelectableChannel.
protected abstract  void implConfigureBlocking(boolean blockingMode)
          Implement the setting of blocking mode.
 boolean isBlocking()
          Returns if channel is in blocking mode.
 boolean isRegistered()
          Returns if channel is registered.
 SelectionKey keyFor(Selector selector)
          Gets the selection key for the channel with the given selector.
 SelectorProvider provider()
          Answer the SelectorProvider of this channel.
 SelectionKey register(Selector selector, int interestSet, Object attachment)
          Realize the register function.
 
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
 
Methods inherited from interface java.nio.channels.Channel
close, isOpen
 

Field Detail

isBlocking

boolean isBlocking
Constructor Detail

AbstractSelectableChannel

protected AbstractSelectableChannel(SelectorProvider selectorProvider)
Constructor for this class.

Parameters:
selectorProvider - A instance of SelectorProvider
Method Detail

provider

public final SelectorProvider provider()
Answer the SelectorProvider of this channel.

Specified by:
provider in class SelectableChannel
Returns:
The provider of this channel.
See Also:
SelectableChannel.provider()

isRegistered

public final boolean isRegistered()
Description copied from class: SelectableChannel
Returns if channel is registered.

Specified by:
isRegistered in class SelectableChannel
Returns:
true if channel is registered
See Also:
SelectableChannel.isRegistered()

keyFor

public final SelectionKey keyFor(Selector selector)
Description copied from class: SelectableChannel
Gets the selection key for the channel with the given selector.

Specified by:
keyFor in class SelectableChannel
Parameters:
selector - the selector with which this channel may register
Returns:
the selection key for the channel according to the given selector
See Also:
SelectableChannel.keyFor(java.nio.channels.Selector)

register

public final SelectionKey register(Selector selector,
                                   int interestSet,
                                   Object attachment)
                            throws ClosedChannelException
Realize the register function.

It registers current channel to the selector, then answer the selection key. The channel must be open and the interest op set must be valid. If the current channel is already registered to the selector, the method only set the new interest op set; otherwise it will call the register in selector, and add the relative key to the key set of the current channel.

Specified by:
register in class SelectableChannel
Parameters:
selector - the selector with which this channel shall be registered
interestSet - the interesting operation
attachment - The attached object, which can be null
Returns:
the selection key indicates the channel
Throws:
ClosedChannelException - if the channel is closed
See Also:
SelectableChannel.register(java.nio.channels.Selector, int, java.lang.Object)

implCloseChannel

protected final void implCloseChannel()
                               throws IOException
Implement the closing function.

Specified by:
implCloseChannel in class AbstractInterruptibleChannel
Throws:
IOException - if a problem occurs closing the channel.
See Also:
AbstractInterruptibleChannel.implCloseChannel()

implCloseSelectableChannel

protected abstract void implCloseSelectableChannel()
                                            throws IOException
Implement the closing function of the SelectableChannel.

Throws:
IOException - If some I/O exception occurred.

isBlocking

public final boolean isBlocking()
Description copied from class: SelectableChannel
Returns if channel is in blocking mode.

Specified by:
isBlocking in class SelectableChannel
Returns:
true if channel is blocking
See Also:
SelectableChannel.isBlocking()

blockingLock

public final Object blockingLock()
Description copied from class: SelectableChannel
Gets the blocking lock which synchronizes the configureBlocking and register methods.

Specified by:
blockingLock in class SelectableChannel
Returns:
the blocking object as lock
See Also:
SelectableChannel.blockingLock()

configureBlocking

public final SelectableChannel configureBlocking(boolean blockingMode)
                                          throws IOException
Set the blocking mode of this channel.

Specified by:
configureBlocking in class SelectableChannel
Parameters:
blockingMode - true for blocking mode; false for non-blocking mode.
Returns:
this channel
Throws:
ClosedChannelException - If this channel has been closed
IOException - if I/O error occurs
See Also:
SelectableChannel.configureBlocking(boolean)

implConfigureBlocking

protected abstract void implConfigureBlocking(boolean blockingMode)
                                       throws IOException
Implement the setting of blocking mode.

Parameters:
blockingMode - true for blocking mode; false for non-blocking mode.
Throws:
IOException - If some I/O exception occurred.

deregister

void deregister(SelectionKey k)

Build 1.0_r1(from source)

Please submit a feedback, bug or feature