KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > mule > routing > inbound > CorrelationEventResequencer


1 /*
2  * $Id: CorrelationEventResequencer.java 3798 2006-11-04 04:07:14Z aperepel $
3  * --------------------------------------------------------------------------------------
4  * Copyright (c) MuleSource, Inc. All rights reserved. http://www.mulesource.com
5  *
6  * The software in this package is published under the terms of the MuleSource MPL
7  * license, a copy of which has been included with this distribution in the
8  * LICENSE.txt file.
9  */

10
11 package org.mule.routing.inbound;
12
13 import org.mule.umo.UMOEvent;
14
15 import java.util.Comparator JavaDoc;
16
17 /**
18  * <code>CorrelationEventResequencer</code> is used to resequence events according
19  * to their dispatch sequence in the correlation group. When the MessageSplitter
20  * router splits an event it assigns a correlation sequence to the individual message
21  * parts so that another router such as the <i>CorrelationEventResequencer</i> can
22  * receive the parts and reorder them or merge them.
23  *
24  * @author <a HREF="mailto:ross.mason@symphonysoft.com">Ross Mason</a>
25  * @version $Revision: 3798 $
26  */

27 public class CorrelationEventResequencer extends AbstractEventResequencer
28 {
29     public CorrelationEventResequencer()
30     {
31         setComparator(new CorrelationSequenceComparator());
32     }
33
34     protected boolean shouldResequence(EventGroup events)
35     {
36         UMOEvent event = (UMOEvent)events.iterator().next();
37         int size = event.getMessage().getCorrelationGroupSize();
38         if (size == -1)
39         {
40             logger.warn("Correlation Group Size not set, but CorrelationResequencer is being used. This can cause messages to be held indefinitely");
41         }
42         return size == events.size();
43     }
44
45     private class CorrelationSequenceComparator implements Comparator JavaDoc
46     {
47         public int compare(Object JavaDoc o1, Object JavaDoc o2)
48         {
49             int val1 = ((UMOEvent)o1).getMessage().getCorrelationSequence();
50             int val2 = ((UMOEvent)o2).getMessage().getCorrelationSequence();
51             if (val1 == val2)
52             {
53                 return 0;
54             }
55             else if (val1 > val2)
56             {
57                 return 1;
58             }
59             else
60             {
61                 return -1;
62             }
63         }
64     }
65 }
66
Popular Tags