1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
package org.mule.transport.quartz.jobs; |
11 | |
|
12 | |
import org.mule.api.MuleContext; |
13 | |
import org.mule.api.MuleException; |
14 | |
import org.mule.api.context.MuleContextAware; |
15 | |
import org.mule.api.endpoint.InboundEndpoint; |
16 | |
import org.mule.api.lifecycle.InitialisationException; |
17 | |
import org.mule.api.lifecycle.Lifecycle; |
18 | |
import org.mule.transport.AbstractConnector; |
19 | |
import org.mule.transport.AbstractPollingMessageReceiver; |
20 | |
|
21 | |
import org.quartz.Job; |
22 | |
import org.quartz.JobExecutionContext; |
23 | |
import org.quartz.JobExecutionException; |
24 | |
|
25 | |
public class PollEndpointJob implements Job, Lifecycle, MuleContextAware |
26 | |
{ |
27 | |
private String inboundPollingEndpointName; |
28 | |
private AbstractPollingMessageReceiver receiver; |
29 | |
private MuleContext muleContext; |
30 | |
|
31 | |
public PollEndpointJob(String inboundPollingEndpointName) |
32 | 0 | { |
33 | 0 | this.inboundPollingEndpointName = inboundPollingEndpointName; |
34 | 0 | } |
35 | |
|
36 | |
public void execute(JobExecutionContext context) throws JobExecutionException |
37 | |
{ |
38 | |
try |
39 | |
{ |
40 | 0 | receiver.poll(); |
41 | |
} |
42 | 0 | catch (Exception e) |
43 | |
{ |
44 | 0 | throw new JobExecutionException(e); |
45 | 0 | } |
46 | |
|
47 | 0 | } |
48 | |
|
49 | |
public void initialise() throws InitialisationException |
50 | |
{ |
51 | |
|
52 | 0 | } |
53 | |
|
54 | |
public void start() throws MuleException |
55 | |
{ |
56 | 0 | InboundEndpoint endpoint = (InboundEndpoint) muleContext.getRegistry().lookupObject(this.inboundPollingEndpointName); |
57 | 0 | AbstractConnector connector = (AbstractConnector) endpoint.getConnector(); |
58 | 0 | receiver = (AbstractPollingMessageReceiver) connector.getReceiver(null, endpoint); |
59 | 0 | receiver.disableNativeScheduling(); |
60 | 0 | } |
61 | |
|
62 | |
public void stop() throws MuleException |
63 | |
{ |
64 | |
|
65 | 0 | } |
66 | |
|
67 | |
public void dispose() |
68 | |
{ |
69 | |
|
70 | 0 | } |
71 | |
|
72 | |
public void setMuleContext(MuleContext context) { |
73 | 0 | this.muleContext = context; |
74 | 0 | } |
75 | |
} |