public final class RepeatSpec extends java.lang.Object implements java.util.function.Function<Flux<java.lang.Long>,Publisher<?>>
Flux.repeatWhen(java.util.function.Function<reactor.core.publisher.Flux<java.lang.Long>, ? extends org.reactivestreams.Publisher<?>>)
and
Mono.repeatWhen(java.util.function.Function<reactor.core.publisher.Flux<java.lang.Long>, ? extends org.reactivestreams.Publisher<?>>)
. This includes limiting the number of repeats, applying delays,
using custom predicates, attaching hooks, and applying jitter.
Use static factory methods such as times(long)
to start building a RepeatSpec
.
The builder is immutable and supports a fluent copy-on-write style, so intermediate configurations can be safely reused.
Additional configuration includes:
onlyIf(Predicate)
doBeforeRepeat(java.util.function.Consumer<reactor.util.repeat.RepeatSpec.RepeatSignal>)
and doAfterRepeat(java.util.function.Consumer<reactor.util.repeat.RepeatSpec.RepeatSignal>)
withFixedDelay(Duration)
, jitter(double)
, and withScheduler(Scheduler)
withRepeatContext(ContextView)
The companion Flux<Long>
represents repeat signals, and each value corresponds to a repeat attempt.
This class transforms the repeat signals into a Publisher
that determines whether to trigger a repeat.
Modifier and Type | Class and Description |
---|---|
static interface |
RepeatSpec.RepeatSignal
State information associated with each repeat signal, used in repeat strategies.
|
Modifier and Type | Method and Description |
---|---|
Publisher<?> |
apply(Flux<java.lang.Long> signals) |
static RepeatSpec |
create(java.util.function.Predicate<RepeatSpec.RepeatSignal> predicate,
long n)
Creates a
RepeatSpec that repeats n times, only if the predicate returns true. |
RepeatSpec |
doAfterRepeat(java.util.function.Consumer<RepeatSpec.RepeatSignal> doAfterRepeat)
Adds a synchronous doAfterRepeat to be executed after the repeat trigger has completed.
|
RepeatSpec |
doBeforeRepeat(java.util.function.Consumer<RepeatSpec.RepeatSignal> doBeforeRepeat)
Adds a synchronous doBeforeRepeat to be executed before the repeat trigger.
|
Publisher<java.lang.Long> |
generateCompanion(Flux<java.lang.Long> signals)
Generates the companion publisher responsible for reacting to incoming repeat signals,
effectively deciding whether to trigger another repeat cycle.
|
RepeatSpec |
jitter(double jitter)
Applies jitter to the configured fixed delay.
|
static RepeatSpec |
once()
Creates a
RepeatSpec that repeats once. |
RepeatSpec |
onlyIf(java.util.function.Predicate<RepeatSpec.RepeatSignal> predicate)
Sets a predicate that determines whether a repeat should occur based on the current
RepeatSpec.RepeatSignal . |
static RepeatSpec |
times(long n)
Creates a
RepeatSpec that repeats n times. |
RepeatSpec |
withFixedDelay(java.time.Duration delay)
Applies a fixed delay between repeat iterations.
|
RepeatSpec |
withRepeatContext(ContextView repeatContext)
Set the user provided
contextView that can be used to
manipulate state on retries. |
RepeatSpec |
withScheduler(Scheduler scheduler)
Sets a
Scheduler to use for delaying repeat attempts. |
public static RepeatSpec once()
RepeatSpec
that repeats once.RepeatSpec
instancepublic static RepeatSpec times(long n)
RepeatSpec
that repeats n times.n
- number of repeatsRepeatSpec
instancepublic static RepeatSpec create(java.util.function.Predicate<RepeatSpec.RepeatSignal> predicate, long n)
RepeatSpec
that repeats n times, only if the predicate returns true.predicate
- Predicate that determines if next repeat is performedn
- number of repeatsRepeatSpec
instancepublic RepeatSpec withRepeatContext(ContextView repeatContext)
contextView
that can be used to
manipulate state on retries.repeatContext
- a new snapshot of user provided dataRepeatSpec
which can either be further
configured.public RepeatSpec onlyIf(java.util.function.Predicate<RepeatSpec.RepeatSignal> predicate)
RepeatSpec.RepeatSignal
.
This allows conditional repetition based on iteration count, companion value, delay, or context.predicate
- the condition to test for each RepeatSpec.RepeatSignal
RepeatSpec
with the updated predicatepublic RepeatSpec doBeforeRepeat(java.util.function.Consumer<RepeatSpec.RepeatSignal> doBeforeRepeat)
doBeforeRepeat
- the Consumer
to invoke with the current RepeatSpec.RepeatSignal
RepeatSpec
with the doBeforeRepeat appliedpublic RepeatSpec doAfterRepeat(java.util.function.Consumer<RepeatSpec.RepeatSignal> doAfterRepeat)
doAfterRepeat
- the Consumer
to invoke with the current RepeatSpec.RepeatSignal
RepeatSpec
with the doAfterRepeat appliedpublic RepeatSpec withFixedDelay(java.time.Duration delay)
delay
- the Duration
of delay to apply between repeat attemptsRepeatSpec
with the delay appliedpublic RepeatSpec jitter(double jitter)
jitter
- jitter factor as a percentage of the base delay (e.g. 0.1 = ±10%)RepeatSpec
with jitter configuredpublic RepeatSpec withScheduler(Scheduler scheduler)
Scheduler
to use for delaying repeat attempts.scheduler
- the scheduler to applyRepeatSpec
with the scheduler appliedpublic Publisher<java.lang.Long> generateCompanion(Flux<java.lang.Long> signals)
signals
- the incoming repeat signals, where each Long
value indicates the iteration index