Package org.zeromq.timer
Class ZTicket
java.lang.Object
org.zeromq.timer.ZTicket
Manages set of tickets.
Ticket timers are very fast in the case where you use a lot of timers (thousands), and frequently remove and add them. The main use case is expiry timers for servers that handle many clients, and which reset the expiry timer for each message received from a client. Whereas normal timers perform poorly as the number of clients grows, the cost of ticket timers is constant, no matter the number of clients
Tickets can be added with a given delay.
When the delay of time expires after addition, handler method is executed with given arguments.
Ticket is NOT repetitive and will be executed once unless canceled.
This class is not thread-safe
This is a DRAFT class, and may change without notice.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final class
Opaque representation of a ticket. -
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionadd
(long delay, TimerHandler handler, Object... args) Add ticket to the set.int
execute()
Execute the tickets.private void
insert
(ZTicket.Ticket ticket) private long
now()
private void
long
timeout()
Returns the time in millisecond until the next ticket.
-
Field Details
-
tickets
-
clock
-
sort
private boolean sort
-
-
Constructor Details
-
ZTicket
public ZTicket() -
ZTicket
-
ZTicket
ZTicket(Supplier<Long> clock, List<ZTicket.Ticket> tickets)
-
-
Method Details
-
now
private long now() -
insert
-
add
Add ticket to the set.- Parameters:
delay
- the expiration delay in milliseconds.handler
- the callback called at the expiration of the ticket.args
- the optional arguments for the handler.- Returns:
- an opaque handle for further cancel and reset.
-
timeout
public long timeout()Returns the time in millisecond until the next ticket.- Returns:
- the time in millisecond until the next ticket.
-
execute
public int execute()Execute the tickets.- Returns:
- the number of tickets triggered.
-
sortIfNeeded
private void sortIfNeeded()
-