use of org.mule.runtime.core.api.processor.Processor 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.core.api.processor.Processor in project mule by mulesoft.
the class AbstractMessageProcessorChain method start.
@Override
public void start() throws MuleException {
List<Processor> startedProcessors = new ArrayList<>();
try {
for (Processor processor : getMessageProcessorsForLifecycle()) {
if (processor instanceof Startable) {
((Startable) processor).start();
startedProcessors.add(processor);
}
}
} catch (MuleException e) {
stopIfNeeded(getMessageProcessorsForLifecycle());
throw e;
}
}
use of org.mule.runtime.core.api.processor.Processor in project mule by mulesoft.
the class DefaultMessageProcessorChainBuilder method build.
/**
* This builder supports the chaining together of message processors that intercept and also those that don't. While one can
* iterate over message processor intercepting message processors need to be chained together. One solution is make all message
* processors intercepting (via adaption) and chain them all together, this results in huge stack traces and recursive calls
* with adaptor. The alternative is to build the chain in such a way that we iterate when we can and chain where we need to.
* <br>
* We iterate over the list of message processor to be chained together in reverse order collecting up those that can be
* iterated over in a temporary list, as soon as we have an intercepting message processor we create a
* DefaultMessageProcessorChain using the temporary list and set it as a listener of the intercepting message processor and then
* we continue with the algorithm
*/
@Override
public MessageProcessorChain build() {
LinkedList<Processor> tempList = new LinkedList<>();
final LinkedList<Processor> processorsForLifecycle = new LinkedList<>();
// Start from last but one message processor and work backwards
for (int i = processors.size() - 1; i >= 0; i--) {
Processor processor = initializeMessageProcessor(processors.get(i));
if (processor instanceof InterceptingMessageProcessor && (!(processor instanceof ReferenceProcessor) || ((ReferenceProcessor) processor).getReferencedProcessor() instanceof InterceptingMessageProcessor)) {
InterceptingMessageProcessor interceptingProcessor = (InterceptingMessageProcessor) processor;
// Processor is intercepting so we can't simply iterate
if (i + 1 < processors.size()) {
// Wrap processors in chain, unless single processor that is already a chain
final MessageProcessorChain innerChain = createSimpleChain(tempList, interceptingProcessor.isBlocking() ? of(BLOCKING_PROCESSING_STRATEGY_INSTANCE) : ofNullable(processingStrategy));
processorsForLifecycle.addFirst(innerChain);
interceptingProcessor.setListener(innerChain);
}
tempList = new LinkedList<>(singletonList(processor));
} else {
// Processor is not intercepting so we can invoke it using iteration
// (add to temp list)
tempList.addFirst(processor);
}
}
// Create the final chain using the current tempList after reserve iteration is complete. This temp
// list contains the first n processors in the chain that are not intercepting.. with processor n+1
// having been injected as the listener of processor n
Processor head = tempList.size() == 1 ? tempList.get(0) : createSimpleChain(tempList, ofNullable(processingStrategy));
processorsForLifecycle.addFirst(head);
return createInterceptingChain(head, processors, processorsForLifecycle);
}
use of org.mule.runtime.core.api.processor.Processor in project mule by mulesoft.
the class ModuleOperationMessageProcessorChainFactoryBean 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()));
}
}
final MessageProcessorChain messageProcessorChain = newLazyProcessorChainBuilder((ModuleOperationMessageProcessorChainBuilder) builder, muleContext, () -> getProcessingStrategy(locator, getRootContainerLocation()).orElse(null));
messageProcessorChain.setAnnotations(getAnnotations());
messageProcessorChain.setMuleContext(muleContext);
return messageProcessorChain;
}
use of org.mule.runtime.core.api.processor.Processor in project mule by mulesoft.
the class ResponseMessageProcessorsFactoryBean method doGetObject.
@Override
public ResponseMessageProcessorAdapter doGetObject() throws Exception {
DefaultMessageProcessorChainBuilder builder = new DefaultMessageProcessorChainBuilder();
builder.setName("'response' child processor chain");
for (Object processor : messageProcessors) {
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");
}
}
ResponseMessageProcessorAdapter responseAdapter = new ResponseMessageProcessorAdapter();
responseAdapter.setProcessor(newLazyProcessorChainBuilder(builder, muleContext, () -> getProcessingStrategy(locator, getRootContainerLocation()).orElse(null)));
responseAdapter.setMuleContext(muleContext);
return responseAdapter;
}
Aggregations