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);
}
}
}
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;
}
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);
}
}
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);
}
}
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);
}
}
Aggregations