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.lifecycle.InitialisationException; |
17 | |
import org.mule.config.i18n.CoreMessages; |
18 | |
import org.mule.routing.correlation.CorrelationSequenceComparator; |
19 | |
import org.mule.routing.correlation.EventCorrelatorCallback; |
20 | |
import org.mule.routing.correlation.ResequenceMessagesCorrelatorCallback; |
21 | |
|
22 | |
import java.util.Comparator; |
23 | |
|
24 | |
|
25 | |
|
26 | |
|
27 | |
|
28 | |
|
29 | |
|
30 | |
|
31 | |
|
32 | |
|
33 | |
public class Resequencer extends AbstractAggregator |
34 | |
{ |
35 | |
protected Comparator eventComparator; |
36 | |
|
37 | |
public Resequencer() |
38 | |
{ |
39 | 0 | super(); |
40 | 0 | this.setEventComparator(new CorrelationSequenceComparator()); |
41 | 0 | } |
42 | |
|
43 | |
@Override |
44 | |
public void initialise() throws InitialisationException |
45 | |
{ |
46 | 0 | if (eventComparator == null) |
47 | |
{ |
48 | 0 | throw new InitialisationException(CoreMessages.objectIsNull("eventComparator"), this); |
49 | |
} |
50 | 0 | super.initialise(); |
51 | 0 | } |
52 | |
|
53 | |
public Comparator getEventComparator() |
54 | |
{ |
55 | 0 | return eventComparator; |
56 | |
} |
57 | |
|
58 | |
public void setEventComparator(Comparator eventComparator) |
59 | |
{ |
60 | 0 | this.eventComparator = eventComparator; |
61 | 0 | } |
62 | |
|
63 | |
protected EventCorrelatorCallback getCorrelatorCallback(MuleContext muleContext) |
64 | |
{ |
65 | 0 | return new ResequenceMessagesCorrelatorCallback(getEventComparator(), muleContext); |
66 | |
} |
67 | |
|
68 | |
@Override |
69 | |
public MuleEvent process(MuleEvent event) throws MuleException |
70 | |
{ |
71 | 0 | MuleEvent result = eventCorrelator.process(event); |
72 | 0 | if (result == null) |
73 | |
{ |
74 | 0 | return null; |
75 | |
} |
76 | 0 | MuleEvent last = null; |
77 | 0 | for (MuleEvent muleEvent : (MuleEvent[]) result.getMessage().getPayload()) |
78 | |
{ |
79 | 0 | last = processNext(muleEvent); |
80 | |
} |
81 | |
|
82 | 0 | return last; |
83 | |
} |
84 | |
|
85 | |
} |