java.nio.channels
public abstract class SelectionKey extends Object
Modifier and Type | Field and Description |
---|---|
static int |
OP_ACCEPT |
static int |
OP_CONNECT |
static int |
OP_READ |
static int |
OP_WRITE |
Modifier | Constructor and Description |
---|---|
protected |
SelectionKey()
Initializes the selection key.
|
Modifier and Type | Method and Description |
---|---|
Object |
attach(Object obj)
Attaches obj to the key and returns the old attached object.
|
Object |
attachment()
Returns the object attached to the key.
|
abstract void |
cancel()
Requests that the registration of this key's channel with
its selector be cancelled.
|
abstract SelectableChannel |
channel()
return the channel attached to the key.
|
abstract int |
interestOps()
Returns the key's interest set.
|
abstract SelectionKey |
interestOps(int ops)
Sets this key's interest set to the given value.
|
boolean |
isAcceptable()
Tests if the channel attached to this key is ready to accept
a new socket connection.
|
boolean |
isConnectable()
Tests whether this key's channel has either finished,
or failed to finish, its socket-connection operation.
|
boolean |
isReadable()
Tests if the channel attached to the key is readable.
|
abstract boolean |
isValid()
Tells whether or not this key is valid.
|
boolean |
isWritable()
Tests if the channel attached to the key is writable.
|
abstract int |
readyOps()
Retrieves this key's ready-operation set.
|
abstract Selector |
selector()
Returns the selector for which this key was created.
|
public static final int OP_ACCEPT
public static final int OP_CONNECT
public static final int OP_READ
public static final int OP_WRITE
protected SelectionKey()
public final Object attach(Object obj)
public final Object attachment()
public final boolean isAcceptable()
CancelledKeyException
- If this key has been cancelledpublic final boolean isConnectable()
CancelledKeyException
- If this key has been cancelledpublic final boolean isReadable()
CancelledKeyException
- If this key has been cancelledpublic final boolean isWritable()
CancelledKeyException
- If this key has been cancelledpublic abstract void cancel()
public abstract SelectableChannel channel()
public abstract int interestOps()
CancelledKeyException
- If this key has been cancelledpublic abstract SelectionKey interestOps(int ops)
CancelledKeyException
- If this key has been cancelledIllegalArgumentException
- 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()) != 0public abstract boolean isValid()
public abstract int readyOps()
CancelledKeyException
- If this key has been cancelled