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
Modifier and Type | Class and Description |
---|---|
static class |
StormTimer.QueueEntry |
static class |
StormTimer.StormTimerTask |
Constructor and Description |
---|
StormTimer(String name,
Thread.UncaughtExceptionHandler onKill)
Makes a Timer in the form of a StormTimerTask Object
|
Modifier and Type | Method and 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 |
scheduleRecurring(int delaySecs,
int recurSecs,
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
|
public StormTimer(String name, Thread.UncaughtExceptionHandler onKill)
Makes a Timer in the form of a StormTimerTask Object
name
- name of the timeronKill
- function to call when timer is killed unexpectedlypublic void schedule(int delaySecs, Runnable func, boolean checkActive, int jitterMs)
Schedule a function to be executed in the timer
delaySecs
- the number of seconds to delay before running the functionfunc
- the function to runcheckActive
- whether to check is the timer is activejitterMs
- add jitter to the runpublic void schedule(int delaySecs, Runnable func)
public void scheduleRecurring(int delaySecs, int recurSecs, Runnable func)
Schedule a function to run recurrently
delaySecs
- the number of seconds to delay before running the functionrecurSecs
- the time between each invocationfunc
- the function to runpublic void scheduleRecurringWithJitter(int delaySecs, int recurSecs, int jitterMs, Runnable func)
schedule a function to run recurrently with jitter
delaySecs
- the number of seconds to delay before running the functionrecurSecs
- the time between each invocationjitterMs
- jitter added to the runfunc
- the function to runpublic void close() throws Exception
cancel timer
close
in interface AutoCloseable
Exception
public boolean isTimerWaiting()
is timer waiting. Used in timer simulation
Copyright © 2022 The Apache Software Foundation. All Rights Reserved.