1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
package org.mule.routing.requestreply; |
8 | |
|
9 | |
import org.mule.api.MuleContext; |
10 | |
import org.mule.api.MuleEvent; |
11 | |
import org.mule.api.MuleException; |
12 | |
import org.mule.api.config.MuleProperties; |
13 | |
import org.mule.api.construct.FlowConstructAware; |
14 | |
import org.mule.api.context.MuleContextAware; |
15 | |
import org.mule.api.endpoint.InboundEndpoint; |
16 | |
import org.mule.api.lifecycle.Disposable; |
17 | |
import org.mule.api.lifecycle.Initialisable; |
18 | |
import org.mule.api.lifecycle.Startable; |
19 | |
import org.mule.api.lifecycle.Stoppable; |
20 | |
import org.mule.api.processor.MessageProcessor; |
21 | |
import org.mule.api.source.MessageSource; |
22 | |
|
23 | 0 | public class SimpleAsyncRequestReplyRequester extends AbstractAsyncRequestReplyRequester |
24 | |
implements Startable, Stoppable |
25 | |
{ |
26 | |
|
27 | |
protected MessageProcessor requestMessageProcessor; |
28 | |
|
29 | |
@Override |
30 | |
protected void sendAsyncRequest(MuleEvent event) throws MuleException |
31 | |
{ |
32 | 0 | setAsyncReplyProperties(event); |
33 | 0 | requestMessageProcessor.process(event); |
34 | 0 | } |
35 | |
|
36 | |
protected void setAsyncReplyProperties(MuleEvent event) throws MuleException |
37 | |
{ |
38 | 0 | event.getMessage().setReplyTo(getReplyTo()); |
39 | 0 | event.getMessage().setOutboundProperty(MuleProperties.MULE_REPLY_TO_REQUESTOR_PROPERTY, |
40 | |
event.getFlowConstruct().getName()); |
41 | 0 | String correlation = event.getFlowConstruct().getMessageInfoMapping().getCorrelationId( |
42 | |
event.getMessage()); |
43 | 0 | event.getMessage().setCorrelationId(correlation); |
44 | 0 | } |
45 | |
|
46 | |
private String getReplyTo() |
47 | |
{ |
48 | 0 | return ((InboundEndpoint) replyMessageSource).getEndpointURI().toString(); |
49 | |
} |
50 | |
|
51 | |
@Override |
52 | |
protected void verifyReplyMessageSource(MessageSource messageSource) |
53 | |
{ |
54 | 0 | if (!(messageSource instanceof InboundEndpoint)) |
55 | |
{ |
56 | 0 | throw new IllegalArgumentException( |
57 | |
"Only an InboundEndpoint reply MessageSource is supported with SimpleAsyncRequestReplyRequester"); |
58 | |
} |
59 | 0 | } |
60 | |
|
61 | |
public void setMessageProcessor(MessageProcessor processor) |
62 | |
{ |
63 | 0 | requestMessageProcessor = processor; |
64 | 0 | } |
65 | |
|
66 | |
@Deprecated |
67 | |
public void setMessageSource(MessageSource source) |
68 | |
{ |
69 | 0 | setReplySource(source); |
70 | 0 | } |
71 | |
|
72 | |
public void start() throws MuleException |
73 | |
{ |
74 | 0 | if (replyMessageSource != null) |
75 | |
{ |
76 | 0 | if (replyMessageSource instanceof FlowConstructAware) |
77 | |
{ |
78 | 0 | ((FlowConstructAware) replyMessageSource).setFlowConstruct(this.flowConstruct); |
79 | |
} |
80 | 0 | if (replyMessageSource instanceof Initialisable) |
81 | |
{ |
82 | 0 | ((Initialisable) replyMessageSource).initialise(); |
83 | |
} |
84 | 0 | if (replyMessageSource instanceof Startable) |
85 | |
{ |
86 | 0 | ((Startable) replyMessageSource).start(); |
87 | |
} |
88 | |
} |
89 | 0 | if (requestMessageProcessor != null) |
90 | |
{ |
91 | 0 | if (requestMessageProcessor instanceof FlowConstructAware) |
92 | |
{ |
93 | 0 | ((FlowConstructAware) requestMessageProcessor).setFlowConstruct(this.flowConstruct); |
94 | |
} |
95 | 0 | if (requestMessageProcessor instanceof Initialisable) |
96 | |
{ |
97 | 0 | ((Initialisable) requestMessageProcessor).initialise(); |
98 | |
} |
99 | 0 | if (requestMessageProcessor instanceof Startable) |
100 | |
{ |
101 | 0 | ((Startable) requestMessageProcessor).start(); |
102 | |
} |
103 | |
} |
104 | 0 | } |
105 | |
|
106 | |
public void stop() throws MuleException |
107 | |
{ |
108 | 0 | if (replyMessageSource != null && replyMessageSource instanceof Stoppable) |
109 | |
{ |
110 | 0 | ((Stoppable) replyMessageSource).stop(); |
111 | |
|
112 | 0 | if (requestMessageProcessor != null && requestMessageProcessor instanceof Stoppable) |
113 | |
{ |
114 | 0 | ((Stoppable) requestMessageProcessor).stop(); |
115 | |
} |
116 | |
} |
117 | 0 | if (requestMessageProcessor != null) |
118 | |
{ |
119 | 0 | if (requestMessageProcessor instanceof Stoppable) |
120 | |
{ |
121 | 0 | ((Stoppable) requestMessageProcessor).stop(); |
122 | |
} |
123 | 0 | if (requestMessageProcessor instanceof Disposable) |
124 | |
{ |
125 | 0 | ((Disposable) requestMessageProcessor).dispose(); |
126 | |
} |
127 | |
} |
128 | 0 | } |
129 | |
|
130 | |
@Override |
131 | |
public void setMuleContext(MuleContext context) |
132 | |
{ |
133 | 0 | super.setMuleContext(context); |
134 | 0 | if (requestMessageProcessor instanceof MuleContextAware) |
135 | |
{ |
136 | 0 | ((MuleContextAware)requestMessageProcessor).setMuleContext(context); |
137 | |
} |
138 | 0 | } |
139 | |
|
140 | |
} |