public class TimeoutWorker
extends java.lang.Object
implements java.lang.Runnable
Timeout
s required by
the AbstractSelector
. The worker processes
timeouts in an expiration-based FIFO fashion. Every existing Timeout is being
waited upon until either cancelled or expired. If a timeout expires, the
Timeout.expired()
method is called on that timeout.
Every
insertion or removal of Timeouts causes the TimeoutWorker to wake up from
waiting, recalculate the shortest timeout to wait for, and go back to sleep.
The TimeoutWorker
is otherwise waiting for incoming tasks via the
insert(Timeout)
method.
Constructor and Description |
---|
TimeoutWorker() |
Modifier and Type | Method and Description |
---|---|
void |
cancel(Timeout timeout)
Cancel an already waited-on
Timeout . |
void |
insert(Timeout timeout)
Insert a
Timeout that needs to be waited upon. |
boolean |
isRunning()
Check whether the
TimeoutWorker is running. |
void |
run()
The run() method of the
TimeoutWorker . |
void |
setRunning(boolean running)
Set the running status of the
TimeoutWorker . |
public void insert(Timeout timeout)
Timeout
that needs to be waited upon. Every Timeout
insertion causes the TimeoutWorker to wake up from waiting, recalculate
the shortest timeout to wait for, and go back to sleep. This implementation is thread-safe.
timeout
- The Timeout to be waited upon.public void cancel(Timeout timeout)
Timeout
. Every Timeout removal causes
the TimeoutWorker to wake up from waiting, recalculate the shortest
timeout to wait for, and go back to sleep. This implementation is thread-safe.
timeout
- The timeout to cancelpublic boolean isRunning()
TimeoutWorker
is running. This implementation is thread-safe.
public void setRunning(boolean running)
TimeoutWorker
. If the running
status of the worker is set to false, the TimeoutWorker is interrupted
(if waiting for a task) in order to cleanly shutdown. This implementation is thread-safe.
running
- Whether the TaskWorker should runpublic void run()
TimeoutWorker
. Here, every existing
Timeout is being waited upon until either cancelled or expired. If a
timeout expires, the Timeout.expired()
method is called on that
timeout. Every insertion or removal of Timeouts causes the TimeoutWorker to wake up from waiting, recalculate the shortest timeout to wait for, and go back to sleep.
run
in interface java.lang.Runnable