Source:
<code>public Source configure(Source source, Optional<ConfigurationInstance> config) { ResolverSetBasedObjectBuilder<Source> builder = new ResolverSetBasedObjectBuilder<Source>(source.getClass(), model, resolverSet, expressionManager, muleContext) { @Override protected Source instantiateObject() { return source; } @Override public Source build(ValueResolvingContext context) throws MuleException { Source source = build(resolverSet.resolve(context)); injectDefaultEncoding(model, source, muleContext.getConfiguration().getDefaultEncoding()); injectComponentLocation(source, componentLocation); config.ifPresent(c -> injectRefName(source, c.getName(), getReflectionCache())); return source; } }; CoreEvent initialiserEvent = null; ValueResolvingContext context = null; try { initialiserEvent = getInitialiserEvent(muleContext); context = ValueResolvingContext.builder(initialiserEvent, expressionManager).withConfig(config).build(); Source configuredSource = builder.build(context); if (configuredSource instanceof PollingSource) { ValueResolver<?> valueResolver = resolverSet.getResolvers().get(SCHEDULING_STRATEGY_PARAMETER_NAME); if (valueResolver == null) { if (!lazyInit()) { throw new IllegalStateException("The scheduling strategy has not been configured"); } } else { context = ValueResolvingContext.builder(initialiserEvent, expressionManager).build(); Scheduler scheduler = (Scheduler) valueResolver.resolve(context); <START> if (isRestart) { <END> if (scheduler instanceof FixedFrequencyScheduler) { ((FixedFrequencyScheduler) scheduler).setStartDelay(0); } else if (scheduler instanceof CronScheduler) { RunNowCronSchedulerWrapper schedulerWrapper = new RunNowCronSchedulerWrapper((CronScheduler) scheduler); scheduler = schedulerWrapper; } } configuredSource = new PollingSourceWrapper<>((PollingSource) configuredSource, scheduler); } } return configuredSource; } catch (Exception e) { throw new MuleRuntimeException(createStaticMessage("Exception was found trying to configure source of type " + source.getClass().getName()), e); } finally { if (initialiserEvent != null) { ((BaseEventContext) initialiserEvent.getContext()).success(); } if (context != null) { context.close(); } } }</code><technical_language>I move this logic another class, a factory a scheduler boolean returns another scheduler</technical_language>

Target:
public Source configure(Source source, Optional<ConfigurationInstance> config) { ResolverSetBasedObjectBuilder<Source> builder = new ResolverSetBasedObjectBuilder<Source>(source.getClass(), model, resolverSet, expressionManager, muleContext) { @Override protected Source instantiateObject() { return source; } @Override public Source build(ValueResolvingContext context) throws MuleException { Source source = build(resolverSet.resolve(context)); injectDefaultEncoding(model, source, muleContext.getConfiguration().getDefaultEncoding()); injectComponentLocation(source, componentLocation); config.ifPresent(c -> injectRefName(source, c.getName(), getReflectionCache())); return source; } }; CoreEvent initialiserEvent = null; ValueResolvingContext context = null; try { initialiserEvent = getInitialiserEvent(muleContext); context = ValueResolvingContext.builder(initialiserEvent, expressionManager).withConfig(config).build(); Source configuredSource = builder.build(context); if (configuredSource instanceof PollingSource) { ValueResolver<?> valueResolver = resolverSet.getResolvers().get(SCHEDULING_STRATEGY_PARAMETER_NAME); if (valueResolver == null) { if (!lazyInit()) { throw new IllegalStateException("The scheduling strategy has not been configured"); } } else { context = ValueResolvingContext.builder(initialiserEvent, expressionManager).build(); Scheduler scheduler = getScheduler(context, valueResolver, restarting); configuredSource = new PollingSourceWrapper<>((PollingSource) configuredSource, scheduler); } } return configuredSource; } catch (Exception e) { throw new MuleRuntimeException(createStaticMessage("Exception was found trying to configure source of type " + source.getClass().getName()), e); } finally { if (initialiserEvent != null) { ((BaseEventContext) initialiserEvent.getContext()).success(); } if (context != null) { context.close(); } } }