java.nio.channels
public
abstract
class
java.nio.channels.Selector
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.
Known Direct Subclasses
Summary
Protected Constructors
Public Methods
clone,
equals,
finalize,
getClass,
hashCode,
notify,
notifyAll,
toString,
wait,
wait,
wait
Details
Protected Constructors
protected
Selector()
The constructor.
Public Methods
public
abstract
void
close()
public
abstract
boolean
isOpen()
Tells whether this selector is open.
Returns
- true if this selector is not closed
Gets the set of registered keys.
Returns
- the keyset of registered keys
public
static
Selector
open()
The factory method for selector.
Gets the provider of this selector.
Returns
- the provider of this selector
public
abstract
int
select()
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
public
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.
Parameters
timeout
| the timeout in millisecond |
Returns
- the number of channels that are ready for operation
public
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.
Returns
- the number of channels that are ready for operation
public
abstract
Set<SelectionKey>
selectedKeys()
Gets the keys whose channels are ready for operation.
Returns
- the keys whose channels are ready for operation
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.