Search in sources :

Example 11 with DefaultMessageProcessorChainBuilder

use of org.mule.runtime.core.privileged.processor.chain.DefaultMessageProcessorChainBuilder 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();
    }
}
Also used : DefaultMessageProcessorChainBuilder(org.mule.runtime.core.privileged.processor.chain.DefaultMessageProcessorChainBuilder) MessageProcessorChain(org.mule.runtime.core.privileged.processor.chain.MessageProcessorChain)

Example 12 with DefaultMessageProcessorChainBuilder

use of org.mule.runtime.core.privileged.processor.chain.DefaultMessageProcessorChainBuilder in project mule by mulesoft.

the class MessageProcessorChainFactoryBean method getBuilderInstance.

protected MessageProcessorChainBuilder getBuilderInstance() {
    DefaultMessageProcessorChainBuilder builder = new DefaultMessageProcessorChainBuilder();
    builder.setName("processor chain '" + name + "'");
    return builder;
}
Also used : DefaultMessageProcessorChainBuilder(org.mule.runtime.core.privileged.processor.chain.DefaultMessageProcessorChainBuilder)

Example 13 with DefaultMessageProcessorChainBuilder

use of org.mule.runtime.core.privileged.processor.chain.DefaultMessageProcessorChainBuilder 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;
}
Also used : DefaultMessageProcessorChainBuilder(org.mule.runtime.core.privileged.processor.chain.DefaultMessageProcessorChainBuilder) ResponseMessageProcessorAdapter(org.mule.runtime.core.internal.processor.ResponseMessageProcessorAdapter) Processor(org.mule.runtime.core.api.processor.Processor) MessageProcessorBuilder(org.mule.runtime.core.privileged.processor.MessageProcessorBuilder)

Example 14 with DefaultMessageProcessorChainBuilder

use of org.mule.runtime.core.privileged.processor.chain.DefaultMessageProcessorChainBuilder in project mule by mulesoft.

the class AsyncDelegateMessageProcessorTestCase method createAsyncDelegateMessageProcessor.

private AsyncDelegateMessageProcessor createAsyncDelegateMessageProcessor(Processor listener, FlowConstruct flowConstruct) throws Exception {
    DefaultMessageProcessorChainBuilder delegateBuilder = new DefaultMessageProcessorChainBuilder();
    delegateBuilder.setProcessingStrategy(flowConstruct.getProcessingStrategy());
    delegateBuilder.chain(listener);
    AsyncDelegateMessageProcessor mp = new AsyncDelegateMessageProcessor(delegateBuilder, "thread");
    mp.setAnnotations(getAppleFlowComponentLocationAnnotations());
    initialiseIfNeeded(mp, true, muleContext);
    return mp;
}
Also used : DefaultMessageProcessorChainBuilder(org.mule.runtime.core.privileged.processor.chain.DefaultMessageProcessorChainBuilder)

Example 15 with DefaultMessageProcessorChainBuilder

use of org.mule.runtime.core.privileged.processor.chain.DefaultMessageProcessorChainBuilder in project mule by mulesoft.

the class ResponseMessageProcessorAdapterTestCase method testResponseAdaptorNestedChainReturnsNull.

@Test
public void testResponseAdaptorNestedChainReturnsNull() throws Exception {
    DefaultMessageProcessorChainBuilder builder = new DefaultMessageProcessorChainBuilder();
    final ResponseMessageProcessorAdapter responseMessageProcessorAdapter = new ResponseMessageProcessorAdapter(new DefaultMessageProcessorChainBuilder().chain(createStringAppendTransformer("a"), createStringAppendTransformer("b"), new ReturnNullMP()).build());
    responseMessageProcessorAdapter.setMuleContext(muleContext);
    builder.chain(createStringAppendTransformer("1"), responseMessageProcessorAdapter, createStringAppendTransformer("2"));
    assertEquals("012", ((PrivilegedEvent) process(builder.build(), eventBuilder(muleContext).message(of("0")).build())).getMessageAsString(muleContext));
}
Also used : DefaultMessageProcessorChainBuilder(org.mule.runtime.core.privileged.processor.chain.DefaultMessageProcessorChainBuilder) Test(org.junit.Test)

Aggregations

DefaultMessageProcessorChainBuilder (org.mule.runtime.core.privileged.processor.chain.DefaultMessageProcessorChainBuilder)16 Test (org.junit.Test)5 Processor (org.mule.runtime.core.api.processor.Processor)4 AsyncDelegateMessageProcessor (org.mule.runtime.core.internal.processor.AsyncDelegateMessageProcessor)3 MessageProcessorBuilder (org.mule.runtime.core.privileged.processor.MessageProcessorBuilder)3 Description (io.qameta.allure.Description)1 CompletableFuture (java.util.concurrent.CompletableFuture)1 TimeoutException (java.util.concurrent.TimeoutException)1 NameableObject (org.mule.runtime.api.meta.NameableObject)1 Latch (org.mule.runtime.api.util.concurrent.Latch)1 ReactiveProcessor (org.mule.runtime.core.api.processor.ReactiveProcessor)1 ResponseMessageProcessorAdapter (org.mule.runtime.core.internal.processor.ResponseMessageProcessorAdapter)1 MessageProcessorExpressionPair (org.mule.runtime.core.internal.routing.MessageProcessorExpressionPair)1 MessageProcessorChain (org.mule.runtime.core.privileged.processor.chain.MessageProcessorChain)1 Setup (org.openjdk.jmh.annotations.Setup)1