Search in sources :

Example 1 with CORRELATION_TIMEOUT

use of org.mule.runtime.api.notification.RoutingNotification.CORRELATION_TIMEOUT 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)

Aggregations

String.format (java.lang.String.format)1 System.currentTimeMillis (java.lang.System.currentTimeMillis)1 MessageFormat (java.text.MessageFormat)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 DAYS (java.util.concurrent.TimeUnit.DAYS)1 MILLISECONDS (java.util.concurrent.TimeUnit.MILLISECONDS)1 MINUTES (java.util.concurrent.TimeUnit.MINUTES)1 DefaultMuleException (org.mule.runtime.api.exception.DefaultMuleException)1 MuleException (org.mule.runtime.api.exception.MuleException)1 MuleRuntimeException (org.mule.runtime.api.exception.MuleRuntimeException)1 I18nMessageFactory.createStaticMessage (org.mule.runtime.api.i18n.I18nMessageFactory.createStaticMessage)1 Disposable (org.mule.runtime.api.lifecycle.Disposable)1 Startable (org.mule.runtime.api.lifecycle.Startable)1 Stoppable (org.mule.runtime.api.lifecycle.Stoppable)1 NotificationDispatcher (org.mule.runtime.api.notification.NotificationDispatcher)1 RoutingNotification (org.mule.runtime.api.notification.RoutingNotification)1 CORRELATION_TIMEOUT (org.mule.runtime.api.notification.RoutingNotification.CORRELATION_TIMEOUT)1 MISSED_AGGREGATION_GROUP_EVENT (org.mule.runtime.api.notification.RoutingNotification.MISSED_AGGREGATION_GROUP_EVENT)1 Scheduler (org.mule.runtime.api.scheduler.Scheduler)1