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 public abstract class AbstractEventAggregator extends SelectiveConsumer
29 {
30 private EventCorrelator eventCorrelator;
31
32 private int timeout = 0;
33
34
35 public void initialise() throws InitialisationException
36 {
37 eventCorrelator = new EventCorrelator(getCorrelatorCallback(), getMessageInfoMapping(), muleContext);
38 if(timeout != 0)
39 {
40 eventCorrelator.setTimeout(timeout);
41 try
42 {
43 eventCorrelator.enableTimeoutMonitor();
44 }
45 catch (WorkException e)
46 {
47 throw new InitialisationException(e, this);
48 }
49 }
50 super.initialise();
51 }
52
53 protected abstract EventCorrelatorCallback getCorrelatorCallback();
54
55
56
57 public MuleEvent[] process(MuleEvent event) throws MessagingException
58 {
59 MuleMessage msg = eventCorrelator.process(event);
60 if(msg==null)
61 {
62 return null;
63 }
64 MuleEvent[] result = new MuleEvent[]{new DefaultMuleEvent(msg, event)};
65 return result;
66 }
67
68 public int getTimeout()
69 {
70 return timeout;
71 }
72
73 public void setTimeout(int timeout)
74 {
75 this.timeout = timeout;
76 }
77 }