use of org.mule.runtime.core.api.processor.Processor in project mule by mulesoft.
the class AbstractPipeline method doInitialise.
@Override
protected void doInitialise() throws MuleException {
super.doInitialise();
pipeline = createPipeline();
if (source != null) {
source.setListener(new Processor() {
@Override
public CoreEvent process(CoreEvent event) throws MuleException {
return processToApply(event, this);
}
@Override
public Publisher<CoreEvent> apply(Publisher<CoreEvent> publisher) {
return from(publisher).transform(dispatchToFlow());
}
});
}
initialiseIfNeeded(source, muleContext);
initialiseIfNeeded(pipeline, muleContext);
}
use of org.mule.runtime.core.api.processor.Processor in project mule by mulesoft.
the class DefaultPolicyManager method createSourcePolicyInstance.
@Override
public SourcePolicy createSourcePolicyInstance(Component source, CoreEvent sourceEvent, Processor flowExecutionProcessor, MessageSourceResponseParametersProcessor messageSourceResponseParametersProcessor) {
PolicyPointcutParameters sourcePointcutParameters = policyPointcutParametersManager.createSourcePointcutParameters(source, sourceEvent);
List<Policy> parameterizedPolicies = policyProvider.findSourceParameterizedPolicies(sourcePointcutParameters);
if (parameterizedPolicies.isEmpty()) {
return event -> from(process(event, flowExecutionProcessor)).defaultIfEmpty(CoreEvent.builder(sourceEvent).message(of(null)).build()).<Either<SourcePolicyFailureResult, SourcePolicySuccessResult>>map(flowExecutionResult -> right(new SourcePolicySuccessResult(flowExecutionResult, () -> messageSourceResponseParametersProcessor.getSuccessfulExecutionResponseParametersFunction().apply(flowExecutionResult), messageSourceResponseParametersProcessor))).onErrorResume(Exception.class, e -> {
MessagingException messagingException = e instanceof MessagingException ? (MessagingException) e : new MessagingException(event, e, (Component) flowExecutionProcessor);
return just(Either.left(new SourcePolicyFailureResult(messagingException, () -> messageSourceResponseParametersProcessor.getFailedExecutionResponseParametersFunction().apply(messagingException.getEvent()))));
});
}
return new CompositeSourcePolicy(parameterizedPolicies, lookupSourceParametersTransformer(source.getLocation().getComponentIdentifier().getIdentifier()), sourcePolicyProcessorFactory, flowExecutionProcessor, messageSourceResponseParametersProcessor);
}
use of org.mule.runtime.core.api.processor.Processor 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.core.api.processor.Processor 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.core.api.processor.Processor in project mule by mulesoft.
the class ReactiveAroundInterceptorAdapter method doAround.
private CompletableFuture<InternalEvent> doAround(InternalEvent event, ProcessorInterceptor interceptor, Processor component, Map<String, String> dslParameters, ReactiveProcessor next) {
final InternalEvent eventWithResolvedParams = addResolvedParameters(event, component, dslParameters);
DefaultInterceptionEvent interceptionEvent = new DefaultInterceptionEvent(eventWithResolvedParams);
final ReactiveInterceptionAction reactiveInterceptionAction = new ReactiveInterceptionAction(interceptionEvent, next, component, ((PrivilegedMuleContext) getMuleContext()).getErrorTypeLocator());
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("Calling around() for '{}' in processor '{}'...", interceptor, ((Component) component).getLocation().getLocation());
}
try {
return withContextClassLoader(interceptor.getClass().getClassLoader(), () -> interceptor.around(((Component) component).getLocation(), getResolvedParams(eventWithResolvedParams), interceptionEvent, reactiveInterceptionAction)).exceptionally(t -> {
if (t instanceof MessagingException) {
throw new CompletionException(t);
} else {
throw new CompletionException(createMessagingException(eventWithResolvedParams, t instanceof CompletionException ? t.getCause() : t, ((Component) component)));
}
}).thenApply(interceptedEvent -> interceptedEvent != null ? ((DefaultInterceptionEvent) interceptedEvent).resolve() : null);
} catch (Exception e) {
throw propagate(createMessagingException(interceptionEvent.resolve(), e, (Component) component));
}
}
Aggregations