public final class Timers
extends java.lang.Object
Modifier and Type | Class and Description |
---|---|
static interface |
Timers.Handler |
static class |
Timers.Timer |
Modifier and Type | Field and Description |
---|---|
private Supplier<java.lang.Long> |
clock |
private MultiMap<java.lang.Long,Timers.Timer> |
timers |
Constructor and Description |
---|
Timers() |
Timers(Supplier<java.lang.Long> clock)
Builds a new timer.
|
Modifier and Type | Method and Description |
---|---|
Timers.Timer |
add(long interval,
Timers.Handler handler,
java.lang.Object... args)
Add timer to the set, timer repeats forever, or until cancel is called.
|
boolean |
cancel(Timers.Timer timer)
Deprecated.
use
Timers.Timer.cancel() instead |
(package private) java.lang.Iterable<java.util.Map.Entry<Timers.Timer,java.lang.Long>> |
entries() |
int |
execute()
Execute the timers.
|
private boolean |
insert(Timers.Timer timer) |
private long |
now() |
boolean |
reset(Timers.Timer timer)
Deprecated.
use
Timers.Timer.reset() instead |
boolean |
setInterval(Timers.Timer timer,
long interval)
Deprecated.
use
Timers.Timer.setInterval(long) instead |
int |
sleepAndExecute() |
long |
timeout()
Returns the time in millisecond until the next timer.
|
private final MultiMap<java.lang.Long,Timers.Timer> timers
private final Supplier<java.lang.Long> clock
public Timers()
public Timers(Supplier<java.lang.Long> clock)
This constructor is for testing and is not intended to be used in production code.
clock
- the supplier of the current time in milliseconds.private long now()
private boolean insert(Timers.Timer timer)
public Timers.Timer add(long interval, Timers.Handler handler, java.lang.Object... args)
interval
- the interval of repetition in milliseconds.handler
- the callback called at the expiration of the timer.args
- the optional arguments for the handler.@Deprecated public boolean setInterval(Timers.Timer timer, long interval)
Timers.Timer.setInterval(long)
insteadtimer
- the timer to change the interval to.@Deprecated public boolean reset(Timers.Timer timer)
Timers.Timer.reset()
insteadtimer
- the timer to reset.@Deprecated public boolean cancel(Timers.Timer timer)
Timers.Timer.cancel()
insteadtimer
- the timer to cancel.public long timeout()
public int execute()
java.lang.Iterable<java.util.Map.Entry<Timers.Timer,java.lang.Long>> entries()
public int sleepAndExecute()