1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
package org.mule.routing.inbound; |
12 | |
|
13 | |
import org.mule.DefaultMuleEvent; |
14 | |
import org.mule.api.MessagingException; |
15 | |
import org.mule.api.MuleEvent; |
16 | |
import org.mule.api.MuleMessage; |
17 | |
import org.mule.api.lifecycle.InitialisationException; |
18 | |
import org.mule.routing.EventCorrelator; |
19 | |
import org.mule.routing.EventCorrelatorCallback; |
20 | |
|
21 | |
import javax.resource.spi.work.WorkException; |
22 | |
|
23 | |
|
24 | |
|
25 | |
|
26 | |
|
27 | |
|
28 | 2 | public abstract class AbstractEventAggregator extends SelectiveConsumer |
29 | |
{ |
30 | |
private EventCorrelator eventCorrelator; |
31 | |
|
32 | 2 | private int timeout = 0; |
33 | |
|
34 | |
|
35 | |
public void initialise() throws InitialisationException |
36 | |
{ |
37 | 2 | eventCorrelator = new EventCorrelator(getCorrelatorCallback(), getMessageInfoMapping(), muleContext); |
38 | 2 | if(timeout != 0) |
39 | |
{ |
40 | 0 | eventCorrelator.setTimeout(timeout); |
41 | |
try |
42 | |
{ |
43 | 0 | eventCorrelator.enableTimeoutMonitor(); |
44 | |
} |
45 | 0 | catch (WorkException e) |
46 | |
{ |
47 | 0 | throw new InitialisationException(e, this); |
48 | 0 | } |
49 | |
} |
50 | 2 | super.initialise(); |
51 | 2 | } |
52 | |
|
53 | |
protected abstract EventCorrelatorCallback getCorrelatorCallback(); |
54 | |
|
55 | |
|
56 | |
|
57 | |
public MuleEvent[] process(MuleEvent event) throws MessagingException |
58 | |
{ |
59 | 6 | MuleMessage msg = eventCorrelator.process(event); |
60 | 6 | if(msg==null) |
61 | |
{ |
62 | 4 | return null; |
63 | |
} |
64 | 2 | MuleEvent[] result = new MuleEvent[]{new DefaultMuleEvent(msg, event)}; |
65 | 2 | return result; |
66 | |
} |
67 | |
|
68 | |
public int getTimeout() |
69 | |
{ |
70 | 0 | return timeout; |
71 | |
} |
72 | |
|
73 | |
public void setTimeout(int timeout) |
74 | |
{ |
75 | 0 | this.timeout = timeout; |
76 | 0 | } |
77 | |
} |