Source:
UntilSuccessfulRouter(Component owner, Publisher<CoreEvent> publisher, MessageProcessorChain nestedChain, ExtendedExpressionManager expressionManager, Predicate<CoreEvent> shouldRetry, Scheduler delayScheduler, String maxRetries, String millisBetweenRetries) { this.owner = owner; this.shouldRetry = shouldRetry; this.delayScheduler = new ConditionalExecutorServiceDecorator(delayScheduler, s -> isTransactionActive()); upstreamFlux = Flux.from(publisher) .doOnNext(event -> { RetryContext ctx = new RetryContext(event); inflightEvents.getAndIncrement(); innerRecorder.next(pushRetryContext(event, ctx)); }) .doOnError(RetryContextInitializationException.class, error -> downstreamRecorder.next(Either.left(error.getCause(), CoreEvent.class))) .doOnComplete(() -> { if (inflightEvents.get() == 0) { completeRouter(); } else { completeDeferred.set(true); } }); innerFlux = Flux.create(innerRecorder) .transform(innerPublisher -> applyWithChildContext(innerPublisher, nestedChain, Optional.of(owner.getLocation()))) .doOnNext(successfulEvent -> { popRetryContext(successfulEvent); downstreamRecorder.next(Either.right(Throwable.class, successfulEvent)); completeRouterIfNecessary(); }) .onErrorContinue(getRetryPredicate(), getRetryHandler()); downstreamFlux = Flux.create(downstreamRecorder) .doOnNext(event -> inflightEvents.decrementAndGet()) .map(getScopeResultMapper()); if (expressionManager.isExpression(maxRetries)) { maxRetriesSupplier = expressionToIntegerSupplierFor(maxRetries); } else { Integer asInteger = Integer.parseInt(maxRetries); maxRetriesSupplier = session -> asInteger; } if (expressionManager.isExpression(millisBetweenRetries)) { delaySupplier = expressionToIntegerSupplierFor(millisBetweenRetries); } else { Integer asInteger = Integer.parseInt(millisBetweenRetries); delaySupplier = session -> asInteger; } if (!expressionManager.isExpression(maxRetries) && !expressionManager.isExpression(millisBetweenRetries)) { sessionSupplier = event -> null; } else { sessionSupplier = event -> expressionManager.openSession(owner.getLocation(), event, NULL_BINDING_CONTEXT); } }

Target:
UntilSuccessfulRouter(Component owner, Publisher<CoreEvent> publisher, MessageProcessorChain nestedChain, ExtendedExpressionManager expressionManager, Predicate<CoreEvent> shouldRetry, Scheduler delayScheduler, String maxRetries, String millisBetweenRetries) { this.owner = owner; this.shouldRetry = shouldRetry; this.delayScheduler = new ConditionalExecutorServiceDecorator(delayScheduler, s -> isTransactionActive()); this.retryContextResolver = new EventInternalContextResolver<>(RETRY_CTX_INTERNAL_PARAM_KEY, HashMap::new); upstreamFlux = Flux.from(publisher) .doOnNext(event -> { RetryContext ctx = new RetryContext(event, sessionSupplier, maxRetriesSupplier, delaySupplier); inflightEvents.getAndIncrement(); innerRecorder.next(eventWithCurrentContext(event, ctx)); }) .doOnComplete(() -> { if (inflightEvents.get() == 0) { completeRouter(); } else { completeDeferred.set(true); } }); innerFlux = Flux.create(innerRecorder) .transform(innerPublisher -> applyWithChildContext(innerPublisher, nestedChain, Optional.of(owner.getLocation()))) .doOnNext(successfulEvent -> { downstreamRecorder.next(right(Throwable.class, eventWithCurrentContextDeleted(successfulEvent))); completeRouterIfNecessary(); }) .onErrorContinue(getRetryPredicate(), getRetryHandler()); downstreamFlux = Flux.create(downstreamRecorder) .doOnNext(event -> inflightEvents.decrementAndGet()) .map(getScopeResultMapper()); if (expressionManager.isExpression(maxRetries)) { maxRetriesSupplier = expressionToIntegerSupplierFor(maxRetries); } else { maxRetriesSupplier = session -> (Integer) parseInt(maxRetries); } if (expressionManager.isExpression(millisBetweenRetries)) { delaySupplier = expressionToIntegerSupplierFor(millisBetweenRetries); } else { delaySupplier = session -> (Integer) parseInt(millisBetweenRetries); } if (!expressionManager.isExpression(maxRetries) && !expressionManager.isExpression(millisBetweenRetries)) { sessionSupplier = event -> null; } else { sessionSupplier = event -> expressionManager.openSession(owner.getLocation(), event, NULL_BINDING_CONTEXT); } }