Search in sources :

Example 11 with ObjectStoreException

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);
        }
    }
}
Also used : DefaultMuleException(org.mule.runtime.api.exception.DefaultMuleException) NOT_SET(org.mule.runtime.core.api.message.GroupCorrelation.NOT_SET) ObjectStoreException(org.mule.runtime.api.store.ObjectStoreException) System.currentTimeMillis(java.lang.System.currentTimeMillis) DeserializationPostInitialisable(org.mule.runtime.core.privileged.store.DeserializationPostInitialisable) LoggerFactory(org.slf4j.LoggerFactory) MINUTES(java.util.concurrent.TimeUnit.MINUTES) PartitionableObjectStore(org.mule.runtime.api.store.PartitionableObjectStore) Expirable(org.mule.runtime.core.privileged.util.monitor.Expirable) Processor(org.mule.runtime.core.api.processor.Processor) ObjectDoesNotExistException(org.mule.runtime.api.store.ObjectDoesNotExistException) MessageFormat(java.text.MessageFormat) ArrayList(java.util.ArrayList) MuleContextWithRegistries(org.mule.runtime.core.internal.context.MuleContextWithRegistries) MuleContext(org.mule.runtime.core.api.MuleContext) MuleException(org.mule.runtime.api.exception.MuleException) Scheduler(org.mule.runtime.api.scheduler.Scheduler) DAYS(java.util.concurrent.TimeUnit.DAYS) CORRELATION_TIMEOUT(org.mule.runtime.api.notification.RoutingNotification.CORRELATION_TIMEOUT) MessagingException(org.mule.runtime.core.internal.exception.MessagingException) Mono.empty(reactor.core.publisher.Mono.empty) ExpiryMonitor(org.mule.runtime.core.privileged.util.monitor.ExpiryMonitor) RoutingNotification(org.mule.runtime.api.notification.RoutingNotification) Disposable(org.mule.runtime.api.lifecycle.Disposable) Startable(org.mule.runtime.api.lifecycle.Startable) MISSED_AGGREGATION_GROUP_EVENT(org.mule.runtime.api.notification.RoutingNotification.MISSED_AGGREGATION_GROUP_EVENT) Logger(org.slf4j.Logger) MessageProcessors.processToApply(org.mule.runtime.core.privileged.processor.MessageProcessors.processToApply) ObjectStore(org.mule.runtime.api.store.ObjectStore) I18nMessageFactory.createStaticMessage(org.mule.runtime.api.i18n.I18nMessageFactory.createStaticMessage) CoreEvent(org.mule.runtime.core.api.event.CoreEvent) RegistrationException(org.mule.runtime.core.privileged.registry.RegistrationException) MuleRuntimeException(org.mule.runtime.api.exception.MuleRuntimeException) MILLISECONDS(java.util.concurrent.TimeUnit.MILLISECONDS) StringMessageUtils.truncate(org.mule.runtime.core.api.util.StringMessageUtils.truncate) StringMessageUtils(org.mule.runtime.core.api.util.StringMessageUtils) String.format(java.lang.String.format) EventGroup(org.mule.runtime.core.internal.routing.EventGroup) DefaultMuleException(org.mule.runtime.api.exception.DefaultMuleException) List(java.util.List) Stoppable(org.mule.runtime.api.lifecycle.Stoppable) CoreMessages.objectIsNull(org.mule.runtime.core.api.config.i18n.CoreMessages.objectIsNull) CoreMessages.correlationTimedOut(org.mule.runtime.core.api.config.i18n.CoreMessages.correlationTimedOut) FlowConstruct(org.mule.runtime.core.api.construct.FlowConstruct) NotificationDispatcher(org.mule.runtime.api.notification.NotificationDispatcher) RoutingException(org.mule.runtime.core.privileged.routing.RoutingException) ObjectAlreadyExistsException(org.mule.runtime.api.store.ObjectAlreadyExistsException) ObjectStoreException(org.mule.runtime.api.store.ObjectStoreException) CoreEvent(org.mule.runtime.core.api.event.CoreEvent) MessagingException(org.mule.runtime.core.internal.exception.MessagingException) RoutingNotification(org.mule.runtime.api.notification.RoutingNotification) ObjectStoreException(org.mule.runtime.api.store.ObjectStoreException) ObjectDoesNotExistException(org.mule.runtime.api.store.ObjectDoesNotExistException) MuleException(org.mule.runtime.api.exception.MuleException) MessagingException(org.mule.runtime.core.internal.exception.MessagingException) RegistrationException(org.mule.runtime.core.privileged.registry.RegistrationException) MuleRuntimeException(org.mule.runtime.api.exception.MuleRuntimeException) DefaultMuleException(org.mule.runtime.api.exception.DefaultMuleException) RoutingException(org.mule.runtime.core.privileged.routing.RoutingException) ObjectAlreadyExistsException(org.mule.runtime.api.store.ObjectAlreadyExistsException)

