Class Timers
java.lang.Object
zmq.util.Timers
Manages set of timers.
Timers can be added with a given interval, when the interval of time expires after addition, handler method is executed with given arguments.
Timer is repetitive and will be executed over time until canceled.
This is a DRAFT class, and may change without notice.
-
Nested Class Summary
Nested Classes -
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionadd(long interval, Timers.Handler handler, Object... args) Add timer to the set, timer repeats forever, or until cancel is called.booleancancel(Timers.Timer timer) Deprecated.(package private) Iterable<Map.Entry<Timers.Timer, Long>> entries()intexecute()Execute the timers.private booleaninsert(Timers.Timer timer) private longnow()booleanreset(Timers.Timer timer) Deprecated.useTimers.Timer.reset()insteadbooleansetInterval(Timers.Timer timer, long interval) Deprecated.useTimers.Timer.setInterval(long)insteadintlongtimeout()Returns the time in millisecond until the next timer.
-
Field Details
-
timers
-
clock
-
-
Constructor Details
-
Timers
public Timers() -
Timers
-
-
Method Details
-
now
private long now() -
insert
-
add
Add timer to the set, timer repeats forever, or until cancel is called.- Parameters:
interval- the interval of repetition in milliseconds.handler- the callback called at the expiration of the timer.args- the optional arguments for the handler.- Returns:
- an opaque handle for further cancel.
-
setInterval
Deprecated.useTimers.Timer.setInterval(long)insteadChanges the interval of the timer. This method is slow, canceling existing and adding a new timer yield better performance.- Parameters:
timer- the timer to change the interval to.- Returns:
- true if set, otherwise false.
-
reset
Deprecated.useTimers.Timer.reset()insteadReset the timer. This method is slow, canceling existing and adding a new timer yield better performance.- Parameters:
timer- the timer to reset.- Returns:
- true if reset, otherwise false.
-
cancel
Deprecated.useTimers.Timer.cancel()insteadCancel a timer.- Parameters:
timer- the timer to cancel.- Returns:
- true if cancelled, otherwise false.
-
timeout
public long timeout()Returns the time in millisecond until the next timer.- Returns:
- the time in millisecond until the next timer.
-
execute
public int execute()Execute the timers.- Returns:
- the number of timers triggered.
-
entries
Iterable<Map.Entry<Timers.Timer, Long>> entries() -
sleepAndExecute
public int sleepAndExecute()
-
Timers.Timer.cancel()instead