Search in sources :

Example 1 with DefaultMessageProcessorChainBuilder

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

the class AbstractPipeline method createPipeline.

/**
 * Creates a {@link Processor} that will process messages from the configured {@link MessageSource} .
 * <p>
 * The default implementation of this methods uses a {@link DefaultMessageProcessorChainBuilder} and allows a chain of
 * {@link Processor}s to be configured using the {@link #configureMessageProcessors(MessageProcessorChainBuilder)} method but if
 * you wish to use another {@link MessageProcessorBuilder} or just a single {@link Processor} then this method can be overridden
 * and return a single {@link Processor} instead.
 */
protected MessageProcessorChain createPipeline() throws MuleException {
    DefaultMessageProcessorChainBuilder builder = new DefaultMessageProcessorChainBuilder();
    builder.setName("'" + getName() + "' processor chain");
    if (processingStrategy != null) {
        builder.setProcessingStrategy(processingStrategy);
    }
    configureMessageProcessors(builder);
    return builder.build();
}
Also used : DefaultMessageProcessorChainBuilder(org.mule.runtime.core.privileged.processor.chain.DefaultMessageProcessorChainBuilder)

Example 2 with DefaultMessageProcessorChainBuilder

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

Example 3 with DefaultMessageProcessorChainBuilder

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

the class ResponseMessageProcessorAdapterTestCase method testResponseAdaptorSingleMP.

@Test
public void testResponseAdaptorSingleMP() throws Exception {
    DefaultMessageProcessorChainBuilder builder = new DefaultMessageProcessorChainBuilder();
    final ResponseMessageProcessorAdapter responseMessageProcessorAdapter = new ResponseMessageProcessorAdapter(createStringAppendTransformer("3"));
    responseMessageProcessorAdapter.setMuleContext(muleContext);
    builder.chain(createStringAppendTransformer("1"), responseMessageProcessorAdapter, createStringAppendTransformer("2"));
    assertEquals("0123", ((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)

Example 4 with DefaultMessageProcessorChainBuilder

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

the class ResponseMessageProcessorAdapterTestCase method testResponseAdaptorNestedChain.

@Test
public void testResponseAdaptorNestedChain() throws Exception {
    DefaultMessageProcessorChainBuilder builder = new DefaultMessageProcessorChainBuilder();
    final ResponseMessageProcessorAdapter responseMessageProcessorAdapter = new ResponseMessageProcessorAdapter(new DefaultMessageProcessorChainBuilder().chain(createStringAppendTransformer("a"), createStringAppendTransformer("b")).build());
    responseMessageProcessorAdapter.setMuleContext(muleContext);
    builder.chain(createStringAppendTransformer("1"), responseMessageProcessorAdapter, createStringAppendTransformer("2"));
    assertEquals("012ab", ((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)

Example 5 with DefaultMessageProcessorChainBuilder

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

the class CompositeProcessorChainRouterTestCase method asyncDelegateChain.

@Test
@Description("Ensure that when an async scope is used as part of the execution of one of the composite chains then the chain does not complete and the next chains is not executed until the child context completes.")
public void asyncDelegateChain() throws Exception {
    Latch latch = new Latch();
    Latch asyncLatch = new Latch();
    DefaultMessageProcessorChainBuilder delegateBuilder = new DefaultMessageProcessorChainBuilder();
    delegateBuilder.chain(event -> {
        try {
            asyncLatch.countDown();
            latch.await();
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        }
        return event;
    });
    async = new AsyncDelegateMessageProcessor(delegateBuilder);
    muleContext.getInjector().inject(async);
    async.setAnnotations(getAppleFlowComponentLocationAnnotations());
    chainRouter = createCompositeProcessorChainRouter(newChain(empty(), async), newChain(empty(), event -> event));
    chainRouter.start();
    // CompletableFuture is not returned immediately because simply invoking CompositeProcessorChainRouter there is no async
    // hand-off and so this blocks until child context completes.
    Future<CompletableFuture<Event>> future = scheduler.submit(() -> chainRouter.execute(testEvent()));
    asyncLatch.await();
    try {
        future.get(BLOCK_TIMEOUT, MILLISECONDS);
        fail("Timeout expected");
    } catch (TimeoutException te) {
    }
    latch.countDown();
    assertThat(future.get(BLOCK_TIMEOUT, MILLISECONDS).get().getMessage(), equalTo(testEvent().getMessage()));
}
Also used : DefaultMessageProcessorChainBuilder(org.mule.runtime.core.privileged.processor.chain.DefaultMessageProcessorChainBuilder) CompletableFuture(java.util.concurrent.CompletableFuture) Latch(org.mule.runtime.api.util.concurrent.Latch) AsyncDelegateMessageProcessor(org.mule.runtime.core.internal.processor.AsyncDelegateMessageProcessor) TimeoutException(java.util.concurrent.TimeoutException) Description(io.qameta.allure.Description) 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