@NotThreadSafe public class SleepingTimer extends Object implements HeartbeatTimer
Modifier and Type | Field and Description |
---|---|
protected java.time.Clock |
mClock |
protected SleepIntervalSupplier |
mIntervalSupplier |
protected java.util.function.Supplier<SleepIntervalSupplier> |
mIntervalSupplierSupplier |
protected org.slf4j.Logger |
mLogger |
protected long |
mPreviousTickedMs |
protected Sleeper |
mSleeper |
Constructor and Description |
---|
SleepingTimer(String threadName,
java.time.Clock clock,
java.util.function.Supplier<SleepIntervalSupplier> intervalSupplierSupplier)
Creates a new instance of
SleepingTimer . |
SleepingTimer(String threadName,
org.slf4j.Logger logger,
java.time.Clock clock,
Sleeper sleeper,
java.util.function.Supplier<SleepIntervalSupplier> intervalSupplierSupplier)
Creates a new instance of
SleepingTimer . |
Modifier and Type | Method and Description |
---|---|
long |
tick()
Enforces the thread waits for the given interval between consecutive ticks.
|
void |
update()
When this object needs to be reconfigured
due to external configuration change etc.,
this function will be invoked.
|
protected long mPreviousTickedMs
protected final org.slf4j.Logger mLogger
protected final java.time.Clock mClock
protected final Sleeper mSleeper
protected final java.util.function.Supplier<SleepIntervalSupplier> mIntervalSupplierSupplier
protected volatile SleepIntervalSupplier mIntervalSupplier
public SleepingTimer(String threadName, java.time.Clock clock, java.util.function.Supplier<SleepIntervalSupplier> intervalSupplierSupplier)
SleepingTimer
.threadName
- the thread nameclock
- for telling the current timeintervalSupplierSupplier
- Sleep time between different heartbeat supplierpublic SleepingTimer(String threadName, org.slf4j.Logger logger, java.time.Clock clock, Sleeper sleeper, java.util.function.Supplier<SleepIntervalSupplier> intervalSupplierSupplier)
SleepingTimer
.threadName
- the thread namelogger
- the logger to log toclock
- for telling the current timesleeper
- the utility to use for sleepingintervalSupplierSupplier
- Sleep time between different heartbeat supplierpublic long tick() throws InterruptedException
tick
in interface HeartbeatTimer
InterruptedException
- if the thread is interrupted while waitingpublic void update()
HeartbeatTimer
update
in interface Reconfigurable
update
in interface HeartbeatTimer
Copyright © 2023. All Rights Reserved.