Share via


Selector.Select Method

Definition

Overloads

Select(IConsumer, Int64)

Selects and performs an action on the keys whose corresponding channels are ready for I/O operations.

Select(Int64)

Selects a set of keys whose corresponding channels are ready for I/O operations.

Select()

Selects a set of keys whose corresponding channels are ready for I/O operations.

Select(IConsumer)

Selects and performs an action on the keys whose corresponding channels are ready for I/O operations.

Select(IConsumer, Int64)

Selects and performs an action on the keys whose corresponding channels are ready for I/O operations.

[Android.Runtime.Register("select", "(Ljava/util/function/Consumer;J)I", "GetSelect_Ljava_util_function_Consumer_JHandler", ApiSince=33)]
public virtual int Select (Java.Util.Functions.IConsumer? action, long timeout);
[<Android.Runtime.Register("select", "(Ljava/util/function/Consumer;J)I", "GetSelect_Ljava_util_function_Consumer_JHandler", ApiSince=33)>]
abstract member Select : Java.Util.Functions.IConsumer * int64 -> int
override this.Select : Java.Util.Functions.IConsumer * int64 -> int

Parameters

action
IConsumer

The action to perform

timeout
Int64

If positive, block for up to timeout milliseconds, more or less, while waiting for a channel to become ready; if zero, block indefinitely; must not be negative

Returns

The number of unique keys consumed, possibly zero

Attributes

Remarks

Selects and performs an action on the keys whose corresponding channels are ready for I/O operations.

This method performs a blocking selection operation. It wakes up from querying the operating system only when at least one channel is selected, this selector's #wakeup wakeup method is invoked, the current thread is interrupted, or the given timeout period expires, whichever comes first.

The specified action's Consumer#accept(Object) accept method is invoked with the key for each channel that is ready to perform an operation identified by its key's interest set. The accept method may be invoked more than once for the same key but with the ready-operation set containing a subset of the operations for which the channel is ready (as described above). The accept method is invoked while synchronized on the selector and its selected-key set. Great care must be taken to avoid deadlocking with other threads that also synchronize on these objects. Selection operations are not reentrant in general and consequently the action should take great care not to attempt a selection operation on the same selector. The behavior when attempting a reentrant selection operation is implementation specific and therefore not specified. If the action closes the selector then ClosedSelectorException is thrown when the action completes. The action is not prohibited from closing channels registered with the selector, nor prohibited from cancelling keys or changing a key's interest set. If a channel is selected but its key is cancelled or its interest set changed before the action is performed on the key then it is implementation specific as to whether the action is invoked (it may be invoked with an SelectionKey#isValid() invalid key). Exceptions thrown by the action are relayed to the caller.

This method does not offer real-time guarantees: It schedules the timeout as if by invoking the Object#wait(long) method.

Added in 11.

Java documentation for java.nio.channels.Selector.select(java.util.function.Consumer<java.nio.channels.SelectionKey>, long).

Portions of this page are modifications based on work created and shared by the Android Open Source Project and used according to terms described in the Creative Commons 2.5 Attribution License.

Applies to

Select(Int64)

Selects a set of keys whose corresponding channels are ready for I/O operations.

[Android.Runtime.Register("select", "(J)I", "GetSelect_JHandler")]
public abstract int Select (long timeout);
[<Android.Runtime.Register("select", "(J)I", "GetSelect_JHandler")>]
abstract member Select : int64 -> int

Parameters

timeout
Int64

If positive, block for up to timeout milliseconds, more or less, while waiting for a channel to become ready; if zero, block indefinitely; must not be negative

Returns

The number of keys, possibly zero, whose ready-operation sets were updated

Attributes

Exceptions

if the selector is closed.

if the given timeout argument is less than zero.

if an I/O error occurs.

Remarks

Selects a set of keys whose corresponding channels are ready for I/O operations.

This method performs a blocking selection operation. It returns only after at least one channel is selected, this selector's #wakeup wakeup method is invoked, the current thread is interrupted, or the given timeout period expires, whichever comes first.

This method does not offer real-time guarantees: It schedules the timeout as if by invoking the Object#wait(long) method.

Java documentation for java.nio.channels.Selector.select(long).

Portions of this page are modifications based on work created and shared by the Android Open Source Project and used according to terms described in the Creative Commons 2.5 Attribution License.

Applies to

Select()

Selects a set of keys whose corresponding channels are ready for I/O operations.

[Android.Runtime.Register("select", "()I", "GetSelectHandler")]
public abstract int Select ();
[<Android.Runtime.Register("select", "()I", "GetSelectHandler")>]
abstract member Select : unit -> int

Returns

The number of keys, possibly zero, whose ready-operation sets were updated

Attributes

Exceptions

if an I/O error occurs.

if the selector is closed.

Remarks

Selects a set of keys whose corresponding channels are ready for I/O operations.

This method performs a blocking selection operation. It returns only after at least one channel is selected, this selector's #wakeup wakeup method is invoked, or the current thread is interrupted, whichever comes first.

Java documentation for java.nio.channels.Selector.select().

Portions of this page are modifications based on work created and shared by the Android Open Source Project and used according to terms described in the Creative Commons 2.5 Attribution License.

Applies to

Select(IConsumer)

Selects and performs an action on the keys whose corresponding channels are ready for I/O operations.

[Android.Runtime.Register("select", "(Ljava/util/function/Consumer;)I", "GetSelect_Ljava_util_function_Consumer_Handler", ApiSince=33)]
public virtual int Select (Java.Util.Functions.IConsumer? action);
[<Android.Runtime.Register("select", "(Ljava/util/function/Consumer;)I", "GetSelect_Ljava_util_function_Consumer_Handler", ApiSince=33)>]
abstract member Select : Java.Util.Functions.IConsumer -> int
override this.Select : Java.Util.Functions.IConsumer -> int

Parameters

action
IConsumer

The action to perform

Returns

The number of unique keys consumed, possibly zero

Attributes

Remarks

Selects and performs an action on the keys whose corresponding channels are ready for I/O operations.

This method performs a blocking selection operation. It wakes up from querying the operating system only when at least one channel is selected, this selector's #wakeup wakeup method is invoked, or the current thread is interrupted, whichever comes first.

This method is equivalent to invoking the 2-arg #select(Consumer, long) select method with a timeout of 0 to block indefinitely.

Added in 11.

Java documentation for java.nio.channels.Selector.select(java.util.function.Consumer<java.nio.channels.SelectionKey>).

Portions of this page are modifications based on work created and shared by the Android Open Source Project and used according to terms described in the Creative Commons 2.5 Attribution License.

Applies to