Build 1.0_r1(from source)

java.nio.channels
Class Selector

java.lang.Object
  extended by java.nio.channels.Selector
Direct Known Subclasses:
AbstractSelector

public abstract class Selector
extends Object

A controller for selection of SelectableChannel objects. Selectable channels can be registered with a selector, and get SelectionKey as a linkage. The keys are also added to the selector's keyset. The SelectionKey can be cancelled so that the corresponding channel is no longer registered with the selector. By invoking the select operation, the keyset is checked and all keys that are cancelled since last select operation are moved to cancelledKey set. During the select operation, the channels registered with this selector are checked to see whether they are ready for operation according to their interesting operation.


Constructor Summary
protected Selector()
          The constructor.
 
Method Summary
abstract  void close()
          Closes this selector.
abstract  boolean isOpen()
          Tells whether this selector is open.
abstract  Set<SelectionKey> keys()
          Gets the set of registered keys.
static Selector open()
          The factory method for selector.
abstract  SelectorProvider provider()
          Gets the provider of this selector.
abstract  int select()
          Detects if any of the registered channels are ready for I/O operations according to their interesting operation.
abstract  int select(long timeout)
          Detects if any of the registered channels are ready for I/O operations according to their interesting operation.This operation will not return until some of the channels are ready or wakeup is invoked or timeout expired.
abstract  Set<SelectionKey> selectedKeys()
          Gets the keys whose channels are ready for operation.
abstract  int selectNow()
          Detects if any of the registered channels are ready for I/O operations according to their interesting operation.This operation will not return immediately.
abstract  Selector wakeup()
          Forces the blocked select operation to return immediately.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Selector

protected Selector()
The constructor.

Method Detail

open

public static Selector open()
                     throws IOException
The factory method for selector.

Returns:
a new selector
Throws:
IOException - if I/O error occurs

close

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

Throws:
IOException - if I/O error occurs

isOpen

public abstract boolean isOpen()
Tells whether this selector is open.

Returns:
true if this selector is not closed

keys

public abstract Set<SelectionKey> keys()
Gets the set of registered keys.

Returns:
the keyset of registered keys

provider

public abstract SelectorProvider provider()
Gets the provider of this selector.

Returns:
the provider of this selector

select

public abstract int select()
                    throws IOException
Detects if any of the registered channels are ready for I/O operations according to their interesting operation. This operation will not return until some of the channels are ready or wakeup is invoked.

Returns:
the number of channels that are ready for operation
Throws:
IOException - if I/O error occurs
ClosedSelectorException - If the selector is closed

select

public abstract int select(long timeout)
                    throws IOException
Detects if any of the registered channels are ready for I/O operations according to their interesting operation.This operation will not return until some of the channels are ready or wakeup is invoked or timeout expired.

Parameters:
timeout - the timeout in millisecond
Returns:
the number of channels that are ready for operation
Throws:
IOException - if I/O error occurs
ClosedSelectorException - If the selector is closed
IllegalArgumentException - If the given timeout argument is less than zero

selectedKeys

public abstract Set<SelectionKey> selectedKeys()
Gets the keys whose channels are ready for operation.

Returns:
the keys whose channels are ready for operation

selectNow

public abstract int selectNow()
                       throws IOException
Detects if any of the registered channels are ready for I/O operations according to their interesting operation.This operation will not return immediately.

Returns:
the number of channels that are ready for operation
Throws:
IOException - if I/O error occur
ClosedSelectorException - If the selector is closed

wakeup

public abstract Selector wakeup()
Forces the blocked select operation to return immediately. If no select operation is blocked currently, the next select operation shall return immediately.

Returns:
this selector
Throws:
ClosedSelectorException - If the selector is closed

Build 1.0_r1(from source)

Please submit a feedback, bug or feature