Fields Summary |
---|
public static final int | OP_READOperation-set bit for read operations.
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_WRITEOperation-set bit for write operations.
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_CONNECTOperation-set bit for socket-connect operations.
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_ACCEPTOperation-set bit for socket-accept operations.
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. |
private volatile Object | attachment |
Methods Summary |
---|
public final java.lang.Object | attach(java.lang.Object ob)Attaches the given object to this key.
An attached object may later be retrieved via the {@link #attachment()
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.
Object a = attachment;
attachment = ob;
return a;
|
public final java.lang.Object | attachment()Retrieves the current attachment.
return attachment;
|
public abstract void | cancel()Requests that the registration of this key's channel with its selector
be cancelled. Upon return the key will be invalid and will have been
added to its selector's cancelled-key set. The key will be removed from
all of the selector's key sets during the next selection operation.
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 java.nio.channels.SelectableChannel | channel()Returns the channel for which this key was created. This method will
continue to return the channel even after the key is cancelled.
|
public abstract int | interestOps()Retrieves this key's interest set.
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.
|
public abstract java.nio.channels.SelectionKey | interestOps(int ops)Sets this key's interest set to the given value.
This method may be invoked at any time. Whether or not it blocks,
and for how long, is implementation-dependent.
|
public final boolean | isAcceptable()Tests whether this key's channel is ready to accept a new socket
connection.
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.
return (readyOps() & OP_ACCEPT) != 0;
|
public final boolean | isConnectable()Tests whether this key's channel has either finished, or failed to
finish, its socket-connection operation.
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.
return (readyOps() & OP_CONNECT) != 0;
|
public final boolean | isReadable()Tests whether this key's channel is ready for reading.
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.
return (readyOps() & OP_READ) != 0;
|
public abstract boolean | isValid()Tells whether or not this key is valid.
A key is valid upon creation and remains so until it is cancelled,
its channel is closed, or its selector is closed.
|
public final boolean | isWritable()Tests whether this key's channel is ready for writing.
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.
return (readyOps() & OP_WRITE) != 0;
|
public abstract int | readyOps()Retrieves this key's ready-operation set.
It is guaranteed that the returned set will only contain operation
bits that are valid for this key's channel.
|
public abstract java.nio.channels.Selector | selector()Returns the selector for which this key was created. This method will
continue to return the selector even after the key is cancelled.
|