Search in sources :

Example 1 with AggregationException

use of org.mule.runtime.core.internal.routing.AggregationException in project mule by mulesoft.

the class ResequenceCorrelatorCallback method aggregateEvents.

/**
 * This method is invoked if the shouldAggregate method is called and returns true. Once this method returns an aggregated
 * message, the event group is removed from the router.
 *
 * @param events the event group for this request
 * @return an aggregated message
 * @throws AggregationException if the aggregation fails. in this scenario the whole event group is removed and passed to the
 *         exception handler for this componenet
 */
@Override
public CoreEvent aggregateEvents(EventGroup events) throws AggregationException {
    CoreEvent[] results;
    try {
        results = events.toArray(false);
    } catch (ObjectStoreException e) {
        throw new AggregationException(events, null, e);
    }
    Arrays.sort(results, eventComparator);
    // Mule Message to pass back
    return CoreEvent.builder(results[0]).message(of(results)).build();
}
Also used : ObjectStoreException(org.mule.runtime.api.store.ObjectStoreException) AggregationException(org.mule.runtime.core.internal.routing.AggregationException) CoreEvent(org.mule.runtime.core.api.event.CoreEvent)

Example 2 with AggregationException

use of org.mule.runtime.core.internal.routing.AggregationException in project mule by mulesoft.

the class ResequenceMessagesCorrelatorCallback method aggregateEvents.

/**
 * This method is invoked if the shouldAggregate method is called and returns true. Once this method returns an aggregated
 * message, the event group is removed from the router.
 *
 * @param events the event group for this request
 * @return an aggregated message
 * @throws AggregationException if the aggregation fails. in this scenario the whole event group
 *         is removed and passed to the exception handler for this componenet
 */
@Override
public CoreEvent aggregateEvents(EventGroup events) throws AggregationException {
    CoreEvent[] results;
    try {
        results = (events == null) ? new CoreEvent[0] : events.toArray(false);
    } catch (ObjectStoreException e) {
        throw new AggregationException(events, null, e);
    }
    Arrays.sort(results, eventComparator);
    // message
    for (int i = 0; i < results.length; i++) {
        results[i] = CoreEvent.builder(results[i]).build();
    }
    return CoreEvent.builder(results[0]).message(of(results)).build();
}
Also used : ObjectStoreException(org.mule.runtime.api.store.ObjectStoreException) AggregationException(org.mule.runtime.core.internal.routing.AggregationException) CoreEvent(org.mule.runtime.core.api.event.CoreEvent)

Aggregations

ObjectStoreException (org.mule.runtime.api.store.ObjectStoreException)2 CoreEvent (org.mule.runtime.core.api.event.CoreEvent)2 AggregationException (org.mule.runtime.core.internal.routing.AggregationException)2