Save This Page
Home » openjdk-7 » java » nio » channels » spi » [javadoc | source]
java.nio.channels.spi
abstract public class: AbstractSelector [javadoc | source]
java.lang.Object
   java.nio.channels.Selector
      java.nio.channels.spi.AbstractSelector
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 begin and end methods before and after, respectively, invoking an I/O operation that might block indefinitely. In order to ensure that the 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 register method that is invoked by a selectable channel's register method in order to perform the actual work of registering a channel.

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

Method from java.nio.channels.spi.AbstractSelector Summary:
begin,   cancel,   cancelledKeys,   close,   deregister,   end,   implCloseSelector,   isOpen,   provider,   register
Methods from java.nio.channels.Selector:
close,   isOpen,   keys,   open,   provider,   select,   select,   selectNow,   selectedKeys,   wakeup
Methods from java.lang.Object:
clone,   equals,   finalize,   getClass,   hashCode,   notify,   notifyAll,   toString,   wait,   wait,   wait
Method from java.nio.channels.spi.AbstractSelector Detail:
 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 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 wakeup method to be invoked if a thread's interrupt method is invoked while the thread is blocked in an I/O operation upon the selector.

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

    This set should only be used while synchronized upon it.

 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 implCloseSelector method in order to complete the close operation.

 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.

 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 begin method, using a try ... finally block as shown above, in order to implement interruption for this selector.

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

    This method is invoked by the 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 wakeup method.

 public final boolean isOpen() 
 public final SelectorProvider provider() 
    Returns the provider that created this channel.
 abstract protected SelectionKey register(AbstractSelectableChannel ch,
    int ops,
    Object att)
    Registers the given channel with this selector.

    This method is invoked by a channel's register method in order to perform the actual work of registering the channel with this selector.