Package org.apache.storm
Class StormTimer
java.lang.Object
org.apache.storm.StormTimer
- All Implemented Interfaces:
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
Modifier and TypeClassDescriptionstatic class
static class
-
Constructor Summary
ConstructorDescriptionStormTimer
(String name, Thread.UncaughtExceptionHandler onKill) Makes a Timer in the form of a StormTimerTask Object. -
Method Summary
Modifier and TypeMethodDescriptionvoid
close()
cancel timer.boolean
is timer waiting.void
void
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.
-
Constructor Details
-
StormTimer
Makes a Timer in the form of a StormTimerTask Object.- Parameters:
name
- name of the timeronKill
- function to call when timer is killed unexpectedly
-
-
Method Details
-
schedule
Schedule a function to be executed in the timer.- Parameters:
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 run
-
schedule
-
scheduleMs
Same as schedule with millisecond resolution.- Parameters:
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 run
-
scheduleMs
-
scheduleRecurring
Schedule a function to run recurrently.- Parameters:
delaySecs
- the number of seconds to delay before running the functionrecurSecs
- the time between each invocationfunc
- the function to run
-
scheduleRecurringMs
Schedule a function to run recurrently.- Parameters:
delayMs
- the number of millis to delay before running the functionrecurMs
- the time between each invocationfunc
- the function to run
-
scheduleRecurringWithJitter
Schedule a function to run recurrently with jitter.- Parameters:
delaySecs
- the number of seconds to delay before running the functionrecurSecs
- the time between each invocationjitterMs
- jitter added to the runfunc
- the function to run
-
close
cancel timer.- Specified by:
close
in interfaceAutoCloseable
- Throws:
InterruptedException
-
isTimerWaiting
public boolean isTimerWaiting()is timer waiting. Used in timer simulation.
-