Class StormTimer

  • All Implemented Interfaces:
    AutoCloseable

    public class StormTimer
    extends Object
    implements AutoCloseable
    The timer defined in this file is very similar to java.util.Timer, except it integrates with Storm's time simulation capabilities. This lets us test code that does asynchronous work on the timer thread.
    • Constructor Detail

      • StormTimer

        public StormTimer​(String name,
                          Thread.UncaughtExceptionHandler onKill)
        Makes a Timer in the form of a StormTimerTask Object.
        Parameters:
        name - name of the timer
        onKill - function to call when timer is killed unexpectedly
    • Method Detail

      • schedule

        public void schedule​(int delaySecs,
                             Runnable func,
                             boolean checkActive,
                             int jitterMs)
        Schedule a function to be executed in the timer.
        Parameters:
        delaySecs - the number of seconds to delay before running the function
        func - the function to run
        checkActive - whether to check is the timer is active
        jitterMs - add jitter to the run
      • schedule

        public void schedule​(int delaySecs,
                             Runnable func)
      • scheduleMs

        public void scheduleMs​(long delayMs,
                               Runnable func,
                               boolean checkActive,
                               int jitterMs)
        Same as schedule with millisecond resolution.
        Parameters:
        delayMs - the number of milliseconds to delay before running the function
        func - the function to run
        checkActive - whether to check is the timer is active
        jitterMs - add jitter to the run
      • scheduleMs

        public void scheduleMs​(long delayMs,
                               Runnable func)
      • scheduleRecurring

        public void scheduleRecurring​(int delaySecs,
                                      int recurSecs,
                                      Runnable func)
        Schedule a function to run recurrently.
        Parameters:
        delaySecs - the number of seconds to delay before running the function
        recurSecs - the time between each invocation
        func - the function to run
      • scheduleRecurringMs

        public void scheduleRecurringMs​(long delayMs,
                                        long recurMs,
                                        Runnable func)
        Schedule a function to run recurrently.
        Parameters:
        delayMs - the number of millis to delay before running the function
        recurMs - the time between each invocation
        func - the function to run
      • scheduleRecurringWithJitter

        public void scheduleRecurringWithJitter​(int delaySecs,
                                                int recurSecs,
                                                int jitterMs,
                                                Runnable func)
        Schedule a function to run recurrently with jitter.
        Parameters:
        delaySecs - the number of seconds to delay before running the function
        recurSecs - the time between each invocation
        jitterMs - jitter added to the run
        func - the function to run
      • isTimerWaiting

        public boolean isTimerWaiting()
        is timer waiting. Used in timer simulation.