java.nio.channels

Class SelectionKey

public abstract class SelectionKey extends Object

Since: 1.4

Field Summary
static intOP_ACCEPT
static intOP_CONNECT
static intOP_READ
static intOP_WRITE
Constructor Summary
protected SelectionKey()
Initializes the selection key.
Method Summary
Objectattach(Object obj)
Attaches obj to the key and returns the old attached object.
Objectattachment()
Returns the object attached to the key.
abstract voidcancel()
Requests that the registration of this key's channel with its selector be cancelled.
abstract SelectableChannelchannel()
return the channel attached to the key.
abstract intinterestOps()
Returns the key's interest set.
abstract SelectionKeyinterestOps(int ops)
Sets this key's interest set to the given value.
booleanisAcceptable()
Tests if the channel attached to this key is ready to accept a new socket connection.
booleanisConnectable()
Tests whether this key's channel has either finished, or failed to finish, its socket-connection operation.
booleanisReadable()
Tests if the channel attached to the key is readable.
abstract booleanisValid()
Tells whether or not this key is valid.
booleanisWritable()
Tests if the channel attached to the key is writable.
abstract intreadyOps()
Retrieves this key's ready-operation set.
abstract Selectorselector()
Returns the selector for which this key was created.

Field Detail

OP_ACCEPT

public static final int OP_ACCEPT

OP_CONNECT

public static final int OP_CONNECT

OP_READ

public static final int OP_READ

OP_WRITE

public static final int OP_WRITE

Constructor Detail

SelectionKey

protected SelectionKey()
Initializes the selection key.

Method Detail

attach

public final Object attach(Object obj)
Attaches obj to the key and returns the old attached object.

attachment

public final Object attachment()
Returns the object attached to the key.

cancel

public abstract void cancel()
Requests that the registration of this key's channel with its selector be cancelled.

channel

public abstract SelectableChannel channel()
return the channel attached to the key.

interestOps

public abstract int interestOps()
Returns the key's interest set.

Throws: CancelledKeyException If this key has been cancelled

interestOps

public abstract SelectionKey interestOps(int ops)
Sets this key's interest set to the given value.

Throws: CancelledKeyException If this key has been cancelled IllegalArgumentException If a bit in the set does not correspond to an operation that is supported by this key's channel, that is, if set & ~(channel().validOps()) != 0

isAcceptable

public final boolean isAcceptable()
Tests if the channel attached to this key is ready to accept a new socket connection.

Throws: CancelledKeyException If this key has been cancelled

isConnectable

public final boolean isConnectable()
Tests whether this key's channel has either finished, or failed to finish, its socket-connection operation.

Throws: CancelledKeyException If this key has been cancelled

isReadable

public final boolean isReadable()
Tests if the channel attached to the key is readable.

Throws: CancelledKeyException If this key has been cancelled

isValid

public abstract boolean isValid()
Tells whether or not this key is valid.

isWritable

public final boolean isWritable()
Tests if the channel attached to the key is writable.

Throws: CancelledKeyException If this key has been cancelled

readyOps

public abstract int readyOps()
Retrieves this key's ready-operation set.

Throws: CancelledKeyException If this key has been cancelled

selector

public abstract Selector selector()
Returns the selector for which this key was created.