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