use of org.mule.runtime.api.store.ObjectStoreException in project mule by mulesoft.
the class EventCorrelator method handleGroupExpiry.
protected void handleGroupExpiry(EventGroup group) throws MuleException {
try {
removeEventGroup(group);
} catch (ObjectStoreException e) {
throw new DefaultMuleException(e);
}
if (isFailOnTimeout()) {
CoreEvent messageCollectionEvent = group.getMessageCollectionEvent();
notificationFirer.dispatch(new RoutingNotification(messageCollectionEvent.getMessage(), null, CORRELATION_TIMEOUT));
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(correlationTimedOut(group.getGroupId()));
} 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().map(v -> v.toString()).orElse(NOT_SET), group.getGroupId()));
}
try {
if (!(group.getCreated() + DAYS.toMillis(1) < currentTimeMillis())) {
CoreEvent newEvent = CoreEvent.builder(callback.aggregateEvents(group)).build();
group.clear();
if (!correlatorStore.contains((String) group.getGroupId(), getExpiredAndDispatchedPartitionKey())) {
// returned?
if (timeoutMessageProcessor != null) {
processToApply(newEvent, timeoutMessageProcessor, false, empty());
} else {
throw new MessagingException(createStaticMessage(MessageFormat.format("Group {0} timed out, but no timeout message processor was " + "configured.", group.getGroupId())), newEvent);
}
correlatorStore.store((String) group.getGroupId(), group.getCreated(), getExpiredAndDispatchedPartitionKey());
} else {
logger.warn(MessageFormat.format("Discarding group {0}", group.getGroupId()));
}
}
} catch (MessagingException me) {
throw me;
} catch (Exception e) {
throw new MessagingException(group.getMessageCollectionEvent(), e);
}
}
}
use of org.mule.runtime.api.store.ObjectStoreException in project mule by mulesoft.
the class EventCorrelator method getEventGroup.
protected EventGroup getEventGroup(String groupId) throws ObjectStoreException {
try {
EventGroup eventGroup = (EventGroup) correlatorStore.retrieve(groupId, getEventGroupsPartitionKey());
if (!eventGroup.isInitialised()) {
try {
DeserializationPostInitialisable.Implementation.init(eventGroup, muleContext);
} catch (Exception e) {
throw new ObjectStoreException(e);
}
}
eventGroup.initEventsStore(correlatorStore);
return eventGroup;
} catch (ObjectDoesNotExistException e) {
return null;
}
}
use of org.mule.runtime.api.store.ObjectStoreException 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();
}
use of org.mule.runtime.api.store.ObjectStoreException in project mule by mulesoft.
the class MessageChunkAggregator method getCorrelatorCallback.
@Override
protected EventCorrelatorCallback getCorrelatorCallback(MuleContext muleContext) {
return new CollectionCorrelatorCallback(muleContext, storePrefix) {
/**
* 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 {
PrivilegedEvent[] collectedEvents;
try {
collectedEvents = events.toArray(false);
} catch (ObjectStoreException e) {
throw new AggregationException(events, MessageChunkAggregator.this, e);
}
CoreEvent firstEvent = collectedEvents[0];
Arrays.sort(collectedEvents, eventComparator);
ByteArrayOutputStream baos = new ByteArrayOutputStream(DEFAULT_BUFFER_SIZE);
try {
for (PrivilegedEvent event : collectedEvents) {
baos.write(event.getMessageAsBytes(muleContext));
}
final Message.Builder builder = Message.builder(firstEvent.getMessage());
// try to deserialize message, since ChunkingRouter might have serialized the object...
try {
builder.value(muleContext.getObjectSerializer().getInternalProtocol().deserialize(baos.toByteArray()));
} catch (SerializationException e) {
builder.value(baos.toByteArray());
}
// Use last event, that hasn't been completed yet, for continued processing.
return PrivilegedEvent.builder(collectedEvents[collectedEvents.length - 1]).message(builder.build()).session(getMergedSession(events.toArray())).build();
} catch (Exception e) {
throw new AggregationException(events, MessageChunkAggregator.this, e);
} finally {
closeQuietly(baos);
}
}
};
}
use of org.mule.runtime.api.store.ObjectStoreException in project mule by mulesoft.
the class EventGroup method getMessageCollectionEvent.
public CoreEvent getMessageCollectionEvent() {
try {
if (size() > 0) {
PrivilegedEvent[] muleEvents = toArray(true);
CoreEvent lastEvent = muleEvents[muleEvents.length - 1];
List<Message> messageList = Arrays.stream(muleEvents).map(event -> event.getMessage()).collect(toList());
final Message.Builder builder = Message.builder().collectionValue(messageList, Message.class);
PrivilegedEvent muleEvent = PrivilegedEvent.builder(lastEvent).message(builder.build()).session(getMergedSession(muleEvents)).build();
return muleEvent;
} else {
return null;
}
} catch (ObjectStoreException e) {
// Nothing to do...
return null;
}
}
Aggregations