Package org.mule.api.routing

Examples of org.mule.api.routing.RoutingException


                // ignore
            }
        }
        if (groupId == null || groupId.equals("-1"))
        {
            throw new RoutingException(CoreMessages.noCorrelationId(), event, timeoutMessageProcessor);
        }

        // spinloop for the EventGroup lookup
        while (true)
        {
            try
            {
                if (isGroupAlreadyProcessed(groupId))
                {
                    if (logger.isDebugEnabled())
                    {
                        logger.debug("An event was received for an event group that has already been processed, "
                                     + "this is probably because the async-reply timed out. Correlation Id is: "
                                     + groupId + ". Dropping event");
                    }
                    // Fire a notification to say we received this message
                    muleContext.fireNotification(new RoutingNotification(event.getMessage(),
                                                                         event.getMessageSourceURI().toString(),
                                                                         RoutingNotification.MISSED_AGGREGATION_GROUP_EVENT));
                    return null;
                }
            }
            catch (ObjectStoreException e)
            {
                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);
                    }

                    return returnEvent;
                }
                else
View Full Code Here

TOP

Related Classes of org.mule.api.routing.RoutingException

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.