Package org.apache.storm

## Class StormTimer

- java.lang.Object
- - org.apache.storm.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.

- - ### Nested Class Summary

    Nested Classes
    Modifier and Type | Class | Description
    --- | --- | ---
    `static class` | `StormTimer.QueueEntry` |
    `static class` | `StormTimer.StormTimerTask` |

  - ### Constructor Summary

    Constructors
    Constructor | Description
    --- | ---
    `StormTimer​(String name, Thread.UncaughtExceptionHandler onKill)` | Makes a Timer in the form of a StormTimerTask Object.

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method | Description
    --- | --- | ---
    `void` | `close()` | cancel timer.
    `boolean` | `isTimerWaiting()` | is timer waiting.
    `void` | `schedule​(int delaySecs, Runnable func)` |
    `void` | `schedule​(int delaySecs, Runnable func, boolean checkActive, int jitterMs)` | Schedule a function to be executed in the timer.
    `void` | `scheduleMs​(long delayMs, Runnable func)` |
    `void` | `scheduleMs​(long delayMs, Runnable func, boolean checkActive, int jitterMs)` | Same as schedule with millisecond resolution.
    `void` | `scheduleRecurring​(int delaySecs, int recurSecs, Runnable func)` | Schedule a function to run recurrently.
    `void` | `scheduleRecurringMs​(long delayMs, long recurMs, Runnable func)` | Schedule a function to run recurrently.
    `void` | `scheduleRecurringWithJitter​(int delaySecs, int recurSecs, int jitterMs, Runnable func)` | Schedule a function to run recurrently with jitter.

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### 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

    - #### close

          public void close()
                     throws InterruptedException

      cancel timer.
      Specified by:
        `close` in interface `AutoCloseable`
      Throws:
        `InterruptedException`

    - #### isTimerWaiting

          public boolean isTimerWaiting()

      is timer waiting. Used in timer simulation.