use of org.mule.runtime.api.scheduler.SchedulerBusyException in project mule by mulesoft.
the class FlowProcessingPhase method runPhase.
@Override
public void runPhase(final FlowProcessingPhaseTemplate flowProcessingPhaseTemplate, final MessageProcessContext messageProcessContext, final PhaseResultNotifier phaseResultNotifier) {
Runnable flowExecutionWork = () -> {
try {
FlowConstruct flowConstruct = registry.<FlowConstruct>lookupByName(messageProcessContext.getMessageSource().getRootContainerLocation().toString()).get();
try {
final AtomicReference exceptionThrownDuringFlowProcessing = new AtomicReference();
TransactionalExecutionTemplate<CoreEvent> transactionTemplate = createTransactionalExecutionTemplate(muleContext, messageProcessContext.getTransactionConfig().orElse(new MuleTransactionConfig()));
CoreEvent response = transactionTemplate.execute(() -> {
try {
Object message = flowProcessingPhaseTemplate.getOriginalMessage();
if (message == null) {
return null;
}
CoreEvent muleEvent = flowProcessingPhaseTemplate.getEvent();
muleEvent = flowProcessingPhaseTemplate.beforeRouteEvent(muleEvent);
muleEvent = flowProcessingPhaseTemplate.routeEvent(muleEvent);
muleEvent = flowProcessingPhaseTemplate.afterRouteEvent(muleEvent);
sendResponseIfNeccessary(messageProcessContext.getMessageSource(), flowConstruct, muleEvent, flowProcessingPhaseTemplate);
return muleEvent;
} catch (Exception e) {
exceptionThrownDuringFlowProcessing.set(e);
throw e;
}
});
if (exceptionThrownDuringFlowProcessing.get() != null && !(exceptionThrownDuringFlowProcessing.get() instanceof ResponseDispatchException)) {
sendResponseIfNeccessary(messageProcessContext.getMessageSource(), flowConstruct, response, flowProcessingPhaseTemplate);
}
flowProcessingPhaseTemplate.afterSuccessfulProcessingFlow(response);
} catch (ResponseDispatchException e) {
flowProcessingPhaseTemplate.afterFailureProcessingFlow(e);
} catch (MessagingException e) {
sendFailureResponseIfNeccessary(messageProcessContext.getMessageSource(), flowConstruct, e, flowProcessingPhaseTemplate);
flowProcessingPhaseTemplate.afterFailureProcessingFlow(e);
}
phaseResultNotifier.phaseSuccessfully();
} catch (Exception e) {
MuleException me = new DefaultMuleException(e);
try {
flowProcessingPhaseTemplate.afterFailureProcessingFlow(me);
} catch (MuleException e1) {
logger.warn("Failure during exception processing in flow template: " + e.getMessage());
if (logger.isDebugEnabled()) {
logger.debug("Failure during exception processing in flow template: ", e);
}
}
phaseResultNotifier.phaseFailure(e);
}
};
if (messageProcessContext.supportsAsynchronousProcessing()) {
try {
messageProcessContext.getFlowExecutionExecutor().execute(flowExecutionWork);
} catch (SchedulerBusyException e) {
phaseResultNotifier.phaseFailure(e);
}
} else {
flowExecutionWork.run();
}
}
Aggregations