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