use of org.mule.runtime.core.privileged.execution.MessageProcessContext in project mule by mulesoft.
the class ModuleFlowProcessingPhase method runPhase.
@Override
public void runPhase(final ModuleFlowProcessingPhaseTemplate template, final MessageProcessContext messageProcessContext, final PhaseResultNotifier phaseResultNotifier) {
try {
final MessageSource messageSource = messageProcessContext.getMessageSource();
final FlowConstruct flowConstruct = (FlowConstruct) componentLocator.find(messageSource.getRootContainerLocation()).get();
final ComponentLocation sourceLocation = messageSource.getLocation();
final Consumer<Either<MessagingException, CoreEvent>> terminateConsumer = getTerminateConsumer(messageSource, template);
final CompletableFuture<Void> responseCompletion = new CompletableFuture<>();
final CoreEvent templateEvent = createEvent(template, sourceLocation, responseCompletion, flowConstruct);
try {
FlowProcessor flowExecutionProcessor = new FlowProcessor(template, flowConstruct.getExceptionListener(), templateEvent);
flowExecutionProcessor.setAnnotations(flowConstruct.getAnnotations());
final SourcePolicy policy = policyManager.createSourcePolicyInstance(messageSource, templateEvent, flowExecutionProcessor, template);
final PhaseContext phaseContext = new PhaseContext(template, messageProcessContext, phaseResultNotifier, terminateConsumer);
just(templateEvent).doOnNext(onMessageReceived(template, messageProcessContext, flowConstruct)).flatMap(request -> from(policy.process(request))).flatMap(policyResult -> policyResult.reduce(policyFailure(phaseContext, flowConstruct, messageSource), policySuccess(phaseContext, flowConstruct, messageSource))).doOnSuccess(aVoid -> phaseResultNotifier.phaseSuccessfully()).doOnError(onFailure(flowConstruct, messageSource, phaseResultNotifier, terminateConsumer)).doAfterTerminate(() -> responseCompletion.complete(null)).subscribe();
} catch (Exception e) {
from(template.sendFailureResponseToClient(new MessagingExceptionResolver(messageProcessContext.getMessageSource()).resolve(new MessagingException(templateEvent, e), muleContext), template.getFailedExecutionResponseParametersFunction().apply(templateEvent))).doOnTerminate(() -> phaseResultNotifier.phaseFailure(e)).subscribe();
}
} catch (Exception t) {
phaseResultNotifier.phaseFailure(t);
}
}
use of org.mule.runtime.core.privileged.execution.MessageProcessContext in project mule by mulesoft.
the class DefaultSourceCallback method handle.
/**
* {@inheritDoc}
*/
@Override
public void handle(Result<T, A> result, SourceCallbackContext context) {
checkArgument(context instanceof SourceCallbackContextAdapter, "The supplied context was not created through this callback, " + "you naughty developer");
SourceCallbackContextAdapter contextAdapter = (SourceCallbackContextAdapter) context;
validateNotifications(contextAdapter);
MessageProcessContext messageProcessContext = processContextSupplier.get();
SourceResultAdapter resultAdapter = new SourceResultAdapter(result, cursorProviderFactory, defaultMediaType, returnsListOfMessages, context.getCorrelationId());
Message message = of(resultAdapter);
executeFlow(context, messageProcessContext, message);
contextAdapter.dispatched();
}
Aggregations