KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > mule > routing > response > ResponseCorrelationAggregator


1 /*
2  * $Id: ResponseCorrelationAggregator.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.response;
12
13 import org.mule.routing.inbound.EventGroup;
14 import org.mule.umo.UMOEvent;
15
16 /**
17  * <code>ResponseCorrelationAggregator</code> Correlates one or more events on a
18  * response flow using the Correlation Id to group events.
19  */

20
21 public abstract class ResponseCorrelationAggregator extends AbstractResponseAggregator
22 {
23     /**
24      * Determines if the event group is ready to be aggregated. if the group is ready
25      * to be aggregated (this is entirely up to the application. it could be
26      * determined by volume, last modified time or some oher criteria based on the
27      * last event received)
28      *
29      * @param events
30      * @return true if the event group is ready of aggregation
31      */

32     protected boolean shouldAggregate(EventGroup events)
33     {
34         int expected = events.expectedSize();
35         int current = events.size();
36
37         if (expected == -1)
38         {
39             logger.warn("Correlation Group Size not set, but CorrelationAggregator is being used. Message is being forwarded");
40             return true;
41         }
42
43         if (logger.isDebugEnabled())
44         {
45             logger.debug("Correlation size is " + expected + ", current event group size is " + current
46                          + " for correlation group " + events.getGroupId());
47         }
48
49         return expected == current;
50     }
51
52     /**
53      * Creates the event group with a specific correlation size based on the Mule
54      * Correlation support
55      *
56      * @param id The group id
57      * @param event the current event
58      * @return a new event group of a fixed size
59      */

60     protected EventGroup createEventGroup(Object JavaDoc id, UMOEvent event)
61     {
62         int groupSize = event.getMessage().getCorrelationGroupSize();
63         return new EventGroup(id, groupSize);
64     }
65 }
66
Popular Tags