Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
SingleResponseRouter |
|
| 1.5;1.5 |
1 | /* | |
2 | * $Id: SingleResponseRouter.java 7963 2007-08-21 08:53:15Z dirk.olmes $ | |
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.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 {@link ResponseCorrelationAggregator} | |
21 | * should be used. | |
22 | */ | |
23 | 0 | public class SingleResponseRouter extends AbstractResponseAggregator |
24 | { | |
25 | /** | |
26 | * The <code>SingleResponseRouter</code> will return true if the event group | |
27 | * size is 1. If the group size is greater than 1, a warning will be logged. | |
28 | * | |
29 | * @param events | |
30 | * @return true if the event group size is 1 or greater | |
31 | * @see {@link AbstractResponseAggregator#shouldAggregateEvents(EventGroup)} | |
32 | */ | |
33 | protected boolean shouldAggregateEvents(EventGroup events) | |
34 | { | |
35 | 0 | if (events.expectedSize() > 1) |
36 | { | |
37 | 0 | logger.warn("CorrelationGroup's expected size is not 1." |
38 | + " The SingleResponseAggregator will only handle single replyTo events;" | |
39 | + " if there will be multiple events for a single request, " | |
40 | + " use the 'ResponseCorrelationAggregator'"); | |
41 | } | |
42 | ||
43 | 0 | return (events.size() != 0); |
44 | } | |
45 | ||
46 | /** | |
47 | * The <code>SingleResponseRouter</code> will always return the first event of | |
48 | * an event group. | |
49 | * | |
50 | * @param events the event group for this request | |
51 | * @return an aggregated message | |
52 | * @throws org.mule.umo.routing.RoutingException if the aggregation fails. in | |
53 | * this scenario the whole event group is removed and passed to the | |
54 | * exception handler for this componenet | |
55 | * @see {@link AbstractResponseAggregator#aggregateEvents(EventGroup)} | |
56 | */ | |
57 | protected UMOMessage aggregateEvents(EventGroup events) throws RoutingException | |
58 | { | |
59 | 0 | return ((UMOEvent) events.iterator().next()).getMessage(); |
60 | } | |
61 | ||
62 | } |