View Javadoc

1   /*
2    * $Id: CorrelationEventResequencer.java 10489 2008-01-23 17:53:38Z dfeist $
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 CPAL v1.0
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.api.MuleEvent;
14  
15  
16  /**
17   * <code>CorrelationEventResequencer</code> is used to resequence events according
18   * to their dispatch sequence in the correlation group. When the MessageSplitter
19   * router splits an event it assigns a correlation sequence to the individual message
20   * parts so that another router such as the <i>CorrelationEventResequencer</i> can
21   * receive the parts and reorder or merge them.
22   */
23  public class CorrelationEventResequencer extends AbstractEventResequencer
24  {
25  
26      public CorrelationEventResequencer()
27      {
28          super();
29          this.setComparator(new CorrelationSequenceComparator());
30      }
31  
32      protected boolean shouldResequenceEvents(EventGroup events)
33      {
34          MuleEvent event = (MuleEvent) events.iterator().next();
35  
36          if (event == null)
37          {
38              // nothing to resequence
39              return false;
40          }
41  
42          int size = event.getMessage().getCorrelationGroupSize();
43          if (size == -1)
44          {
45              logger.warn("Correlation Group Size not set, but CorrelationResequencer is being used.  This can cause messages to be held indefinitely");
46          }
47  
48          return size == events.size();
49      }
50  
51  }