Interface Selectable
- All Superinterfaces:
Extendable
,ReactorChild
- All Known Implementing Classes:
SelectableImpl
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()
.
-
Nested Class Summary
Nested ClassesModifier and TypeInterfaceDescriptionstatic interface
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. -
Method Summary
Modifier and TypeMethodDescriptionvoid
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.long
boolean
boolean
Check if a selectable is registered.boolean
boolean
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 underlyingSelectableChannel
is ready for a read operation.void
release()
Notify the selectable that it has been released.void
setChannel
(SelectableChannel channel) Associates aSelectableChannel
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 bygetDeadline()
.void
setReading
(boolean reading) Sets the value that will be returned byisReading()
.void
setRegistered
(boolean registered) Set the registered flag for a selectable.void
setWriting
(boolean writing) Sets the value that will be returned byisWriting()
.void
Terminates the selectable.void
Notify the selectable that the underlyingSelectableChannel
is ready for a write operation.Methods inherited from interface org.apache.qpid.proton.engine.Extendable
attachments
-
Method Details
-
isReading
boolean isReading()- Returns:
true
if the selectable is interested in receiving notification (via thereadable()
method that indicate that the associatedSelectableChannel
has data ready to be read from it.
-
isWriting
boolean isWriting()- Returns:
true
if the selectable is interested in receiving notifications (via thewriteable()
method that indicate that the associatedSelectableChannel
is ready to be written to.
-
getDeadline
long getDeadline()- Returns:
- a deadline after which this selectable can expect to receive
a notification (via the
expired()
method that indicates that the deadline has past. The deadline is expressed in the same format asSystem.currentTimeMillis()
. Returning a deadline of zero (or a negative number) indicates that the selectable does not wish to be notified of expiry.
-
setReading
void setReading(boolean reading) Sets the value that will be returned byisReading()
.- Parameters:
reading
-
-
setWriting
void setWriting(boolean writing) Sets the value that will be returned byisWriting()
.- Parameters:
writing
-
-
setDeadline
void setDeadline(long deadline) Sets the value that will be returned bygetDeadline()
.- Parameters:
deadline
-
-
onReadable
Registers a callback that will be run when the selectable becomes ready for reading.- Parameters:
runnable
- the callback to register. Any previously registered callback will be replaced.
-
onWritable
Registers a callback that will be run when the selectable becomes ready for writing.- Parameters:
runnable
- the callback to register. Any previously registered callback will be replaced.
-
onExpired
Registers a callback that will be run when the selectable expires.- Parameters:
runnable
- the callback to register. Any previously registered callback will be replaced.
-
onError
Registers a callback that will be run when the selectable is notified of an error.- Parameters:
runnable
- the callback to register. Any previously registered callback will be replaced.
-
onRelease
Registers a callback that will be run when the selectable is notified that it has been released.- Parameters:
runnable
- the callback to register. Any previously registered callback will be replaced.
-
onFree
Registers a callback that will be run when the selectable is notified that it has been free'd.- Parameters:
runnable
- the callback to register. Any previously registered callback will be replaced.
-
readable
void readable()Notify the selectable that the underlyingSelectableChannel
is ready for a read operation. -
writeable
void writeable()Notify the selectable that the underlyingSelectableChannel
is ready for a write operation. -
expired
void expired()Notify the selectable that it has expired. -
error
void error()Notify the selectable that an error has occurred. -
release
void release()Notify the selectable that it has been released. -
free
void free()Notify the selectable that it has been free'd.- Specified by:
free
in interfaceReactorChild
-
setChannel
Associates aSelectableChannel
with this selector.- Parameters:
channel
-
-
getChannel
SelectableChannel getChannel()- Returns:
- the
SelectableChannel
associated with this selector.
-
isRegistered
boolean isRegistered()Check if a selectable is registered. This can be used for tracking whether a given selectable has been registerd with an external event loop.Note: the reactor code, currently, does not use this flag.
- Returns:
true
if the selectable is registered.
-
setRegistered
void setRegistered(boolean registered) Set the registered flag for a selectable.Note: the reactor code, currently, does not use this flag.
- Parameters:
registered
- the value returned byisRegistered()
-
setCollector
Configure a selectable with a set of callbacks that emit readable, writable, and expired events into the supplied collector.- Parameters:
collector
-
-
getReactor
Reactor getReactor()- Returns:
- the reactor to which this selectable is a child.
-
terminate
void terminate()Terminates the selectable. Once a selectable reaches a terminal state it will never be interested in events of any kind. -
isTerminal
boolean isTerminal()- Returns:
true
if the selectable has reached a terminal state.
-