1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
package org.mule.endpoint; |
12 | |
|
13 | |
import org.mule.MessageExchangePattern; |
14 | |
import org.mule.api.MuleContext; |
15 | |
import org.mule.api.MuleException; |
16 | |
import org.mule.api.MuleMessage; |
17 | |
import org.mule.api.construct.FlowConstruct; |
18 | |
import org.mule.api.construct.FlowConstructAware; |
19 | |
import org.mule.api.context.MuleContextAware; |
20 | |
import org.mule.api.endpoint.EndpointMessageProcessorChainFactory; |
21 | |
import org.mule.api.endpoint.EndpointURI; |
22 | |
import org.mule.api.endpoint.InboundEndpoint; |
23 | |
import org.mule.api.lifecycle.Initialisable; |
24 | |
import org.mule.api.lifecycle.LifecycleException; |
25 | |
import org.mule.api.lifecycle.Startable; |
26 | |
import org.mule.api.lifecycle.Stoppable; |
27 | |
import org.mule.api.processor.MessageProcessor; |
28 | |
import org.mule.api.retry.RetryPolicyTemplate; |
29 | |
import org.mule.api.transaction.TransactionConfig; |
30 | |
import org.mule.api.transport.Connector; |
31 | |
import org.mule.config.MuleManifest; |
32 | |
import org.mule.config.i18n.CoreMessages; |
33 | |
|
34 | |
import java.beans.ExceptionListener; |
35 | |
import java.util.List; |
36 | |
import java.util.Map; |
37 | |
|
38 | |
public class DefaultInboundEndpoint extends AbstractEndpoint implements InboundEndpoint |
39 | |
{ |
40 | |
private static final long serialVersionUID = -4752772777414636142L; |
41 | |
private MessageProcessor listener; |
42 | |
private FlowConstruct flowConstruct; |
43 | |
private ExceptionListener exceptionListener; |
44 | |
|
45 | |
public DefaultInboundEndpoint(Connector connector, |
46 | |
EndpointURI endpointUri, |
47 | |
String name, |
48 | |
Map properties, |
49 | |
TransactionConfig transactionConfig, |
50 | |
boolean deleteUnacceptedMessage, |
51 | |
MessageExchangePattern messageExchangePattern, |
52 | |
int responseTimeout, |
53 | |
String initialState, |
54 | |
String endpointEncoding, |
55 | |
String endpointBuilderName, |
56 | |
MuleContext muleContext, |
57 | |
RetryPolicyTemplate retryPolicyTemplate, |
58 | |
EndpointMessageProcessorChainFactory messageProcessorsFactory, |
59 | |
List <MessageProcessor> messageProcessors, |
60 | |
List <MessageProcessor> responseMessageProcessors, |
61 | |
boolean disableTransportTransformer, |
62 | |
String mimeType) |
63 | |
{ |
64 | 0 | super(connector, endpointUri, name, properties, |
65 | |
transactionConfig, deleteUnacceptedMessage, |
66 | |
messageExchangePattern, responseTimeout, initialState, endpointEncoding, |
67 | |
endpointBuilderName, muleContext, retryPolicyTemplate, messageProcessorsFactory, |
68 | |
messageProcessors, responseMessageProcessors, disableTransportTransformer, |
69 | |
mimeType); |
70 | 0 | } |
71 | |
|
72 | |
public MuleMessage request(long timeout) throws Exception |
73 | |
{ |
74 | 0 | if (getConnector() != null) |
75 | |
{ |
76 | 0 | return getConnector().request(this, timeout); |
77 | |
} |
78 | |
else |
79 | |
{ |
80 | |
|
81 | |
|
82 | 0 | throw new IllegalStateException("The connector on the endpoint: " + toString() |
83 | |
+ " is null. Please contact " + MuleManifest.getDevListEmail()); |
84 | |
} |
85 | |
} |
86 | |
|
87 | |
public void setListener(MessageProcessor listener) |
88 | |
{ |
89 | 0 | this.listener = listener; |
90 | 0 | } |
91 | |
|
92 | |
public void start() throws MuleException |
93 | |
{ |
94 | |
try |
95 | |
{ |
96 | 0 | if (getMessageProcessorChain(flowConstruct) instanceof Startable) |
97 | |
{ |
98 | 0 | ((Startable) getMessageProcessorChain(flowConstruct)).start(); |
99 | |
} |
100 | 0 | getConnector().registerListener(this, getMessageProcessorChain(flowConstruct), flowConstruct); |
101 | |
} |
102 | 0 | catch (Exception e) |
103 | |
{ |
104 | 0 | throw new LifecycleException(CoreMessages.failedToStartInboundEndpoint(this), e, this); |
105 | 0 | } |
106 | 0 | } |
107 | |
|
108 | |
public void stop() throws MuleException |
109 | |
{ |
110 | |
try |
111 | |
{ |
112 | 0 | getConnector().unregisterListener(this, flowConstruct); |
113 | 0 | if (getMessageProcessorChain(flowConstruct) instanceof Stoppable) |
114 | |
{ |
115 | 0 | ((Stoppable) getMessageProcessorChain(flowConstruct)).stop(); |
116 | |
} |
117 | |
} |
118 | 0 | catch (Exception e) |
119 | |
{ |
120 | 0 | throw new LifecycleException(CoreMessages.failedToStartInboundEndpoint(this), e, this); |
121 | 0 | } |
122 | 0 | } |
123 | |
|
124 | |
@Override |
125 | |
public MessageProcessor createMessageProcessorChain(FlowConstruct flowContruct) throws MuleException |
126 | |
{ |
127 | 0 | EndpointMessageProcessorChainFactory factory = getMessageProcessorsFactory(); |
128 | 0 | MessageProcessor processorChain = factory.createInboundMessageProcessorChain(this, flowConstruct, |
129 | |
listener); |
130 | 0 | if (processorChain instanceof MuleContextAware) |
131 | |
{ |
132 | 0 | ((MuleContextAware) processorChain).setMuleContext(getMuleContext()); |
133 | |
} |
134 | 0 | if (processorChain instanceof FlowConstructAware) |
135 | |
{ |
136 | 0 | ((FlowConstructAware) processorChain).setFlowConstruct(flowContruct); |
137 | |
} |
138 | 0 | if (processorChain instanceof Initialisable) |
139 | |
{ |
140 | 0 | ((Initialisable) processorChain).initialise(); |
141 | |
} |
142 | 0 | return processorChain; |
143 | |
} |
144 | |
|
145 | |
public void setFlowConstruct(FlowConstruct flowConstruct) |
146 | |
{ |
147 | 0 | this.flowConstruct = flowConstruct; |
148 | 0 | } |
149 | |
|
150 | |
public ExceptionListener getExceptionListener() |
151 | |
{ |
152 | 0 | return exceptionListener; |
153 | |
} |
154 | |
|
155 | |
public void setExceptionListener(ExceptionListener exceptionListener) |
156 | |
{ |
157 | 0 | this.exceptionListener = exceptionListener; |
158 | 0 | } |
159 | |
|
160 | |
@Override |
161 | |
public void dispose() |
162 | |
{ |
163 | 0 | super.dispose(); |
164 | 0 | this.flowConstruct = null; |
165 | 0 | this.listener = null; |
166 | 0 | } |
167 | |
|
168 | |
@Override |
169 | |
public int hashCode() |
170 | |
{ |
171 | |
|
172 | |
|
173 | |
|
174 | |
|
175 | 0 | return System.identityHashCode(this); |
176 | |
} |
177 | |
} |