Interface Selectable
-
- All Superinterfaces:
Extendable,ReactorChild
- All Known Implementing Classes:
SelectableImpl
public interface Selectable extends ReactorChild, Extendable
An entity that can be multiplexed using aSelector.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 theisReading(),isWriting(), andgetDeadline()methods.When a read, write, or timer event occurs, the selectable must be notified by calling
readable(),writeable(), orexpired()as appropriate. Once a selectable reaches a terminal state (seeisTerminal(), it will never be interested in events of any kind. When this occurs it should be removed from the Selector and discarded usingfree().
-
-
Nested Class Summary
Nested Classes Modifier and Type Interface Description static interfaceSelectable.CallbackA 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
All Methods Instance Methods Abstract Methods Modifier and Type Method Description voiderror()Notify the selectable that an error has occurred.voidexpired()Notify the selectable that it has expired.voidfree()Notify the selectable that it has been free'd.java.nio.channels.SelectableChannelgetChannel()longgetDeadline()ReactorgetReactor()booleanisReading()booleanisRegistered()Check if a selectable is registered.booleanisTerminal()booleanisWriting()voidonError(Selectable.Callback runnable)Registers a callback that will be run when the selectable is notified of an error.voidonExpired(Selectable.Callback runnable)Registers a callback that will be run when the selectable expires.voidonFree(Selectable.Callback runnable)Registers a callback that will be run when the selectable is notified that it has been free'd.voidonReadable(Selectable.Callback runnable)Registers a callback that will be run when the selectable becomes ready for reading.voidonRelease(Selectable.Callback runnable)Registers a callback that will be run when the selectable is notified that it has been released.voidonWritable(Selectable.Callback runnable)Registers a callback that will be run when the selectable becomes ready for writing.voidreadable()Notify the selectable that the underlyingSelectableChannelis ready for a read operation.voidrelease()Notify the selectable that it has been released.voidsetChannel(java.nio.channels.SelectableChannel channel)Associates aSelectableChannelwith this selector.voidsetCollector(Collector collector)Configure a selectable with a set of callbacks that emit readable, writable, and expired events into the supplied collector.voidsetDeadline(long deadline)Sets the value that will be returned bygetDeadline().voidsetReading(boolean reading)Sets the value that will be returned byisReading().voidsetRegistered(boolean registered)Set the registered flag for a selectable.voidsetWriting(boolean writing)Sets the value that will be returned byisWriting().voidterminate()Terminates the selectable.voidwriteable()Notify the selectable that the underlyingSelectableChannelis ready for a write operation.-
Methods inherited from interface org.apache.qpid.proton.engine.Extendable
attachments
-
-
-
-
Method Detail
-
isReading
boolean isReading()
- Returns:
trueif the selectable is interested in receiving notification (via thereadable()method that indicate that the associatedSelectableChannelhas data ready to be read from it.
-
isWriting
boolean isWriting()
- Returns:
trueif the selectable is interested in receiving notifications (via thewriteable()method that indicate that the associatedSelectableChannelis 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
void onReadable(Selectable.Callback runnable)
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
void onWritable(Selectable.Callback runnable)
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
void onExpired(Selectable.Callback runnable)
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
void onError(Selectable.Callback runnable)
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
void onRelease(Selectable.Callback runnable)
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
void onFree(Selectable.Callback runnable)
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 underlyingSelectableChannelis ready for a read operation.
-
writeable
void writeable()
Notify the selectable that the underlyingSelectableChannelis 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:
freein interfaceReactorChild
-
setChannel
void setChannel(java.nio.channels.SelectableChannel channel)
Associates aSelectableChannelwith this selector.- Parameters:
channel-
-
getChannel
java.nio.channels.SelectableChannel getChannel()
- Returns:
- the
SelectableChannelassociated 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:
trueif 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
void setCollector(Collector collector)
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:
trueif the selectable has reached a terminal state.
-
-