Added in API level 1

AbstractSelector

abstract class AbstractSelector : Selector
kotlin.Any
   ↳ 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 java.nio.channels.spi.AbstractSelectableChannel#register method in order to perform the actual work of registering a channel.

Summary

Protected constructors

Initializes a new instance of this class.

Public methods
Unit

Closes this selector.

Boolean

SelectorProvider!

Returns the provider that created this channel.

Protected methods
Unit

Marks the beginning of an I/O operation that might block indefinitely.

MutableSet<SelectionKey!>!

Retrieves this selector's cancelled-key set.

Unit

Removes the given key from its channel's key set.

Unit
end()

Marks the end of an I/O operation that might block indefinitely.

abstract Unit

Closes this selector.

abstract SelectionKey!

Registers the given channel with this selector.

Inherited functions

Protected constructors

AbstractSelector

Added in API level 1
protected AbstractSelector(provider: SelectorProvider!)

Initializes a new instance of this class.

Parameters
provider SelectorProvider!: The provider that created this selector

Public methods

close

Added in API level 1
fun close(): Unit

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.

Exceptions
java.lang.Exception if this resource cannot be closed
java.io.IOException If an I/O error occurs

isOpen

Added in API level 1
fun isOpen(): Boolean
Return
Boolean true if, and only if, this selector is open

provider

Added in API level 1
fun provider(): SelectorProvider!

Returns the provider that created this channel.

Return
SelectorProvider! The provider that created this channel

Protected methods

begin

Added in API level 1
protected fun begin(): Unit

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.

cancelledKeys

Added in API level 1
protected fun cancelledKeys(): MutableSet<SelectionKey!>!

Retrieves this selector's cancelled-key set.

This set should only be used while synchronized upon it.

Return
MutableSet<SelectionKey!>! The cancelled-key set

deregister

Added in API level 1
protected fun deregister(key: AbstractSelectionKey!): Unit

Removes the given key from its channel's key set.

This method must be invoked by the selector for each channel that it deregisters.

Parameters
key AbstractSelectionKey!: The selection key to be removed

end

Added in API level 1
protected fun end(): Unit

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.

implCloseSelector

Added in API level 1
protected abstract fun implCloseSelector(): Unit

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.

Exceptions
java.io.IOException If an I/O error occurs while closing the selector

register

Added in API level 1
protected abstract fun register(
    ch: AbstractSelectableChannel!,
    ops: Int,
    att: Any!
): SelectionKey!

Registers the given channel with this selector.

This method is invoked by a channel's java.nio.channels.spi.AbstractSelectableChannel#register method in order to perform the actual work of registering the channel with this selector.

Parameters
ch AbstractSelectableChannel!: The channel to be registered
ops Int: The initial interest set, which must be valid
att Any!: The initial attachment for the resulting key
Return
SelectionKey! A new key representing the registration of the given channel with this selector