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