1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
package org.mule.transport.quartz.jobs; |
12 | |
|
13 | |
import org.mule.api.MuleException; |
14 | |
import org.mule.module.client.MuleClient; |
15 | |
import org.mule.transport.NullPayload; |
16 | |
import org.mule.transport.quartz.QuartzConnector; |
17 | |
import org.mule.transport.quartz.i18n.QuartzMessages; |
18 | |
|
19 | |
import java.io.Serializable; |
20 | |
|
21 | |
import org.apache.commons.logging.Log; |
22 | |
import org.apache.commons.logging.LogFactory; |
23 | |
import org.quartz.Job; |
24 | |
import org.quartz.JobDataMap; |
25 | |
import org.quartz.JobExecutionContext; |
26 | |
import org.quartz.JobExecutionException; |
27 | |
|
28 | |
|
29 | |
|
30 | |
|
31 | |
|
32 | 0 | public class ScheduledDispatchJob implements Job, Serializable |
33 | |
{ |
34 | |
|
35 | |
|
36 | |
|
37 | 0 | protected transient Log logger = LogFactory.getLog(getClass()); |
38 | |
|
39 | |
public void execute(JobExecutionContext jobExecutionContext) throws JobExecutionException |
40 | |
{ |
41 | 0 | JobDataMap jobDataMap = jobExecutionContext.getJobDetail().getJobDataMap(); |
42 | 0 | Object payload = jobDataMap.get(QuartzConnector.PROPERTY_PAYLOAD); |
43 | |
|
44 | 0 | if (payload == null) |
45 | |
{ |
46 | 0 | payload = NullPayload.getInstance(); |
47 | |
} |
48 | |
|
49 | 0 | ScheduledDispatchJobConfig config = (ScheduledDispatchJobConfig) jobDataMap.get(QuartzConnector.PROPERTY_JOB_CONFIG); |
50 | 0 | if (config == null) |
51 | |
{ |
52 | 0 | throw new JobExecutionException( |
53 | |
QuartzMessages.missingJobDetail(QuartzConnector.PROPERTY_JOB_CONFIG).getMessage()); |
54 | |
} |
55 | |
|
56 | |
try |
57 | |
{ |
58 | 0 | MuleClient client = new MuleClient(config.getMuleContext()); |
59 | |
|
60 | 0 | String endpointRef = config.getEndpointRef(); |
61 | 0 | if (jobDataMap.containsKey("endpointRef")) |
62 | |
{ |
63 | 0 | endpointRef = (String) jobDataMap.get("endpointRef"); |
64 | |
} |
65 | |
|
66 | 0 | logger.debug("Dispatching payload on: " + config.getEndpointRef()); |
67 | |
|
68 | 0 | client.dispatch(endpointRef, payload, jobDataMap); |
69 | |
} |
70 | 0 | catch (MuleException e) |
71 | |
{ |
72 | 0 | throw new JobExecutionException(e); |
73 | 0 | } |
74 | 0 | } |
75 | |
} |