Package org.apache.qpid.proton.reactor
Interface Selector
public interface Selector
A multiplexor of instances of
Selectable
.
Many instances of Selectable
can be added to a selector, and
the select(long)
method used to block the calling thread until
one of the Selectables
becomes read to perform an operation.
This class is not thread safe, so only one thread should be manipulating the
contents of the selector, or running the select(long)
method at
any given time.
-
Method Summary
Modifier and TypeMethodDescriptionvoid
add
(Selectable selectable) Adds a selectable to the selector.error()
expired()
void
free()
Frees the resources used by this selector.readable()
void
remove
(Selectable selectable) Removes a selectable from the selector.void
select
(long timeout) Waits for the specified timeout period for one or more selectables to become ready for an operation.void
update
(Selectable selectable) Updates the selector to reflect any changes interest by the specified selectable.
-
Method Details
-
add
Adds a selectable to the selector.- Parameters:
selectable
-- Throws:
IOException
-
update
Updates the selector to reflect any changes interest by the specified selectable. This is achieved by calling theSelectable.isReading()
andSelectable.isWriting()
methods.- Parameters:
selectable
-
-
remove
Removes a selectable from the selector.- Parameters:
selectable
-
-
select
Waits for the specified timeout period for one or more selectables to become ready for an operation. Selectables that become ready are returned by thereadable()
,writeable()
,expired()
, orerror()
methods.- Parameters:
timeout
- the maximum number of milliseconds to block the calling thread waiting for a selectable to become ready for an operation. The value zero is interpreted as check but don't block.- Throws:
IOException
-
readable
Iterator<Selectable> readable()- Returns:
- the selectables that have become readable since the last call
to
select(long)
. Callingselect
clears any previous values in this set before adding new values corresponding to those selectables that have become readable.
-
writeable
Iterator<Selectable> writeable()- Returns:
- the selectables that have become writable since the last call
to
select(long)
. Callingselect
clears any previous values in this set before adding new values corresponding to those selectables that have become writable.
-
expired
Iterator<Selectable> expired()- Returns:
- the selectables that have expired since the last call
to
select(long)
. Callingselect
clears any previous values in this set before adding new values corresponding to those selectables that have now expired.
-
error
Iterator<Selectable> error()- Returns:
- the selectables that have encountered an error since the last
call to
select(long)
. Callingselect
clears any previous values in this set before adding new values corresponding to those selectables that have encountered an error.
-
free
void free()Frees the resources used by this selector.
-