java.lang.Object | |
↳ | java.nio.channels.SelectionKey |
Known Direct Subclasses |
A SelectionKey
represents the relationship between a channel and a
selector for which the channel is registered.
OP_ACCEPT
), connecting with a socket (OP_CONNECT
),
reading (OP_READ
) and writing (OP_WRITE
).
channel
is ready to execute.
Constants | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
int | OP_ACCEPT | Interest set mask bit for socket-accept operations. | |||||||||
int | OP_CONNECT | Interest set mask bit for socket-connect operations. | |||||||||
int | OP_READ | Interesting operation mask bit for read operations. | |||||||||
int | OP_WRITE | Interest set mask bit for write operations. |
Protected Constructors | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Constructs a new
SelectionKey . |
Public Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Attaches an object to this key.
| |||||||||||
Gets the attached object.
| |||||||||||
Cancels this key.
| |||||||||||
Gets the channel of this key.
| |||||||||||
Sets the interest set for this key.
| |||||||||||
Gets this key's interest set.
| |||||||||||
Indicates whether this key's channel is interested in the accept
operation and is ready to accept new connections.
| |||||||||||
Indicates whether this key's channel is interested in the connect
operation and is ready to connect.
| |||||||||||
Indicates whether this key's channel is interested in the read operation
and is ready to read.
| |||||||||||
Indicates whether this key is valid.
| |||||||||||
Indicates whether this key's channel is interested in the write operation
and is ready to write.
| |||||||||||
Gets the set of operations that are ready.
| |||||||||||
Gets the selector for which this key's channel is registered.
|
[Expand]
Inherited Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
From class java.lang.Object
|
Interest set mask bit for socket-accept operations.
Interest set mask bit for socket-connect operations.
Interesting operation mask bit for read operations.
Interest set mask bit for write operations.
Constructs a new SelectionKey
.
Attaches an object to this key. It is acceptable to attach null
,
this discards the old attachment.
anObject | the object to attach, or null to discard the current
attachment. |
---|
null
if no object has been
attached.Gets the attached object.
null
if no object has been
attached.Cancels this key.
A key that has been canceled is no longer valid. Calling this method on an already canceled key does nothing.
Calling this method is safe at any time. The call might block until another ongoing call to a method of this selector has finished. The reason is that it is synchronizing on the key set of the selector. After this call finishes, the key will have been added to the selectors canceled-keys set and will not be included in any future selects of this selector.
Gets the channel of this key.
Sets the interest set for this key.
operations | the new interest set. |
---|
IllegalArgumentException | if a bit in operations is not in the set of
valid operations of this
key's channel. |
---|---|
CancelledKeyException | if the key has already been canceled. |
Gets this key's interest set. The returned set has only those bits set that are valid for this key's channel.
CancelledKeyException | if the key has already been canceled. |
---|
Indicates whether this key's channel is interested in the accept
operation and is ready to accept new connections. A call to this method
is equal to executing (readyOps() & OP_ACCEPT) == OP_ACCEPT
.
true
if the channel is interested in the accept operation
and is ready to accept new connections, false
otherwise.CancelledKeyException | if the key has already been canceled. |
---|
Indicates whether this key's channel is interested in the connect
operation and is ready to connect. A call to this method is equal to
executing (readyOps() & OP_CONNECT) == OP_CONNECT
.
true
if the channel is interested in the connect
operation and is ready to connect, false
otherwise.CancelledKeyException | if the key has already been canceled. |
---|
Indicates whether this key's channel is interested in the read operation
and is ready to read. A call to this method is equal to executing
(readyOps() & OP_READ) == OP_READ
.
true
if the channel is interested in the read operation
and is ready to read, false
otherwise.CancelledKeyException | if the key has already been canceled. |
---|
Indicates whether this key is valid. A key is valid as long as it has not been canceled.
true
if this key has not been canceled, false
otherwise.Indicates whether this key's channel is interested in the write operation
and is ready to write. A call to this method is equal to executing
(readyOps() & OP_WRITE) == OP_WRITE
.
true
if the channel is interested in the wrie operation
and is ready to write, false
otherwise.CancelledKeyException | if the key has already been canceled. |
---|
Gets the set of operations that are ready. The returned set has only those bits set that are valid for this key's channel.
CancelledKeyException | if the key has already been canceled. |
---|
Gets the selector for which this key's channel is registered.