use of org.mule.runtime.core.privileged.processor.chain.MessageProcessorChain in project mule by mulesoft.
the class SplitAggregateScopeTestCase method routingPairs.
@Test
@Description("RoutingPairs are created for each route configured. Each RoutingPair has the same input event.")
public void routingPairs() throws Exception {
CoreEvent event = createListEvent();
MessageProcessorChain nested = mock(MessageProcessorChain.class);
muleContext.getInjector().inject(router);
router.setMessageProcessors(singletonList(nested));
router.setAnnotations(getAppleFlowComponentLocationAnnotations());
router.initialise();
List<RoutingPair> routingPairs = from(router.getRoutingPairs(event)).collectList().block();
assertThat(routingPairs, hasSize(2));
assertThat(routingPairs.get(0).getEvent().getMessage().getPayload().getValue(), equalTo(((List<Message>) event.getMessage().getPayload().getValue()).get(0)));
assertThat(routingPairs.get(0).getRoute(), sameInstance(nested));
assertThat(routingPairs.get(1).getEvent().getMessage().getPayload().getValue(), equalTo(((List<Message>) event.getMessage().getPayload().getValue()).get(1)));
assertThat(routingPairs.get(1).getRoute(), sameInstance(nested));
}
use of org.mule.runtime.core.privileged.processor.chain.MessageProcessorChain in project mule by mulesoft.
the class AbstractForkJoinStrategyTestCase method createChain.
private MessageProcessorChain createChain(Processor processor) throws MuleException {
MessageProcessorChain chain = newChain(Optional.empty(), processor);
chain.setMuleContext(muleContext);
return chain;
}
use of org.mule.runtime.core.privileged.processor.chain.MessageProcessorChain in project mule by mulesoft.
the class CompositeProcessorChainRouterTestCase method simpleChain.
@Test
@Description("Ensure that with simple chains both chains are executed consecutively with the result of the first chain being used for the second chain.")
public void simpleChain() throws Exception {
Message chain1Out = of(1);
Message chain2Out = of(2);
AtomicReference<Message> chain1In = new AtomicReference<>();
AtomicReference<Message> chain2In = new AtomicReference<>();
MessageProcessorChain chain1 = newChain(empty(), event -> {
chain1In.set(event.getMessage());
return builder(event).message(chain1Out).build();
});
MessageProcessorChain chain2 = newChain(empty(), event -> {
chain2In.set(event.getMessage());
return builder(event).message(chain2Out).build();
});
chainRouter = createCompositeProcessorChainRouter(chain1, chain2);
Message result = chainRouter.execute(testEvent()).get().getMessage();
assertThat(chain1In.get(), equalTo(testEvent().getMessage()));
assertThat(chain2In.get(), equalTo(chain1Out));
assertThat(result, equalTo(chain2Out));
}
use of org.mule.runtime.core.privileged.processor.chain.MessageProcessorChain in project mule by mulesoft.
the class MessageProcessors method newChain.
/**
* Creates a new {@link MessageProcessorChain} from a {@link List} of {@link Processor}'s. Note that this performs chains
* construction but will not inject {@link MuleContext} or perform any lifecycle.
*
* @param processingStrategy the processing strategy to use for configuring the chain. It may be {@link Optional#empty()}.
* @param processors list of processors to construct chains from.
* @return new {@link MessageProcessorChain} instance.
*/
public static MessageProcessorChain newChain(Optional<ProcessingStrategy> processingStrategy, List<Processor> processors) {
if (processors.size() == 1 && processors.get(0) instanceof MessageProcessorChain) {
return (MessageProcessorChain) processors.get(0);
} else {
DefaultMessageProcessorChainBuilder defaultMessageProcessorChainBuilder = new DefaultMessageProcessorChainBuilder();
processingStrategy.ifPresent(defaultMessageProcessorChainBuilder::setProcessingStrategy);
return defaultMessageProcessorChainBuilder.chain(processors).build();
}
}
use of org.mule.runtime.core.privileged.processor.chain.MessageProcessorChain in project mule by mulesoft.
the class AbstractOutboundRouter method doProcessRoute.
protected CoreEvent doProcessRoute(Processor route, CoreEvent event) throws MuleException {
if (route instanceof MessageProcessorChain) {
return route.process(event);
} else {
// MULE-13028 All routers should use processor chains rather than processors as their routes
MessageProcessorChain chain = processorChainCache.getIfPresent(route);
if (chain == null) {
chain = newChain(getProcessingStrategy(locator, getRootContainerLocation()), route);
initialiseObject(chain);
processorChainCache.put(route, chain);
}
return chain.process(event);
}
}
Aggregations