Search in sources :

Example 41 with MuleException

use of org.mule.runtime.api.exception.MuleException 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 42 with MuleException

use of org.mule.runtime.api.exception.MuleException in project mule by mulesoft.

the class FirstSuccessfulRoutingStrategy method route.

@Override
public CoreEvent route(CoreEvent event, List<Processor> messageProcessors) throws MuleException {
    CoreEvent returnEvent = null;
    boolean failed = true;
    Exception failExceptionCause = null;
    validateMessageIsNotConsumable(event.getMessage());
    for (Processor mp : messageProcessors) {
        try {
            returnEvent = processToApplyWithChildContext(event, mp);
            if (returnEvent == null) {
                failed = false;
            } else if (returnEvent.getMessage() == null) {
                failed = true;
            } else {
                failed = returnEvent.getError().isPresent();
            }
        } catch (Exception ex) {
            failed = true;
            failExceptionCause = ex;
        }
        if (!failed) {
            break;
        }
    }
    if (failed) {
        if (failExceptionCause != null) {
            throw new RoutingFailedException(createStaticMessage("All processors failed during 'first-successful' routing strategy"), failExceptionCause);
        } else {
            throw new RoutingFailedException(createStaticMessage("All processors failed during 'first-successful' routing strategy"));
        }
    }
    return returnEvent != null ? builder(event.getContext(), returnEvent).build() : null;
}
Also used : Processor(org.mule.runtime.core.api.processor.Processor) CoreEvent(org.mule.runtime.core.api.event.CoreEvent) MuleRuntimeException(org.mule.runtime.api.exception.MuleRuntimeException) MuleException(org.mule.runtime.api.exception.MuleException) DispatchException(org.mule.runtime.core.privileged.connector.DispatchException) RoutingException(org.mule.runtime.core.privileged.routing.RoutingException)

Example 43 with MuleException

use of org.mule.runtime.api.exception.MuleException in project mule by mulesoft.

the class SimpleRegistry method doRegisterObject.

/**
 * {@inheritDoc}
 */
@Override
protected void doRegisterObject(String key, Object object, Object metadata) throws RegistrationException {
    Object previous = doGet(key);
    if (previous != null) {
        if (logger.isDebugEnabled()) {
            logger.debug(String.format("An entry already exists for key %s. It will be replaced", key));
        }
        unregisterObject(key);
    }
    doPut(key, object);
    try {
        getLifecycleManager().applyCompletedPhases(object);
    } catch (MuleException e) {
        throw new RegistrationException(e);
    }
}
Also used : RegistrationException(org.mule.runtime.core.privileged.registry.RegistrationException) MuleException(org.mule.runtime.api.exception.MuleException)

Example 44 with MuleException

use of org.mule.runtime.api.exception.MuleException in project mule by mulesoft.

the class RoundRobin method route.

/**
 * Process the event using the next target route in sequence
 */
@Override
public CoreEvent route(CoreEvent event) throws MuleException {
    int modulo = getAndIncrementModuloN(routes.size());
    if (modulo < 0) {
        throw new CouldNotRouteOutboundMessageException(this);
    }
    Processor mp = routes.get(modulo);
    try {
        return doProcessRoute(mp, event);
    } catch (MuleException ex) {
        throw new RoutingException(this, ex);
    }
}
Also used : CouldNotRouteOutboundMessageException(org.mule.runtime.core.privileged.routing.CouldNotRouteOutboundMessageException) RoutingException(org.mule.runtime.core.privileged.routing.RoutingException) Processor(org.mule.runtime.core.api.processor.Processor) MuleException(org.mule.runtime.api.exception.MuleException)

Example 45 with MuleException

use of org.mule.runtime.api.exception.MuleException in project mule by mulesoft.

the class DefaultSchedulerMessageSource method start.

@Override
public synchronized void start() throws MuleException {
    if (started) {
        return;
    }
    try {
        // The initialization phase if handled by the scheduler
        schedulingJob = withContextClassLoader(muleContext.getExecutionClassLoader(), () -> scheduler.schedule(pollingExecutor, () -> run()));
        this.started = true;
    } catch (Exception ex) {
        this.stop();
        throw new CreateException(failedToScheduleWork(), ex, this);
    }
}
Also used : CreateException(org.mule.runtime.api.lifecycle.CreateException) InitialisationException(org.mule.runtime.api.lifecycle.InitialisationException) CreateException(org.mule.runtime.api.lifecycle.CreateException) MuleException(org.mule.runtime.api.exception.MuleException) MessagingException(org.mule.runtime.core.internal.exception.MessagingException)

Aggregations

MuleException (org.mule.runtime.api.exception.MuleException)68 InitialisationException (org.mule.runtime.api.lifecycle.InitialisationException)21 MuleRuntimeException (org.mule.runtime.api.exception.MuleRuntimeException)19 CoreEvent (org.mule.runtime.core.api.event.CoreEvent)19 Test (org.junit.Test)15 DefaultMuleException (org.mule.runtime.api.exception.DefaultMuleException)14 Processor (org.mule.runtime.core.api.processor.Processor)12 MessagingException (org.mule.runtime.core.internal.exception.MessagingException)9 Logger (org.slf4j.Logger)7 ArrayList (java.util.ArrayList)6 List (java.util.List)6 BaseEventContext (org.mule.runtime.core.privileged.event.BaseEventContext)6 RegistrationException (org.mule.runtime.core.privileged.registry.RegistrationException)6 Map (java.util.Map)5 ConnectionException (org.mule.runtime.api.connection.ConnectionException)5 MuleContext (org.mule.runtime.core.api.MuleContext)5 LifecycleUtils.stopIfNeeded (org.mule.runtime.core.api.lifecycle.LifecycleUtils.stopIfNeeded)5 Thread.currentThread (java.lang.Thread.currentThread)4 CountDownLatch (java.util.concurrent.CountDownLatch)4 Startable (org.mule.runtime.api.lifecycle.Startable)4