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 |
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.
|
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 scheduleMs(long delayMs, Runnable func, boolean checkActive, int jitterMs)
Same as schedule with millisecond resolution.
delayMs
- the number of milliseconds to delay before running the functionfunc
- the function to runcheckActive
- whether to check is the timer is activejitterMs
- add jitter to the runpublic void scheduleMs(long delayMs, 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 scheduleRecurringMs(long delayMs, long recurMs, Runnable func)
Schedule a function to run recurrently.
delayMs
- the number of millis to delay before running the functionrecurMs
- 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 InterruptedException
cancel timer.
close
in interface AutoCloseable
InterruptedException
public boolean isTimerWaiting()
is timer waiting. Used in timer simulation.
Copyright © 2019 The Apache Software Foundation. All rights reserved.