KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * $Id: SingleResponseRouter.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 import org.mule.umo.UMOMessage;
16 import org.mule.umo.routing.RoutingException;
17
18 /**
19  * Handles single event responses from a replyTo address. If multiple responses will
20  * be received for a single invocation the ResponseCorrelationaggregator should be
21  * used.
22  *
23  * @author <a HREF="mailto:ross.mason@symphonysoft.com">Ross Mason</a>
24  * @version $Revision: 3798 $
25  */

26 public class SingleResponseRouter extends AbstractResponseAggregator
27 {
28     /**
29      * Determines if the event group is ready to be aggregated. if the group is ready
30      * to be aggregated (this is entirely up to the application. it could be
31      * determined by volume, last modified time or some oher criteria based on the
32      * last event received) Because this is a Single response router it will return
33      * true if the event group size is 1. It will raise a warning if the event Group
34      * size is greater than 1.
35      *
36      * @param events
37      * @return true if the event group size is 1 or greater
38      */

39     protected boolean shouldAggregate(EventGroup events)
40     {
41         int size = events.expectedSize();
42         if (size > 1)
43         {
44             logger.warn("Correlation Group Size is not 1. The SingleResponse Aggregator will only handle single replyTo events for a response router. If there will be multiple events for a single request use the 'ResponseCorrelationAggregator'");
45         }
46         return true;
47     }
48
49     /**
50      * This method is invoked if the shouldAggregate method is called and returns
51      * true. Once this method returns an aggregated message the event group is
52      * removed from the router Because this is a Single response router it returns
53      * the first event in the event group. It will raise a warning if the event Group
54      * size is greater than 1.
55      *
56      * @param events the event group for this request
57      * @return an aggregated message
58      * @throws org.mule.umo.routing.RoutingException if the aggregation fails. in
59      * this scenario the whole event group is removed and passed to the
60      * exception handler for this componenet
61      */

62     protected UMOMessage aggregateEvents(EventGroup events) throws RoutingException
63     {
64         return ((UMOEvent)events.iterator().next()).getMessage();
65     }
66
67 }
68
Popular Tags