1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
package org.mule.routing.outbound; |
12 | |
|
13 | |
import org.mule.api.MuleException; |
14 | |
import org.mule.api.MuleMessage; |
15 | |
import org.mule.api.MuleSession; |
16 | |
import org.mule.api.endpoint.ImmutableEndpoint; |
17 | |
import org.mule.api.endpoint.OutboundEndpoint; |
18 | |
import org.mule.api.routing.CouldNotRouteOutboundMessageException; |
19 | |
import org.mule.api.routing.RoutePathNotFoundException; |
20 | |
import org.mule.api.routing.RoutingException; |
21 | |
import org.mule.config.i18n.CoreMessages; |
22 | |
|
23 | |
|
24 | |
|
25 | |
|
26 | |
|
27 | |
|
28 | 2 | public class MulticastingRouter extends FilteringOutboundRouter |
29 | |
{ |
30 | |
|
31 | |
public MuleMessage route(MuleMessage message, MuleSession session, boolean synchronous) |
32 | |
throws RoutingException |
33 | |
{ |
34 | 4 | MuleMessage result = null; |
35 | 4 | if (endpoints == null || endpoints.size() == 0) |
36 | |
{ |
37 | 0 | throw new RoutePathNotFoundException(CoreMessages.noEndpointsForRouter(), message, null); |
38 | |
} |
39 | 4 | if (enableCorrelation != ENABLE_CORRELATION_NEVER) |
40 | |
{ |
41 | 4 | boolean correlationSet = message.getCorrelationId() != null; |
42 | 4 | if (correlationSet && (enableCorrelation == ENABLE_CORRELATION_IF_NOT_SET)) |
43 | |
{ |
44 | 0 | logger.debug("CorrelationId is already set, not setting Correlation group size"); |
45 | |
} |
46 | |
else |
47 | |
{ |
48 | |
|
49 | 4 | message.setCorrelationGroupSize(endpoints.size()); |
50 | |
} |
51 | |
} |
52 | |
|
53 | |
try |
54 | |
{ |
55 | |
OutboundEndpoint endpoint; |
56 | 4 | synchronized (endpoints) |
57 | |
{ |
58 | 12 | for (int i = 0; i < endpoints.size(); i++) |
59 | |
{ |
60 | 8 | endpoint = (OutboundEndpoint) endpoints.get(i); |
61 | 8 | if (synchronous) |
62 | |
{ |
63 | |
|
64 | 4 | if (result == null) |
65 | |
{ |
66 | 2 | result = send(session, message, endpoint); |
67 | |
} |
68 | |
else |
69 | |
{ |
70 | 2 | String def = (String) endpoint.getProperties().get("default"); |
71 | 2 | if (def != null) |
72 | |
{ |
73 | 0 | result = send(session, message, endpoint); |
74 | |
} |
75 | |
else |
76 | |
{ |
77 | 2 | send(session, message, endpoint); |
78 | |
} |
79 | 2 | } |
80 | |
} |
81 | |
else |
82 | |
{ |
83 | 4 | dispatch(session, message, endpoint); |
84 | |
} |
85 | |
} |
86 | 4 | } |
87 | |
} |
88 | 0 | catch (MuleException e) |
89 | |
{ |
90 | 0 | throw new CouldNotRouteOutboundMessageException(message, (ImmutableEndpoint) endpoints.get(0), e); |
91 | 4 | } |
92 | 4 | return result; |
93 | |
} |
94 | |
} |