use of org.mule.runtime.core.api.retry.policy.SimpleRetryPolicyTemplate.RETRY_COUNT_FOREVER in project mule by mulesoft.
the class SimpleRetryPolicy method applyPolicy.
@Override
public <T> Publisher<T> applyPolicy(Publisher<T> publisher, Predicate<Throwable> shouldRetry, Consumer<Throwable> onExhausted, Function<Throwable, Throwable> errorFunction, Scheduler retryScheduler) {
return from(publisher).onErrorResume(e -> {
if (shouldRetry.test(e)) {
Retry<T> retry = (Retry<T>) onlyIf(ctx -> shouldRetry.test(unwrap(ctx.exception()))).backoff(ctx -> new BackoffDelay(frequency, ZERO, ZERO));
if (count != RETRY_COUNT_FOREVER) {
retry = retry.retryMax(count - 1);
}
reactor.core.scheduler.Scheduler reactorRetryScheduler = fromExecutorService(new ConditionalExecutorServiceDecorator(retryScheduler, s -> isTransactionActive()));
Mono<T> retryMono = from(publisher).retryWhen(retry.withBackoffScheduler(reactorRetryScheduler)).doOnError(e2 -> onExhausted.accept(unwrap(e2))).onErrorMap(RetryExhaustedException.class, e2 -> errorFunction.apply(unwrap(e2.getCause())));
return delay(frequency, reactorRetryScheduler).then(isTransactionActive() ? just(retryMono.block()) : retryMono);
} else {
e = unwrap(e);
onExhausted.accept(e);
return error(errorFunction.apply(e));
}
});
}
Aggregations