Example 12 with ObjectStoreException

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;
    }
}
Also used : ObjectStoreException(org.mule.runtime.api.store.ObjectStoreException) ObjectDoesNotExistException(org.mule.runtime.api.store.ObjectDoesNotExistException) EventGroup(org.mule.runtime.core.internal.routing.EventGroup) ObjectStoreException(org.mule.runtime.api.store.ObjectStoreException) ObjectDoesNotExistException(org.mule.runtime.api.store.ObjectDoesNotExistException) MuleException(org.mule.runtime.api.exception.MuleException) MessagingException(org.mule.runtime.core.internal.exception.MessagingException) RegistrationException(org.mule.runtime.core.privileged.registry.RegistrationException) MuleRuntimeException(org.mule.runtime.api.exception.MuleRuntimeException) DefaultMuleException(org.mule.runtime.api.exception.DefaultMuleException) RoutingException(org.mule.runtime.core.privileged.routing.RoutingException) ObjectAlreadyExistsException(org.mule.runtime.api.store.ObjectAlreadyExistsException)

Example 13 with ObjectStoreException

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();
}
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 14 with ObjectStoreException

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);
            }
        }
    };
}
Also used : CollectionCorrelatorCallback(org.mule.runtime.core.internal.routing.correlation.CollectionCorrelatorCallback) ObjectStoreException(org.mule.runtime.api.store.ObjectStoreException) PrivilegedEvent(org.mule.runtime.core.privileged.event.PrivilegedEvent) SerializationException(org.mule.runtime.api.serialization.SerializationException) Message(org.mule.runtime.api.message.Message) CoreEvent(org.mule.runtime.core.api.event.CoreEvent) ByteArrayOutputStream(org.apache.commons.io.output.ByteArrayOutputStream) ObjectStoreException(org.mule.runtime.api.store.ObjectStoreException) SerializationException(org.mule.runtime.api.serialization.SerializationException)

Example 15 with ObjectStoreException

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;
    }
}
Also used : NOT_SET(org.mule.runtime.core.api.message.GroupCorrelation.NOT_SET) ObjectStoreException(org.mule.runtime.api.store.ObjectStoreException) Arrays(java.util.Arrays) PrivilegedEvent(org.mule.runtime.core.privileged.event.PrivilegedEvent) Iterator(java.util.Iterator) Message(org.mule.runtime.api.message.Message) CoreEvent(org.mule.runtime.core.api.event.CoreEvent) DeserializationPostInitialisable(org.mule.runtime.core.privileged.store.DeserializationPostInitialisable) PartitionableObjectStore(org.mule.runtime.api.store.PartitionableObjectStore) MuleSession(org.mule.runtime.core.privileged.event.MuleSession) Serializable(java.io.Serializable) ClassUtils(org.mule.runtime.core.api.util.ClassUtils) DefaultMuleSession(org.mule.runtime.core.privileged.event.DefaultMuleSession) DASH(org.mule.runtime.core.api.util.StringUtils.DASH) Collectors.toList(java.util.stream.Collectors.toList) List(java.util.List) MuleContext(org.mule.runtime.core.api.MuleContext) MuleException(org.mule.runtime.api.exception.MuleException) MuleProperties(org.mule.runtime.core.api.config.MuleProperties) IteratorUtils(org.apache.commons.collections.IteratorUtils) Optional(java.util.Optional) Comparator(java.util.Comparator) ObjectStoreException(org.mule.runtime.api.store.ObjectStoreException) PrivilegedEvent(org.mule.runtime.core.privileged.event.PrivilegedEvent) Message(org.mule.runtime.api.message.Message) CoreEvent(org.mule.runtime.core.api.event.CoreEvent)

Aggregations

ObjectStoreException (org.mule.runtime.api.store.ObjectStoreException)20 MuleRuntimeException (org.mule.runtime.api.exception.MuleRuntimeException)10 ObjectAlreadyExistsException (org.mule.runtime.api.store.ObjectAlreadyExistsException)9 ObjectDoesNotExistException (org.mule.runtime.api.store.ObjectDoesNotExistException)9 CoreEvent (org.mule.runtime.core.api.event.CoreEvent)6 MuleException (org.mule.runtime.api.exception.MuleException)5 RegistrationException (org.mule.runtime.core.privileged.registry.RegistrationException)5 File (java.io.File)3 IOException (java.io.IOException)3 Serializable (java.io.Serializable)3 DefaultMuleException (org.mule.runtime.api.exception.DefaultMuleException)3 MessagingException (org.mule.runtime.core.internal.exception.MessagingException)3 EventGroup (org.mule.runtime.core.internal.routing.EventGroup)3 RoutingException (org.mule.runtime.core.privileged.routing.RoutingException)3 PollingProber (org.mule.tck.probe.PollingProber)3 List (java.util.List)2 Message (org.mule.runtime.api.message.Message)2 RoutingNotification (org.mule.runtime.api.notification.RoutingNotification)2 ObjectStoreNotAvailableException (org.mule.runtime.api.store.ObjectStoreNotAvailableException)2 PartitionableObjectStore (org.mule.runtime.api.store.PartitionableObjectStore)2