public interface Selectable extends ReactorChild, Extendable
Selector
.
Every selectable is associated with exactly one SelectableChannel
.
Selectables may be interested in three kinds of events: read events, write
events, and timer events. A selectable will express its interest in these
events through the isReading()
, isWriting()
, and
getDeadline()
methods.
When a read, write, or timer event occurs, the selectable must be notified by
calling readable()
, writeable()
, or expired()
as
appropriate.
Once a selectable reaches a terminal state (see isTerminal()
, it
will never be interested in events of any kind. When this occurs it should be
removed from the Selector and discarded using free()
.
Modifier and Type | Interface and Description |
---|---|
static interface |
Selectable.Callback
A callback that can be passed to the various "on" methods of the
selectable - to allow code to be run when the selectable becomes ready
for the associated operation.
|
Modifier and Type | Method and Description |
---|---|
void |
error()
Notify the selectable that an error has occurred.
|
void |
expired()
Notify the selectable that it has expired.
|
void |
free()
Notify the selectable that it has been free'd.
|
java.nio.channels.SelectableChannel |
getChannel() |
long |
getDeadline() |
Reactor |
getReactor() |
boolean |
isReading() |
boolean |
isRegistered()
Check if a selectable is registered.
|
boolean |
isTerminal() |
boolean |
isWriting() |
void |
onError(Selectable.Callback runnable)
Registers a callback that will be run when the selectable is notified of
an error.
|
void |
onExpired(Selectable.Callback runnable)
Registers a callback that will be run when the selectable expires.
|
void |
onFree(Selectable.Callback runnable)
Registers a callback that will be run when the selectable is notified
that it has been free'd.
|
void |
onReadable(Selectable.Callback runnable)
Registers a callback that will be run when the selectable becomes ready
for reading.
|
void |
onRelease(Selectable.Callback runnable)
Registers a callback that will be run when the selectable is notified
that it has been released.
|
void |
onWritable(Selectable.Callback runnable)
Registers a callback that will be run when the selectable becomes ready
for writing.
|
void |
readable()
Notify the selectable that the underlying
SelectableChannel is
ready for a read operation. |
void |
release()
Notify the selectable that it has been released.
|
void |
setChannel(java.nio.channels.SelectableChannel channel)
Associates a
SelectableChannel with this selector. |
void |
setCollector(Collector collector)
Configure a selectable with a set of callbacks that emit readable,
writable, and expired events into the supplied collector.
|
void |
setDeadline(long deadline)
Sets the value that will be returned by
getDeadline() . |
void |
setReading(boolean reading)
Sets the value that will be returned by
isReading() . |
void |
setRegistered(boolean registered)
Set the registered flag for a selectable.
|
void |
setWriting(boolean writing)
Sets the value that will be returned by
isWriting() . |
void |
terminate()
Terminates the selectable.
|
void |
writeable()
Notify the selectable that the underlying
SelectableChannel is
ready for a write operation. |
attachments
boolean isReading()
true
if the selectable is interested in receiving
notification (via the readable()
method that indicate
that the associated SelectableChannel
has data ready
to be read from it.boolean isWriting()
true
if the selectable is interested in receiving
notifications (via the writeable()
method that indicate
that the associated SelectableChannel
is ready to be
written to.long getDeadline()
expired()
method that indicates
that the deadline has past. The deadline is expressed in the
same format as System.currentTimeMillis()
. Returning
a deadline of zero (or a negative number) indicates that the
selectable does not wish to be notified of expiry.void setReading(boolean reading)
isReading()
.reading
- void setWriting(boolean writing)
isWriting()
.writing
- void setDeadline(long deadline)
getDeadline()
.deadline
- void onReadable(Selectable.Callback runnable)
runnable
- the callback to register. Any previously registered
callback will be replaced.void onWritable(Selectable.Callback runnable)
runnable
- the callback to register. Any previously registered
callback will be replaced.void onExpired(Selectable.Callback runnable)
runnable
- the callback to register. Any previously registered
callback will be replaced.void onError(Selectable.Callback runnable)
runnable
- the callback to register. Any previously registered
callback will be replaced.void onRelease(Selectable.Callback runnable)
runnable
- the callback to register. Any previously registered
callback will be replaced.void onFree(Selectable.Callback runnable)
runnable
- the callback to register. Any previously registered
callback will be replaced.void readable()
SelectableChannel
is
ready for a read operation.void writeable()
SelectableChannel
is
ready for a write operation.void expired()
void error()
void release()
void free()
free
in interface ReactorChild
void setChannel(java.nio.channels.SelectableChannel channel)
SelectableChannel
with this selector.channel
- java.nio.channels.SelectableChannel getChannel()
SelectableChannel
associated with this selector.boolean isRegistered()
Note: the reactor code, currently, does not use this flag.
true
if the selectable is registered.void setRegistered(boolean registered)
Note: the reactor code, currently, does not use this flag.
registered
- the value returned by isRegistered()
void setCollector(Collector collector)
collector
- Reactor getReactor()
void terminate()
boolean isTerminal()
true
if the selectable has reached a terminal state.