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 | 0 | public class MuleClientReceiveJob implements Job |
31 | |
{ |
32 | |
|
33 | |
|
34 | |
|
35 | 0 | protected transient Log logger = LogFactory.getLog(getClass()); |
36 | |
|
37 | |
public void execute(JobExecutionContext jobExecutionContext) throws JobExecutionException |
38 | |
{ |
39 | 0 | JobDataMap jobDataMap = jobExecutionContext.getJobDetail().getJobDataMap(); |
40 | |
|
41 | 0 | String dispatchEndpoint = jobDataMap.getString(QuartzConnector.PROPERTY_JOB_DISPATCH_ENDPOINT); |
42 | 0 | if (dispatchEndpoint == null) |
43 | |
{ |
44 | 0 | throw new JobExecutionException( |
45 | |
QuartzMessages.missingJobDetail(QuartzConnector.PROPERTY_JOB_DISPATCH_ENDPOINT).getMessage()); |
46 | |
} |
47 | |
|
48 | 0 | String receiveEndpoint = jobDataMap.getString(QuartzConnector.PROPERTY_JOB_RECEIVE_ENDPOINT); |
49 | 0 | if (receiveEndpoint == null) |
50 | |
{ |
51 | 0 | throw new JobExecutionException( |
52 | |
QuartzMessages.missingJobDetail(QuartzConnector.PROPERTY_JOB_RECEIVE_ENDPOINT).getMessage()); |
53 | |
} |
54 | 0 | long timeout = MuleManager.getConfiguration().getSynchronousEventTimeout(); |
55 | 0 | String timeoutString = jobDataMap.getString(QuartzConnector.PROPERTY_JOB_RECEIVE_TIMEOUT); |
56 | 0 | if (timeoutString != null) |
57 | |
{ |
58 | 0 | timeout = Long.parseLong(timeoutString); |
59 | |
} |
60 | |
try |
61 | |
{ |
62 | 0 | MuleClient client = new MuleClient(); |
63 | 0 | logger.debug("Attempting to receive event on: " + receiveEndpoint); |
64 | 0 | UMOMessage result = client.receive(receiveEndpoint, timeout); |
65 | 0 | if (result != null) |
66 | |
{ |
67 | 0 | logger.debug("Received event on: " + receiveEndpoint); |
68 | 0 | logger.debug("Dispatching result on: " + dispatchEndpoint); |
69 | 0 | result.addProperties(jobDataMap); |
70 | 0 | client.dispatch(dispatchEndpoint, result); |
71 | |
} |
72 | |
} |
73 | 0 | catch (UMOException e) |
74 | |
{ |
75 | 0 | throw new JobExecutionException(e); |
76 | 0 | } |
77 | 0 | } |
78 | |
} |