}
if (event != null)
{
final MuleEvent eventToProcess = event;
TransactionalErrorHandlingExecutionTemplate executionTemplate = TransactionalErrorHandlingExecutionTemplate.createMainExecutionTemplate(muleContext, event.getFlowConstruct().getExceptionListener());
ExecutionCallback<MuleEvent> processingCallback = new ExecutionCallback<MuleEvent>()
{
@Override
public MuleEvent process() throws Exception
{
if (isStatsEnabled())
{
queueStatistics.decQueuedEvent();
}
if (logger.isDebugEnabled())
{
logger.debug(MessageFormat.format("{0}: Dequeued event from {1}",
getStageDescription(), getQueueName()));
}
AsyncMessageProcessorWorker work = new AsyncMessageProcessorWorker(eventToProcess);
try
{
// TODO Remove this thread handoff to ensure Zero Message Loss
workManagerSource.getWorkManager().scheduleWork(work, WorkManager.INDEFINITE,
null, new AsyncWorkListener(next));
}
catch (Exception e)
{
// because dequeued event may still be owned by a previuos
// thread we need to use the copy created in AsyncMessageProcessorWorker
// constructor.
OptimizedRequestContext.unsafeSetEvent(work.getEvent());
throw new MessagingException(work.getEvent(), e, SedaStageInterceptingMessageProcessor.this);
}
return null;
}
};
try
{
executionTemplate.execute(processingCallback);
}
catch (MessagingException e)
{
//Already handled by processing template
}