1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
package org.mule.transport.quartz.jobs; |
12 | |
|
13 | |
import org.mule.api.MuleContext; |
14 | |
import org.mule.api.config.MuleProperties; |
15 | |
import org.mule.transport.quartz.QuartzConnector; |
16 | |
import org.mule.transport.quartz.i18n.QuartzMessages; |
17 | |
|
18 | |
import org.quartz.Job; |
19 | |
import org.quartz.JobDataMap; |
20 | |
import org.quartz.JobExecutionContext; |
21 | |
import org.quartz.JobExecutionException; |
22 | |
import org.quartz.SchedulerContext; |
23 | |
import org.quartz.SchedulerException; |
24 | |
|
25 | |
|
26 | |
|
27 | |
|
28 | |
|
29 | |
|
30 | |
|
31 | |
|
32 | |
|
33 | |
|
34 | 0 | public class CustomJob implements Job |
35 | |
{ |
36 | |
public void execute(JobExecutionContext jobExecutionContext) throws JobExecutionException |
37 | |
{ |
38 | 0 | MuleContext muleContext = lookupMuleContext(jobExecutionContext); |
39 | |
|
40 | 0 | JobDataMap jobDataMap = jobExecutionContext.getJobDetail().getJobDataMap(); |
41 | 0 | Object tempJob = jobDataMap.get(QuartzConnector.PROPERTY_JOB_OBJECT); |
42 | 0 | if (tempJob == null) |
43 | |
{ |
44 | 0 | tempJob = jobDataMap.get(QuartzConnector.PROPERTY_JOB_REF); |
45 | 0 | if (tempJob == null) |
46 | |
{ |
47 | 0 | throw new JobExecutionException(QuartzMessages.invalidPayloadType().getMessage()); |
48 | |
} |
49 | |
else |
50 | |
{ |
51 | 0 | tempJob = muleContext.getRegistry().lookupObject((String) tempJob); |
52 | 0 | if (tempJob == null) |
53 | |
{ |
54 | 0 | throw new JobExecutionException("Job not found: " + tempJob); |
55 | |
} |
56 | 0 | if (!(tempJob instanceof Job)) |
57 | |
{ |
58 | 0 | throw new JobExecutionException(QuartzMessages.invalidJobObject().getMessage()); |
59 | |
} |
60 | |
} |
61 | |
} |
62 | 0 | else if (!(tempJob instanceof Job)) |
63 | |
{ |
64 | 0 | throw new JobExecutionException(QuartzMessages.invalidJobObject().toString()); |
65 | |
} |
66 | 0 | ((Job)tempJob).execute(jobExecutionContext); |
67 | 0 | } |
68 | |
|
69 | |
private MuleContext lookupMuleContext(JobExecutionContext jobExecutionContext) throws JobExecutionException |
70 | |
{ |
71 | |
try |
72 | |
{ |
73 | 0 | SchedulerContext schedulerContext = jobExecutionContext.getScheduler().getContext(); |
74 | 0 | return (MuleContext) schedulerContext.get(MuleProperties.MULE_CONTEXT_PROPERTY); |
75 | |
} |
76 | 0 | catch (SchedulerException e) |
77 | |
{ |
78 | 0 | throw new JobExecutionException("Failed to retrieve Mulecontext from the Scheduler Context: " + e.getMessage(), e); |
79 | |
} |
80 | |
} |
81 | |
} |