public interface Selector
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.
Modifier and Type | Method and Description |
---|---|
void |
add(Selectable selectable)
Adds a selectable to the selector.
|
java.util.Iterator<Selectable> |
error() |
java.util.Iterator<Selectable> |
expired() |
void |
free()
Frees the resources used by this selector.
|
java.util.Iterator<Selectable> |
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.
|
java.util.Iterator<Selectable> |
writeable() |
void add(Selectable selectable) throws java.io.IOException
selectable
- java.io.IOException
void update(Selectable selectable)
Selectable.isReading()
and Selectable.isWriting()
methods.selectable
- void remove(Selectable selectable)
selectable
- void select(long timeout) throws java.io.IOException
readable()
, writeable()
,
expired()
, or error()
methods.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.java.io.IOException
java.util.Iterator<Selectable> readable()
select(long)
. Calling select
clears
any previous values in this set before adding new values
corresponding to those selectables that have become readable.java.util.Iterator<Selectable> writeable()
select(long)
. Calling select
clears
any previous values in this set before adding new values
corresponding to those selectables that have become writable.java.util.Iterator<Selectable> expired()
select(long)
. Calling select
clears
any previous values in this set before adding new values
corresponding to those selectables that have now expired.java.util.Iterator<Selectable> error()
select(long)
. Calling select
clears any previous values in this set before adding new values
corresponding to those selectables that have encountered an
error.void free()