1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
package org.mule.transport.quartz.jobs; |
8 | |
|
9 | |
import org.mule.api.MuleContext; |
10 | |
import org.mule.api.MuleException; |
11 | |
import org.mule.api.config.MuleProperties; |
12 | |
import org.mule.module.client.MuleClient; |
13 | |
import org.mule.transport.NullPayload; |
14 | |
import org.mule.transport.quartz.QuartzConnector; |
15 | |
import org.mule.transport.quartz.i18n.QuartzMessages; |
16 | |
|
17 | |
import java.io.Serializable; |
18 | |
|
19 | |
import org.apache.commons.logging.Log; |
20 | |
import org.apache.commons.logging.LogFactory; |
21 | |
import org.quartz.Job; |
22 | |
import org.quartz.JobDataMap; |
23 | |
import org.quartz.JobExecutionContext; |
24 | |
import org.quartz.JobExecutionException; |
25 | |
import org.quartz.SchedulerContext; |
26 | |
import org.quartz.SchedulerException; |
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 | SchedulerContext schedulerContext = jobExecutionContext.getScheduler().getContext(); |
59 | 0 | MuleContext muleContext = (MuleContext) schedulerContext.get(MuleProperties.MULE_CONTEXT_PROPERTY); |
60 | |
|
61 | 0 | String endpointRef = config.getEndpointRef(); |
62 | 0 | if (jobDataMap.containsKey("endpointRef")) |
63 | |
{ |
64 | 0 | endpointRef = (String) jobDataMap.get("endpointRef"); |
65 | |
} |
66 | |
|
67 | 0 | logger.debug("Dispatching payload on: " + config.getEndpointRef()); |
68 | |
|
69 | 0 | MuleClient client = new MuleClient(muleContext); |
70 | 0 | client.dispatch(endpointRef, payload, jobDataMap); |
71 | |
} |
72 | 0 | catch (MuleException e) |
73 | |
{ |
74 | 0 | throw new JobExecutionException(e); |
75 | |
} |
76 | 0 | catch (SchedulerException e) |
77 | |
{ |
78 | 0 | throw new JobExecutionException(e); |
79 | 0 | } |
80 | 0 | } |
81 | |
} |