{
removeEventGroup(group);
}
catch (ObjectStoreException e)
{
throw new MessagingException(group.getMessageCollectionEvent(), e);
}
if (isFailOnTimeout())
{
MuleMessageCollection messageCollection;
try
{
messageCollection = group.toMessageCollection();
}
catch (ObjectStoreException e)
{
throw new MessagingException(group.getMessageCollectionEvent(), e);
}
muleContext.fireNotification(new RoutingNotification(messageCollection, null,
RoutingNotification.CORRELATION_TIMEOUT));
MuleEvent groupCollectionEvent = group.getMessageCollectionEvent();
try
{
group.clear();
}
catch (ObjectStoreException e)
{
logger.warn("Failed to clear group with id " + group.getGroupId()
+ " since underlying ObjectStore threw Exception:" + e.getMessage());
}
throw new CorrelationTimeoutException(CoreMessages.correlationTimedOut(group.getGroupId()),
groupCollectionEvent);
}
else
{
if (logger.isDebugEnabled())
{
logger.debug(MessageFormat.format(
"Aggregator expired, but ''failOnTimeOut'' is false. Forwarding {0} events out of {1} "
+ "total for group ID: {2}", group.size(), group.expectedSize(),
group.getGroupId()));
}
try
{
if (!(group.getCreated() + groupTimeToLive < System.currentTimeMillis()))
{
MuleEvent newEvent = callback.aggregateEvents(group);
group.clear();
newEvent.getMessage().setCorrelationId(group.getGroupId().toString());
if (!expiredAndDispatchedGroups.contains((Serializable) group.getGroupId()))
{
// TODO which use cases would need a sync reply event
// returned?
if (timeoutMessageProcessor != null)
{
timeoutMessageProcessor.process(newEvent);
}
else
{
final FlowConstruct service = group.toArray(false)[0].getFlowConstruct();
if (!(service instanceof Service))
{
throw new UnsupportedOperationException(
"EventAggregator is only supported with Service");
}
((Service) service).dispatchEvent(newEvent);
}
expiredAndDispatchedGroups.store((Serializable) group.getGroupId(),
group.getCreated());
}
else
{
logger.warn(MessageFormat.format("Discarding group {0}", group.getGroupId()));
}
}
}
catch (MessagingException me)
{
throw me;
}
catch (Exception e)
{
throw new MessagingException(group.getMessageCollectionEvent(), e);
}
}
}