Class ZTimer


  • public final class ZTimer
    extends java.lang.Object
    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 
      Modifier and Type Class Description
      static class  ZTimer.Timer
      Opaque representation of a timer.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private Timers timer  
    • Constructor Summary

      Constructors 
      Constructor Description
      ZTimer()  
      ZTimer​(Supplier<java.lang.Long> clock)  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      ZTimer.Timer add​(long interval, TimerHandler handler, java.lang.Object... args)
      Add timer to the set, timer repeats forever, or until cancel is called.
      int execute()
      Execute the timers.
      int sleepAndExecute()
      Sleeps until at least one timer can be executed and execute the timers.
      long timeout()
      Returns the time in millisecond until the next timer.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • timer

        private final Timers timer
    • Constructor Detail

      • ZTimer

        public ZTimer()
      • ZTimer

        ZTimer​(Supplier<java.lang.Long> clock)
    • Method Detail

      • add

        public ZTimer.Timer add​(long interval,
                                TimerHandler handler,
                                java.lang.Object... args)
        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.
      • 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.
      • sleepAndExecute

        public int sleepAndExecute()
        Sleeps until at least one timer can be executed and execute the timers.
        Returns:
        the number of timers triggered.