{
throw new RoutingException(event, timeoutMessageProcessor, e);
}
// check for an existing group first
EventGroup group;
try
{
group = this.getEventGroup(groupId);
}
catch (ObjectStoreException e)
{
throw new RoutingException(event, timeoutMessageProcessor, e);
}
// does the group exist?
if (group == null)
{
// ..apparently not, so create a new one & add it
try
{
group = this.addEventGroup(callback.createEventGroup(event, groupId));
}
catch (ObjectStoreException e)
{
throw new RoutingException(event, timeoutMessageProcessor, e);
}
}
// ensure that only one thread at a time evaluates this EventGroup
synchronized (groupsLock)
{
if (logger.isDebugEnabled())
{
logger.debug("Adding event to aggregator group: " + groupId);
}
// add the incoming event to the group
try
{
group.addEvent(event);
}
catch (ObjectStoreException e)
{
throw new RoutingException(event, timeoutMessageProcessor, e);
}
// check to see if the event group is ready to be aggregated
if (callback.shouldAggregateEvents(group))
{
// create the response event
MuleEvent returnEvent = callback.aggregateEvents(group);
returnEvent.getMessage().setCorrelationId(groupId);
String rootId = group.getCommonRootId();
if (rootId != null)
{
returnEvent.getMessage().setMessageRootId(rootId);
}
// remove the eventGroup as no further message will be received
// for this group once we aggregate
try
{
this.removeEventGroup(group);
group.clear();
}
catch (ObjectStoreException e)
{
throw new RoutingException(event, timeoutMessageProcessor, e);
}