*/
protected transient Log logger = LogFactory.getLog(getClass());
public void execute(JobExecutionContext jobExecutionContext) throws JobExecutionException
{
MuleContext muleContext;
try
{
muleContext = (MuleContext)jobExecutionContext.getScheduler().getContext().get(MuleProperties.MULE_CONTEXT_PROPERTY);
}
catch (SchedulerException e)
{
throw new JobExecutionException("Failed to retrieve Mulecontext from the Scheduler Context: " + e.getMessage(), e);
}
final JobDataMap jobDataMap = jobExecutionContext.getJobDetail().getJobDataMap();
String receiverKey = (String) jobDataMap.get(QuartzMessageReceiver.QUARTZ_RECEIVER_PROPERTY);
if (receiverKey == null)
{
throw new JobExecutionException(QuartzMessages.receiverNotInJobDataMap().getMessage());
}
String connectorName = (String) jobDataMap.get(QuartzMessageReceiver.QUARTZ_CONNECTOR_PROPERTY);
if (connectorName == null)
{
throw new JobExecutionException(QuartzMessages.connectorNotInJobDataMap().getMessage());
}
final QuartzConnector connector = (QuartzConnector) muleContext.getRegistry().lookupConnector(connectorName);
if (connector == null)
{
throw new JobExecutionException(QuartzMessages.noConnectorFound(connectorName).getMessage());
}
final AbstractMessageReceiver receiver = (AbstractMessageReceiver) connector.lookupReceiver(receiverKey);
if (receiver == null)
{
throw new JobExecutionException(
QuartzMessages.noReceiverInConnector(receiverKey, connectorName).getMessage());
}
final EndpointPollingJobConfig jobConfig = (EndpointPollingJobConfig) jobDataMap.get(QuartzConnector.PROPERTY_JOB_CONFIG);
if (jobConfig == null)
{
throw new JobExecutionException(
QuartzMessages.missingJobDetail(QuartzConnector.PROPERTY_JOB_CONFIG).getMessage());
}
try
{
logger.debug("Attempting to receive event on: " + jobConfig.getEndpointRef());
TransactionTemplate<Void> tt;
final AtomicBoolean pollGlobalEndpoint = new AtomicBoolean(false);
//TODO MULE-5050 work around because the builder is no longer idempotent, we now cache the endpoint instance
InboundEndpoint endpoint = muleContext.getRegistry().lookupObject(jobConfig.getEndpointRef() + ".quartz-job");
if(endpoint==null)
{
final EndpointBuilder epBuilder = muleContext.getRegistry().lookupEndpointBuilder(jobConfig.getEndpointRef());
pollGlobalEndpoint.set(epBuilder != null);
if (pollGlobalEndpoint.get())
{
// referencing a global endpoint, fetch configuration from it
endpoint = epBuilder.buildInboundEndpoint();
//TODO MULE-5050 work around because the builder is no longer idempotent, we now cache the endpoint instance
muleContext.getRegistry().registerObject(jobConfig.getEndpointRef() + ".quartz-job", endpoint);
tt = new TransactionTemplate<Void>(endpoint.getTransactionConfig(), muleContext);
}
else
{
// a simple inline endpoint