Android
java.nio.channels
public abstract class

java.nio.channels.Selector

java.lang.Object
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

            Selector()
The constructor.

Public Methods

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          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          Set<SelectionKey selectedKeys()
Gets the keys whose channels are ready for operation.
abstract          Selector  wakeup()
Forces the blocked select operation to return immediately.
Methods inherited from class java.lang.Object

Details

Protected Constructors

protected Selector()

The constructor.

Public Methods

public abstract void close()

Closes this selector.

Throws

IOException if I/O error occurs

public abstract boolean isOpen()

Tells whether this selector is open.

Returns

  • true if this selector is not closed

public abstract Set<SelectionKey> keys()

Gets the set of registered keys.

Returns

  • the keyset of registered keys

public static Selector open()

The factory method for selector.

Returns

  • a new selector

Throws

IOException if I/O error occurs

public abstract SelectorProvider provider()

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

Throws

IOException if I/O error occurs
ClosedSelectorException If the selector is closed

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

Throws

IOException if I/O error occurs
ClosedSelectorException If the selector is closed
IllegalArgumentException If the given timeout argument is less than zero

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

Throws

IOException if I/O error occur
ClosedSelectorException If the selector is closed

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.

Returns

  • this selector

Throws

ClosedSelectorException If the selector is closed
Copyright 2007 Google Inc. Build 0.9_r1-98467 - 14 Aug 2008 18:56