Package io.debezium.util
Interface DelayStrategy
- Functional Interface:
- This is a functional interface and can therefore be used as the assignment target for a lambda expression or method reference.
Encapsulates the logic of determining a delay when some criteria is met.
- Author:
- Randall Hauch
-
Method Summary
Modifier and TypeMethodDescriptionstatic DelayStrategyCreate a delay strategy that applies a constant delay as long as the criteria is met.static DelayStrategyexponential(Duration initialDelay, Duration maxDelay) Create a delay strategy that applies an exponentially-increasing delay as long as the criteria is met.static DelayStrategyexponential(Duration initialDelay, Duration maxDelay, double backOffMultiplier) Create a delay strategy that applies an exponentially-increasing delay as long as the criteria is met.static DelayStrategyCreate a delay strategy that applies an linearly-increasing delay as long as the criteria is met.static DelayStrategynone()Create a delay strategy that never delays.booleansleepWhen(boolean criteria) Attempt to sleep when the specified criteria is met.default booleansleepWhen(BooleanSupplier criteria) Attempt to sleep when the specified criteria is met.
-
Method Details
-
sleepWhen
Attempt to sleep when the specified criteria is met.- Parameters:
criteria-trueif this method should sleep, orfalseif there is no need to sleep- Returns:
trueif this invocation caused the thread to sleep, orfalseif this method did not sleep
-
sleepWhen
boolean sleepWhen(boolean criteria) Attempt to sleep when the specified criteria is met.- Parameters:
criteria-trueif this method should sleep, orfalseif there is no need to sleep- Returns:
trueif this invocation caused the thread to sleep, orfalseif this method did not sleep
-
none
Create a delay strategy that never delays.- Returns:
- the strategy; never null
-
constant
Create a delay strategy that applies a constant delay as long as the criteria is met. As soon as the criteria is not met, the delay resets to zero.- Parameters:
delay- the initial delay; must be positive- Returns:
- the strategy; never null
-
linear
Create a delay strategy that applies an linearly-increasing delay as long as the criteria is met. As soon as the criteria is not met, the delay resets to zero.- Parameters:
delay- the initial delay; must be positive- Returns:
- the strategy; never null
-
exponential
Create a delay strategy that applies an exponentially-increasing delay as long as the criteria is met. As soon as the criteria is not met, the delay resets to zero.- Parameters:
initialDelay- the initial delay; must be positivemaxDelay- the maximum delay; must be greater than the initial delay- Returns:
- the strategy; never null
-
exponential
static DelayStrategy exponential(Duration initialDelay, Duration maxDelay, double backOffMultiplier) Create a delay strategy that applies an exponentially-increasing delay as long as the criteria is met. As soon as the criteria is not met, the delay resets to zero.- Parameters:
initialDelay- the initial delay; must be positivemaxDelay- the maximum delay; must be greater than the initial delaybackOffMultiplier- the factor by which the delay increases each pass- Returns:
- the strategy
-