1 10 11 package org.mule.providers.quartz.jobs; 12 13 import org.apache.commons.logging.Log; 14 import org.apache.commons.logging.LogFactory; 15 import org.mule.MuleManager; 16 import org.mule.config.i18n.Message; 17 import org.mule.extras.client.MuleClient; 18 import org.mule.providers.quartz.QuartzConnector; 19 import org.mule.umo.UMOException; 20 import org.mule.umo.UMOMessage; 21 import org.quartz.Job; 22 import org.quartz.JobDataMap; 23 import org.quartz.JobExecutionContext; 24 import org.quartz.JobExecutionException; 25 26 29 public class MuleClientReceiveJob implements Job 30 { 31 34 protected transient Log logger = LogFactory.getLog(getClass()); 35 36 public void execute(JobExecutionContext jobExecutionContext) throws JobExecutionException 37 { 38 JobDataMap jobDataMap = jobExecutionContext.getJobDetail().getJobDataMap(); 39 40 String dispatchEndpoint = jobDataMap.getString(QuartzConnector.PROPERTY_JOB_DISPATCH_ENDPOINT); 41 if (dispatchEndpoint == null) 42 { 43 throw new JobExecutionException(new Message("quartz", 4, 44 QuartzConnector.PROPERTY_JOB_DISPATCH_ENDPOINT).getMessage()); 45 } 46 47 String receiveEndpoint = jobDataMap.getString(QuartzConnector.PROPERTY_JOB_RECEIVE_ENDPOINT); 48 if (receiveEndpoint == null) 49 { 50 throw new JobExecutionException(new Message("quartz", 4, 51 QuartzConnector.PROPERTY_JOB_RECEIVE_ENDPOINT).getMessage()); 52 } 53 long timeout = MuleManager.getConfiguration().getSynchronousEventTimeout(); 54 String timeoutString = jobDataMap.getString(QuartzConnector.PROPERTY_JOB_RECEIVE_TIMEOUT); 55 if (timeoutString != null) 56 { 57 timeout = Long.parseLong(timeoutString); 58 } 59 try 60 { 61 MuleClient client = new MuleClient(); 62 logger.debug("Attempting to receive event on: " + receiveEndpoint); 63 UMOMessage result = client.receive(receiveEndpoint, timeout); 64 if (result != null) 65 { 66 logger.debug("Received event on: " + receiveEndpoint); 67 logger.debug("Dispatching result on: " + dispatchEndpoint); 68 result.addProperties(jobDataMap); 69 client.dispatch(dispatchEndpoint, result); 70 } 71 } 72 catch (UMOException e) 73 { 74 throw new JobExecutionException(e); 75 } 76 } 77 } 78 | Popular Tags |