Class ZTicket

java.lang.Object
org.zeromq.timer.ZTicket

public final class ZTicket extends Object
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.

  • Field Details

  • Constructor Details

  • Method Details

    • now

      private long now()
    • insert

      private void insert(ZTicket.Ticket ticket)
    • add

      public ZTicket.Ticket add(long delay, TimerHandler handler, Object... args)
      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()