1 /* 2 * $Id: SingleCorrelatorCallback.java 11567 2008-04-11 13:08:05Z 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 package org.mule.routing; 11 12 import org.mule.api.MuleEvent; 13 import org.mule.api.MuleMessage; 14 import org.mule.api.routing.RoutingException; 15 import org.mule.routing.inbound.EventGroup; 16 17 import org.apache.commons.logging.Log; 18 import org.apache.commons.logging.LogFactory; 19 20 /** 21 * A Correlator that correlates one message at a time 22 */ 23 public class SingleCorrelatorCallback implements EventCorrelatorCallback 24 { 25 /** 26 * logger used by this class 27 */ 28 protected transient final Log logger = LogFactory.getLog(CollectionCorrelatorCallback.class); 29 30 /** 31 * The <code>SingleResponseRouter</code> will return true if the event group 32 * size is 1. If the group size is greater than 1, a warning will be logged. 33 * 34 * @param events 35 * @return true if the event group size is 1 or greater 36 * @see {@link org.mule.routing.response.AbstractResponseAggregator#shouldAggregateEvents(EventGroup)} 37 */ 38 public boolean shouldAggregateEvents(EventGroup events) 39 { 40 if (events.expectedSize() > 1) 41 { 42 logger.warn("CorrelationGroup's expected size is not 1." 43 + " The SingleResponseAggregator will only handle single replyTo events;" 44 + " if there will be multiple events for a single request, " 45 + " use the 'ResponseCorrelationAggregator'"); 46 } 47 48 return (events.size() != 0); 49 } 50 51 /** 52 * The <code>SingleResponseRouter</code> will always return the first event of 53 * an event group. 54 * 55 * @param events the event group for this request 56 * @return an aggregated message 57 * @throws org.mule.api.routing.RoutingException 58 * 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 * @see {@link org.mule.routing.response.AbstractResponseAggregator#aggregateEvents(EventGroup)} 62 */ 63 public MuleMessage aggregateEvents(EventGroup events) throws RoutingException 64 { 65 return ((MuleEvent) events.iterator().next()).getMessage(); 66 } 67 68 public EventGroup createEventGroup(MuleEvent event, Object id) 69 { 70 return new EventGroup(id); 71 } 72 }