|
Préférences
Moteurs de recherche
|
||||||||||||||||||||||||||||||||||||||||||||||
JavaTM 2 Platform Std. Ed. v1.5.0
java.nio.channels
|
Field Summary | |
---|---|
static int |
OP_ACCEPT
Operation-set bit for socket-accept operations. |
static int |
OP_CONNECT
Operation-set bit for socket-connect operations. |
static int |
OP_READ
Operation-set bit for read operations. |
static int |
OP_WRITE
Operation-set bit for write operations. |
Constructor Summary | |
---|---|
protected |
SelectionKey()
Constructs an instance of this class. |
Method Summary | |
---|---|
Object |
attach(Object ob)
Attaches the given object to this key. |
Object |
attachment()
Retrieves the current attachment. |
abstract void |
cancel()
Requests that the registration of this key's channel with its selector be cancelled. |
abstract SelectableChannel |
channel()
Returns the channel for which this key was created. |
abstract int |
interestOps()
Retrieves this key's interest set. |
abstract SelectionKey |
interestOps(int ops)
Sets this key's interest set to the given value. |
boolean |
isAcceptable()
Tests whether this key's channel 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 whether this key's channel is ready for reading. |
abstract boolean |
isValid()
Tells whether or not this key is valid. |
boolean |
isWritable()
Tests whether this key's channel is ready for writing. |
abstract int |
readyOps()
Retrieves this key's ready-operation set. |
abstract Selector |
selector()
Returns the selector for which this key was created. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final int OP_READ
Suppose that a selection key's interest set contains OP_READ at the start of a selection operation. If the selector detects that the corresponding channel is ready for reading, has reached end-of-stream, has been remotely shut down for further reading, or has an error pending, then it will add OP_READ to the key's ready-operation set and add the key to its selected-key set.
public static final int OP_WRITE
Suppose that a selection key's interest set contains OP_WRITE at the start of a selection operation. If the selector detects that the corresponding channel is ready for writing, has been remotely shut down for further writing, or has an error pending, then it will add OP_WRITE to the key's ready set and add the key to its selected-key set.
public static final int OP_CONNECT
Suppose that a selection key's interest set contains OP_CONNECT at the start of a selection operation. If the selector detects that the corresponding socket channel is ready to complete its connection sequence, or has an error pending, then it will add OP_CONNECT to the key's ready set and add the key to its selected-key set.
public static final int OP_ACCEPT
Suppose that a selection key's interest set contains OP_ACCEPT at the start of a selection operation. If the selector detects that the corresponding server-socket channel is ready to accept another connection, or has an error pending, then it will add OP_ACCEPT to the key's ready set and add the key to its selected-key set.
Constructor Detail |
---|
protected SelectionKey()
Method Detail |
---|
public abstract SelectableChannel channel()
public abstract Selector selector()
public abstract boolean isValid()
A key is valid upon creation and remains so until it is cancelled, its channel is closed, or its selector is closed.
public abstract void cancel()
If this key has already been cancelled then invoking this method has no effect. Once cancelled, a key remains forever invalid.
This method may be invoked at any time. It synchronizes on the selector's cancelled-key set, and therefore may block briefly if invoked concurrently with a cancellation or selection operation involving the same selector.
public abstract int interestOps()
It is guaranteed that the returned set will only contain operation bits that are valid for this key's channel.
This method may be invoked at any time. Whether or not it blocks, and for how long, is implementation-dependent.
CancelledKeyException
- If this key has been cancelledpublic abstract SelectionKey interestOps(int ops)
This method may be invoked at any time. Whether or not it blocks, and for how long, is implementation-dependent.
ops
- The new interest set
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
CancelledKeyException
- If this key has been cancelledpublic abstract int readyOps()
It is guaranteed that the returned set will only contain operation bits that are valid for this key's channel.
CancelledKeyException
- If this key has been cancelledpublic final boolean isReadable()
An invocation of this method of the form k.isReadable() behaves in exactly the same way as the expression
k.readyOps() & OP_READ != 0
If this key's channel does not support read operations then this method always returns false.
CancelledKeyException
- If this key has been cancelledpublic final boolean isWritable()
An invocation of this method of the form k.isWritable() behaves in exactly the same way as the expression
k.readyOps() & OP_WRITE != 0
If this key's channel does not support write operations then this method always returns false.
CancelledKeyException
- If this key has been cancelledpublic final boolean isConnectable()
An invocation of this method of the form k.isConnectable() behaves in exactly the same way as the expression
k.readyOps() & OP_CONNECT != 0
If this key's channel does not support socket-connect operations then this method always returns false.
CancelledKeyException
- If this key has been cancelledpublic final boolean isAcceptable()
An invocation of this method of the form k.isAcceptable() behaves in exactly the same way as the expression
k.readyOps() & OP_ACCEPT != 0
If this key's channel does not support socket-accept operations then this method always returns false.
CancelledKeyException
- If this key has been cancelledpublic final Object attach(Object ob)
An attached object may later be retrieved via the attachment
method. Only one object may be attached at a time; invoking
this method causes any previous attachment to be discarded. The current
attachment may be discarded by attaching null.
ob
- The object to be attached; may be null
public final Object attachment()