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.impl.MuleMessage; 17 import org.mule.providers.AbstractMessageReceiver; 18 import org.mule.providers.NullPayload; 19 import org.mule.providers.quartz.QuartzConnector; 20 import org.mule.providers.quartz.QuartzMessageReceiver; 21 import org.mule.umo.manager.ObjectNotFoundException; 22 import org.quartz.Job; 23 import org.quartz.JobDataMap; 24 import org.quartz.JobExecutionContext; 25 import org.quartz.JobExecutionException; 26 27 30 public class MuleReceiverJob implements Job 31 { 32 33 36 protected transient Log logger = LogFactory.getLog(getClass()); 37 38 public void execute(JobExecutionContext jobExecutionContext) throws JobExecutionException 39 { 40 JobDataMap map = jobExecutionContext.getJobDetail().getJobDataMap(); 41 AbstractMessageReceiver receiver = (AbstractMessageReceiver)map.get(QuartzMessageReceiver.QUARTZ_RECEIVER_PROPERTY); 42 Object payload = jobExecutionContext.getJobDetail().getJobDataMap().get( 43 QuartzConnector.PROPERTY_PAYLOAD); 44 45 try 46 { 47 if (payload == null) 48 { 49 String ref = jobExecutionContext.getJobDetail().getJobDataMap().getString( 50 QuartzConnector.PROPERTY_PAYLOAD_REFERENCE); 51 if (ref == null) 54 { 55 ref = jobExecutionContext.getJobDetail().getJobDataMap().getString( 56 QuartzConnector.PROPERTY_PAYLOAD_CLASS_NAME); 57 } 58 try 59 { 60 payload = MuleManager.getInstance().getContainerContext().getComponent(ref); 61 } 62 catch (ObjectNotFoundException e) 63 { 64 logger.warn("There is no payload attached to this quartz job. Sending Null payload"); 65 payload = new NullPayload(); 66 } 67 } 68 receiver.routeMessage(new MuleMessage(receiver.getConnector().getMessageAdapter(payload))); 69 } 70 catch (Exception e) 71 { 72 receiver.handleException(e); 73 } 74 } 75 } 76 | Popular Tags |