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