This documentation differs from the official API. Jadeite adds extra features to the API including: variable font sizes, constructions examples, placeholders for classes and methods, and auto-generated “See Also” links. Additionally it is missing some items found in standard Javadoc documentation, including: generics type information, “Deprecated” tags and comments, “See Also” links, along with other minor differences. Please send any questions or feedback to bam@cs.cmu.edu.


java.nio.channels.spi
class AbstractSelector

java.lang.Object extended by java.nio.channels.Selector extended by java.nio.channels.spi.AbstractSelector

public abstract class AbstractSelector
extends Selector

Base implementation class for selectors.

This class encapsulates the low-level machinery required to implement the interruption of selection operations. A concrete selector class must invoke the {@link #begin begin} and {@link #end end} methods before and after, respectively, invoking an I/O operation that might block indefinitely. In order to ensure that the {@link #end end} method is always invoked, these methods should be used within a try ... finally block:

 try {
     begin();
     // Perform blocking I/O operation here
     ...
 } finally {
     end();
 }

This class also defines methods for maintaining a selector's cancelled-key set and for removing a key from its channel's key set, and declares the abstract {@link #register register} method that is invoked by a selectable channel's {@link AbstractSelectableChannel#register register} method in order to perform the actual work of registering a channel.


Constructor Summary
protected

          Initializes a new instance of this class.
 
Method Summary
protected void

          Marks the beginning of an I/O operation that might block indefinitely.
protected Set

          Retrieves this selector's cancelled-key set.
 void

          Closes this selector.
protected void

          Removes the given key from its channel's key set.
protected void
end()

          Marks the end of an I/O operation that might block indefinitely.
protected abstract void

          Closes this selector.
 boolean

          Tells whether or not this selector is open.
 SelectorProvider

          Returns the provider that created this channel.
protected abstract SelectionKey

          Registers the given channel with this selector.
 
Methods inherited from class java.nio.channels.Selector
close, isOpen, keys, open, provider, select, select, selectedKeys, selectNow, wakeup
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AbstractSelector

protected AbstractSelector(SelectorProvider provider)
Initializes a new instance of this class.

Parameters:
provider
Method Detail

begin

protected final void begin()
Marks the beginning of an I/O operation that might block indefinitely.

This method should be invoked in tandem with the {@link #end end} method, using a try ... finally block as shown above, in order to implement interruption for this selector.

Invoking this method arranges for the selector's {@link Selector#wakeup wakeup} method to be invoked if a thread's {@link Thread#interrupt interrupt} method is invoked while the thread is blocked in an I/O operation upon the selector.


cancelledKeys

protected final Set cancelledKeys()
Retrieves this selector's cancelled-key set.

This set should only be used while synchronized upon it.

Returns:
The cancelled-key set

close

public final void close()
                 throws IOException
Closes this selector.

If the selector has already been closed then this method returns immediately. Otherwise it marks the selector as closed and then invokes the {@link #implCloseSelector implCloseSelector} method in order to complete the close operation.

Overrides:
close in class Selector
Throws:
IOException - If an I/O error occurs

deregister

protected final void deregister(AbstractSelectionKey key)
Removes the given key from its channel's key set.

This method must be invoked by the selector for each channel that it deregisters.

Parameters:
key - The selection key to be removed

end

protected final void end()
Marks the end of an I/O operation that might block indefinitely.

This method should be invoked in tandem with the {@link #begin begin} method, using a try ... finally block as shown above, in order to implement interruption for this selector.


implCloseSelector

protected abstract void implCloseSelector()
                                   throws IOException
Closes this selector.

This method is invoked by the {@link #close close} method in order to perform the actual work of closing the selector. This method is only invoked if the selector 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 a selection operation upon this selector to return immediately as if by invoking the {@link java.nio.channels.Selector#wakeup wakeup} method.

Throws:
IOException - If an I/O error occurs while closing the selector

isOpen

public final boolean isOpen()
Overrides:
isOpen in class Selector

provider

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

Overrides:
provider in class Selector
Returns:
The provider that created this channel

register

protected abstract SelectionKey register(AbstractSelectableChannel ch,
                                         int ops,
                                         Object att)
Registers the given channel with this selector.

This method is invoked by a channel's {@link AbstractSelectableChannel#register register} method in order to perform the actual work of registering the channel with this selector.

Parameters:
ch - The channel to be registered
ops - The initial interest set, which must be valid
att - The initial attachment for the resulting key
Returns:
A new key representing the registration of the given channel with this selector


This documentation differs from the official API. Jadeite adds extra features to the API including: variable font sizes, constructions examples, placeholders for classes and methods, and auto-generated “See Also” links. Additionally it is missing some items found in standard Javadoc documentation, including: generics type information, “Deprecated” tags and comments, “See Also” links, along with other minor differences. Please send any questions or feedback to bam@cs.cmu.edu.
This page displays the Jadeite version of the documention, which is derived from the offical documentation that contains this copyright notice:
Copyright 2008 Sun Microsystems, Inc. All rights reserved. Use is subject to license terms. Also see the documentation redistribution policy.
The official Sun™ documentation can be found here at http://java.sun.com/javase/6/docs/api/.