Udostępnij za pośrednictwem


SelectionKey Class

Definition

A token representing the registration of a SelectableChannel with a Selector.

[Android.Runtime.Register("java/nio/channels/SelectionKey", DoNotGenerateAcw=true)]
public abstract class SelectionKey : Java.Lang.Object
[<Android.Runtime.Register("java/nio/channels/SelectionKey", DoNotGenerateAcw=true)>]
type SelectionKey = class
    inherit Object
Inheritance
SelectionKey
Derived
Attributes

Remarks

A token representing the registration of a SelectableChannel with a Selector.

A selection key is created each time a channel is registered with a selector. A key remains valid until it is cancelled by invoking its #cancel cancel method, by closing its channel, or by closing its selector. Cancelling a key does not immediately remove it from its selector; it is instead added to the selector's <i>cancelled-key set</i> for removal during the next selection operation. The validity of a key may be tested by invoking its #isValid isValid method.

"opsets">

A selection key contains two operation sets represented as integer values. Each bit of an operation set denotes a category of selectable operations that are supported by the key's channel.

<ul>

<li>

The interest set determines which operation categories will be tested for readiness the next time one of the selector's selection methods is invoked. The interest set is initialized with the value given when the key is created; it may later be changed via the #interestOps(int) method.

</li>

<li>

The ready set identifies the operation categories for which the key's channel has been detected to be ready by the key's selector. The ready set is initialized to zero when the key is created; it may later be updated by the selector during a selection operation, but it cannot be updated directly.

</li>

</ul>

That a selection key's ready set indicates that its channel is ready for some operation category is a hint, but not a guarantee, that an operation in such a category may be performed by a thread without causing the thread to block. A ready set is most likely to be accurate immediately after the completion of a selection operation. It is likely to be made inaccurate by external events and by I/O operations that are invoked upon the corresponding channel.

This class defines all known operation-set bits, but precisely which bits are supported by a given channel depends upon the type of the channel. Each subclass of SelectableChannel defines an SelectableChannel#validOps() validOps() method which returns a set identifying just those operations that are supported by the channel. An attempt to set or test an operation-set bit that is not supported by a key's channel will result in an appropriate run-time exception.

It is often necessary to associate some application-specific data with a selection key, for example an object that represents the state of a higher-level protocol and handles readiness notifications in order to implement that protocol. Selection keys therefore support the attachment of a single arbitrary object to a key. An object can be attached via the #attach attach method and then later retrieved via the #attachment() attachment method.

Selection keys are safe for use by multiple concurrent threads. A selection operation will always use the interest-set value that was current at the moment that the operation began.

Added in 1.4.

Java documentation for 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.

Constructors

SelectionKey()

Constructs an instance of this class.

SelectionKey(IntPtr, JniHandleOwnership)

A constructor used when creating managed representations of JNI objects; called by the runtime.

Fields

OpAccept
Obsolete.

Operation-set bit for socket-accept operations.

OpConnect
Obsolete.

Operation-set bit for socket-connect operations.

OpRead
Obsolete.

Operation-set bit for read operations.

OpWrite
Obsolete.

Operation-set bit for write operations.

Properties

Class

Returns the runtime class of this Object.

(Inherited from Object)
Handle

The handle to the underlying Android instance.

(Inherited from Object)
IsAcceptable

Tests whether this key's channel is ready to accept a new socket connection.

IsConnectable

Tests whether this key's channel has either finished, or failed to finish, its socket-connection operation.

IsReadable

Tests whether this key's channel is ready for reading.

IsValid

Indicates whether this key is valid.

IsWritable

Tests whether this key's channel is ready for writing.

JniIdentityHashCode (Inherited from Object)
JniPeerMembers
PeerReference (Inherited from Object)
ThresholdClass

This API supports the Mono for Android infrastructure and is not intended to be used directly from your code.

ThresholdType

This API supports the Mono for Android infrastructure and is not intended to be used directly from your code.

Methods

Attach(Object)

Attaches the given object to this key.

Attachment()

Retrieves the current attachment.

Cancel()

Requests that the registration of this key's channel with its selector be cancelled.

Channel()

Returns the channel for which this key was created.

Clone()

Creates and returns a copy of this object.

(Inherited from Object)
Dispose() (Inherited from Object)
Dispose(Boolean) (Inherited from Object)
Equals(Object)

Indicates whether some other object is "equal to" this one.

(Inherited from Object)
GetHashCode()

Returns a hash code value for the object.

(Inherited from Object)
InterestOps()

Retrieves this key's interest set.

InterestOps(Operations)

Retrieves this key's interest set.

InterestOpsAnd(Int32)

Atomically sets this key's interest set to the bitwise intersection ("and") of the existing interest set and the given value.

InterestOpsOr(Int32)

Atomically sets this key's interest set to the bitwise union ("or") of the existing interest set and the given value.

JavaFinalize()

Called by the garbage collector on an object when garbage collection determines that there are no more references to the object.

(Inherited from Object)
Notify()

Wakes up a single thread that is waiting on this object's monitor.

(Inherited from Object)
NotifyAll()

Wakes up all threads that are waiting on this object's monitor.

(Inherited from Object)
ReadyOps()

Retrieves this key's ready-operation set.

Selector()

Returns the selector for which this key was created.

SetHandle(IntPtr, JniHandleOwnership)

Sets the Handle property.

(Inherited from Object)
ToArray<T>() (Inherited from Object)
ToString()

Returns a string representation of the object.

(Inherited from Object)
UnregisterFromRuntime() (Inherited from Object)
Wait()

Causes the current thread to wait until it is awakened, typically by being <em>notified</em> or <em>interrupted</em>.

(Inherited from Object)
Wait(Int64, Int32)

Causes the current thread to wait until it is awakened, typically by being <em>notified</em> or <em>interrupted</em>, or until a certain amount of real time has elapsed.

(Inherited from Object)
Wait(Int64)

Causes the current thread to wait until it is awakened, typically by being <em>notified</em> or <em>interrupted</em>, or until a certain amount of real time has elapsed.

(Inherited from Object)

Explicit Interface Implementations

IJavaPeerable.Disposed() (Inherited from Object)
IJavaPeerable.DisposeUnlessReferenced() (Inherited from Object)
IJavaPeerable.Finalized() (Inherited from Object)
IJavaPeerable.JniManagedPeerState (Inherited from Object)
IJavaPeerable.SetJniIdentityHashCode(Int32) (Inherited from Object)
IJavaPeerable.SetJniManagedPeerState(JniManagedPeerStates) (Inherited from Object)
IJavaPeerable.SetPeerReference(JniObjectReference) (Inherited from Object)

Extension Methods

JavaCast<TResult>(IJavaObject)

Performs an Android runtime-checked type conversion.

JavaCast<TResult>(IJavaObject)
GetJniTypeName(IJavaPeerable)

Applies to