1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
package org.mule.routing; |
12 | |
|
13 | |
import org.mule.api.MuleContext; |
14 | |
import org.mule.api.MuleEvent; |
15 | |
import org.mule.api.MuleException; |
16 | |
import org.mule.api.construct.FlowConstruct; |
17 | |
import org.mule.api.construct.FlowConstructAware; |
18 | |
import org.mule.api.context.MuleContextAware; |
19 | |
import org.mule.api.lifecycle.Initialisable; |
20 | |
import org.mule.api.lifecycle.InitialisationException; |
21 | |
import org.mule.api.routing.Aggregator; |
22 | |
import org.mule.api.routing.MessageInfoMapping; |
23 | |
import org.mule.api.service.Service; |
24 | |
import org.mule.processor.AbstractInterceptingMessageProcessor; |
25 | |
import org.mule.routing.correlation.EventCorrelator; |
26 | |
import org.mule.routing.correlation.EventCorrelatorCallback; |
27 | |
|
28 | |
import javax.resource.spi.work.WorkException; |
29 | |
|
30 | |
|
31 | |
|
32 | |
|
33 | |
|
34 | |
|
35 | |
|
36 | |
|
37 | 0 | public abstract class AbstractAggregator extends AbstractInterceptingMessageProcessor |
38 | |
implements Initialisable, MuleContextAware, FlowConstructAware, Aggregator |
39 | |
{ |
40 | |
|
41 | |
protected EventCorrelator eventCorrelator; |
42 | |
protected MuleContext muleContext; |
43 | |
protected FlowConstruct flowConstruct; |
44 | |
protected MessageInfoMapping messageInfoMapping; |
45 | |
|
46 | 0 | private long timeout = 0; |
47 | 0 | private boolean failOnTimeout = true; |
48 | |
|
49 | |
public void initialise() throws InitialisationException |
50 | |
{ |
51 | 0 | if (messageInfoMapping == null) |
52 | |
{ |
53 | 0 | messageInfoMapping = flowConstruct.getMessageInfoMapping(); |
54 | |
} |
55 | |
|
56 | 0 | eventCorrelator = new EventCorrelator(getCorrelatorCallback(muleContext), next, messageInfoMapping, |
57 | |
muleContext); |
58 | |
|
59 | |
|
60 | 0 | if (flowConstruct instanceof Service) |
61 | |
{ |
62 | 0 | Service service = (Service) flowConstruct; |
63 | 0 | if (service.getAsyncReplyMessageSource().getMessageProcessors().contains(this)) |
64 | |
{ |
65 | 0 | failOnTimeout = service.getAsyncReplyMessageSource().isFailOnTimeout(); |
66 | |
} |
67 | |
} |
68 | |
|
69 | 0 | eventCorrelator.setTimeout(timeout); |
70 | 0 | eventCorrelator.setFailOnTimeout(isFailOnTimeout()); |
71 | 0 | if (timeout != 0) |
72 | |
{ |
73 | |
try |
74 | |
{ |
75 | 0 | eventCorrelator.enableTimeoutMonitor(); |
76 | |
} |
77 | 0 | catch (WorkException e) |
78 | |
{ |
79 | 0 | throw new InitialisationException(e, this); |
80 | 0 | } |
81 | |
} |
82 | 0 | } |
83 | |
|
84 | |
public void setMuleContext(MuleContext context) |
85 | |
{ |
86 | 0 | this.muleContext = context; |
87 | 0 | } |
88 | |
|
89 | |
protected abstract EventCorrelatorCallback getCorrelatorCallback(MuleContext muleContext); |
90 | |
|
91 | |
public MuleEvent process(MuleEvent event) throws MuleException |
92 | |
{ |
93 | 0 | MuleEvent result = eventCorrelator.process(event); |
94 | 0 | if (result == null) |
95 | |
{ |
96 | 0 | return null; |
97 | |
} |
98 | 0 | return processNext(result); |
99 | |
} |
100 | |
|
101 | |
public void expireAggregation(String groupId) |
102 | |
{ |
103 | 0 | eventCorrelator.forceGroupExpiry(groupId); |
104 | 0 | } |
105 | |
|
106 | |
public long getTimeout() |
107 | |
{ |
108 | 0 | return timeout; |
109 | |
} |
110 | |
|
111 | |
public void setTimeout(long timeout) |
112 | |
{ |
113 | 0 | this.timeout = timeout; |
114 | 0 | } |
115 | |
|
116 | |
public boolean isFailOnTimeout() |
117 | |
{ |
118 | 0 | return failOnTimeout; |
119 | |
} |
120 | |
|
121 | |
public void setFailOnTimeout(boolean failOnTimeout) |
122 | |
{ |
123 | 0 | this.failOnTimeout = failOnTimeout; |
124 | 0 | } |
125 | |
|
126 | |
public void setFlowConstruct(FlowConstruct flowConstruct) |
127 | |
{ |
128 | 0 | this.flowConstruct = flowConstruct; |
129 | 0 | } |
130 | |
|
131 | |
public void setMessageInfoMapping(MessageInfoMapping messageInfoMapping) |
132 | |
{ |
133 | 0 | this.messageInfoMapping = messageInfoMapping; |
134 | 0 | } |
135 | |
} |