Package io.openems.edge.bridge.http.time
Class DelayTimeProviderChain
java.lang.Object
io.openems.edge.bridge.http.time.DelayTimeProviderChain
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic DelayTimeProviderChain
fixedAtEveryFull
(Clock clock, DurationUnit durationUnit) Creates aDelayTimeProviderChain
which returns aDuration
till the next truncated time of the givenDurationUnit
.static DelayTimeProviderChain
fixedDelay
(Duration delay) Creates aDelayTimeProviderChain
which returns a fixedDuration
on request.getDelay()
static DelayTimeProviderChain
Creates aDelayTimeProviderChain
which returns a theDuration
of zero on request.static DelayTimeProviderChain
plusFixedAmount
(DelayTimeProviderChain origin, Duration duration) Creates aDelayTimeProviderChain
which adds to the original provider the given amount.plusFixedAmount
(Duration duration) Helper method to create a newDelayTimeProviderChain
with a fixed amount added.plusRandomDelay
(int bound, TemporalUnit unit) Helper method to create a newDelayTimeProviderChain
with a random amount added between 0 (inclusive) and the bound (exclusive).static DelayTimeProviderChain
plusRandomDelay
(DelayTimeProviderChain origin, int bound, TemporalUnit unit) Creates aDelayTimeProviderChain
which adds to the original provider a random amount between 0 (inclusive) and bound (exclusive).
-
Constructor Details
-
DelayTimeProviderChain
-
-
Method Details
-
immediate
Creates aDelayTimeProviderChain
which returns a theDuration
of zero on request.- Returns:
- a
DelayTimeProviderChain
of zero delay
-
fixedDelay
Creates aDelayTimeProviderChain
which returns a fixedDuration
on request.- Parameters:
delay
- theDuration
to return when requested- Returns:
- a
DelayTimeProviderChain
of the givenDuration
-
fixedAtEveryFull
Creates aDelayTimeProviderChain
which returns aDuration
till the next truncated time of the givenDurationUnit
.e. g. if a
DurationUnit.ofMinutes(1)
gets provided theDuration
at the time 12h 43min 23sec would be (60sec - 23sec) = 37sec to 12h 44min 0sec. Same would work for every hour 12h, 13h, 14h, ... withDurationUnit.ofHours(1)
- Parameters:
clock
- theClock
to get the current timedurationUnit
- theDurationUnit
to truncate with- Returns:
- a
DelayTimeProviderChain
which returns theDuration
-
getDelay
-
plusFixedAmount
public static DelayTimeProviderChain plusFixedAmount(DelayTimeProviderChain origin, Duration duration) Creates aDelayTimeProviderChain
which adds to the original provider the given amount. The new providedDuration
gets rounded to seconds based on the implementation ofinvalid reference
Delay#plus(Delay)
- Parameters:
origin
- the originalDelayTimeProviderChain
to get the initialDuration
duration
- theDuration
to add- Returns:
- a
DelayTimeProviderChain
which returns theDuration
of the originalDelayTimeProviderChain
with the added amount
-
plusFixedAmount
Helper method to create a newDelayTimeProviderChain
with a fixed amount added.- Parameters:
duration
- theDuration
to add- Returns:
- a
DelayTimeProviderChain
which returns theDuration
of the originalDelayTimeProviderChain
with the added amount - See Also:
-
plusRandomDelay
public static DelayTimeProviderChain plusRandomDelay(DelayTimeProviderChain origin, int bound, TemporalUnit unit) Creates aDelayTimeProviderChain
which adds to the original provider a random amount between 0 (inclusive) and bound (exclusive). The new providedDuration
gets rounded to seconds based on the implementation ofinvalid reference
Delay#plus(Delay)
- Parameters:
origin
- the originalDelayTimeProviderChain
to get the initialDuration
bound
- the upper bound (exclusive). Must be positive.unit
- theTemporalUnit
of the amount to add- Returns:
- a
DelayTimeProviderChain
which returns theDuration
of the originalDelayTimeProviderChain
with the added amount
-
plusRandomDelay
Helper method to create a newDelayTimeProviderChain
with a random amount added between 0 (inclusive) and the bound (exclusive).- Parameters:
bound
- the upper bound (exclusive). Must be positive.unit
- theTemporalUnit
of the amount to add- Returns:
- a
DelayTimeProviderChain
which returns theDuration
of the originalDelayTimeProviderChain
with the added amount - See Also:
-