use of org.mule.runtime.core.api.processor.Processor in project mule by mulesoft.
the class PolicyNextActionMessageProcessor method apply.
@Override
public Publisher<CoreEvent> apply(Publisher<CoreEvent> publisher) {
return from(publisher).doOnNext(coreEvent -> logExecuteNextEvent("Before execute-next", coreEvent.getContext(), coreEvent.getMessage(), this.muleContext.getConfiguration().getId())).flatMap(event -> {
Processor nextOperation = policyStateHandler.retrieveNextOperation(event.getContext().getCorrelationId());
if (nextOperation == null) {
return error(new MuleRuntimeException(createStaticMessage("There's no next operation configured for event context id " + event.getContext().getCorrelationId())));
}
popBeforeNextFlowFlowStackElement().accept(event);
notificationHelper.notification(BEFORE_NEXT).accept(event);
return from(processWithChildContext(event, nextOperation, ofNullable(getLocation()))).doOnSuccessOrError(notificationHelper.successOrErrorNotification(AFTER_NEXT).andThen((ev, t) -> pushAfterNextFlowStackElement().accept(event))).onErrorResume(MessagingException.class, t -> {
PolicyStateId policyStateId = new PolicyStateId(event.getContext().getCorrelationId(), muleContext.getConfiguration().getId());
policyStateHandler.getLatestState(policyStateId).ifPresent(latestStateEvent -> t.setProcessedEvent(policyEventConverter.createEvent((PrivilegedEvent) t.getEvent(), (PrivilegedEvent) latestStateEvent)));
// Given we've used child context to ensure AFTER_NEXT notifications are fired at exactly the right time we need
// to propagate the error to parent context manually.
((BaseEventContext) event.getContext()).error(resolveMessagingException(t.getFailingComponent(), muleContext).apply(t));
return empty();
}).doOnNext(coreEvent -> logExecuteNextEvent("After execute-next", coreEvent.getContext(), coreEvent.getMessage(), this.muleContext.getConfiguration().getId()));
});
}
use of org.mule.runtime.core.api.processor.Processor in project mule by mulesoft.
the class AbstractMessageProcessorChain method apply.
@Override
public Publisher<CoreEvent> apply(Publisher<CoreEvent> publisher) {
List<BiFunction<Processor, ReactiveProcessor, ReactiveProcessor>> interceptors = resolveInterceptors();
Flux<CoreEvent> stream = from(publisher);
for (Processor processor : getProcessorsToExecute()) {
// Perform assembly for processor chain by transforming the existing publisher with a publisher function for each processor
// along with the interceptors that decorate it.
stream = stream.transform(applyInterceptors(interceptors, processor)).subscriberContext(context -> context.put(REACTOR_ON_OPERATOR_ERROR_LOCAL, getLocalOperatorErrorHook(processor))).errorStrategyContinue(getContinueStrategyErrorHandler(processor));
}
return stream.subscriberContext(ctx -> {
ClassLoader tccl = currentThread().getContextClassLoader();
if (tccl == null || tccl.getParent() == null || appClClass == null || !appClClass.isAssignableFrom(tccl.getClass())) {
return ctx;
} else {
return ctx.put(TCCL_ORIGINAL_REACTOR_CTX_KEY, tccl).put(TCCL_REACTOR_CTX_KEY, tccl.getParent());
}
});
}
use of org.mule.runtime.core.api.processor.Processor in project mule by mulesoft.
the class AbstractMessageProcessorChain method toString.
@Override
public String toString() {
StringBuilder string = new StringBuilder();
string.append(getClass().getSimpleName());
if (!isBlank(name)) {
string.append(format(" '%s' ", name));
}
Iterator<Processor> mpIterator = processors.iterator();
final String nl = format("%n");
// TODO have it print the nested structure with indents increasing for nested MPCs
if (mpIterator.hasNext()) {
string.append(format("%n[ "));
while (mpIterator.hasNext()) {
Processor mp = mpIterator.next();
final String indented = replace(mp.toString(), nl, format("%n "));
string.append(format("%n %s", indented));
if (mpIterator.hasNext()) {
string.append(", ");
}
}
string.append(format("%n]"));
}
return string.toString();
}
use of org.mule.runtime.core.api.processor.Processor in project mule by mulesoft.
the class MessageProcessorChainObjectFactory method doGetObject.
@Override
public MessageProcessorChain doGetObject() throws Exception {
MessageProcessorChainBuilder builder = getBuilderInstance();
for (Object processor : processors) {
if (processor instanceof Processor) {
builder.chain((Processor) processor);
} else {
throw new IllegalArgumentException(format("MessageProcessorBuilder should only have MessageProcessor's or MessageProcessorBuilder's configured. Found a %s", processor.getClass().getName()));
}
}
MessageProcessorChain messageProcessorChain = builder.build();
messageProcessorChain.setMuleContext(muleContext);
return messageProcessorChain;
}
use of org.mule.runtime.core.api.processor.Processor in project mule by mulesoft.
the class ProcessorChainRouter method initialise.
@Override
public void initialise() throws InitialisationException {
DefaultMessageProcessorChainBuilder builder = new DefaultMessageProcessorChainBuilder();
builder.setName("processor chain '" + name + "'");
for (Object processor : processors) {
if (processor instanceof Processor) {
builder.chain((Processor) processor);
} else if (processor instanceof MessageProcessorBuilder) {
builder.chain((MessageProcessorBuilder) processor);
} else {
throw new IllegalArgumentException("MessageProcessorBuilder should only have MessageProcessor's or MessageProcessorBuilder's configured");
}
}
processorChain = builder.build();
initialiseIfNeeded(processorChain, muleContext);
}
Aggregations