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
tt = new TransactionTemplate<Void>(new MuleTransactionConfig(), muleContext);
}
}
else
{
tt = new TransactionTemplate<Void>(endpoint.getTransactionConfig(), muleContext);
}
final InboundEndpoint finalEndpoint = endpoint;
TransactionCallback<Void> cb = new TransactionCallback<Void>()
{
public Void doInTransaction() throws Exception
{
Transaction tx = TransactionCoordination.getInstance().getTransaction();
if (tx != null)
{
tx.begin();
}
MuleMessage result = null;
if (pollGlobalEndpoint.get())
{
result = finalEndpoint.getConnector().request(finalEndpoint, jobConfig.getTimeout());
}
else
{
MuleClient client = new MuleClient(connector.getMuleContext());
result = client.request(jobConfig.getEndpointRef(), jobConfig.getTimeout());
}
if (result != null)
{
if (logger.isDebugEnabled())
{
logger.debug("Received event on: " + jobConfig.getEndpointRef());
}
if (pollGlobalEndpoint.get())
{
result.applyTransformers(null, finalEndpoint.getTransformers());
}
//we need to do this because
result = (MuleMessage) ((ThreadSafeAccess) result).newThreadCopy();