Search in sources :

Example 1 with MessageProcessorChainBuilder

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

Example 2 with MessageProcessorChainBuilder

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

the class FlowRefFactoryBean method getReferencedFlow.

protected Processor getReferencedFlow(String name, FlowRefMessageProcessor flowRefMessageProcessor) throws MuleException {
    if (name == null) {
        throw new RoutePathNotFoundException(createStaticMessage("flow-ref name expression returned 'null'"), flowRefMessageProcessor);
    }
    Component referencedFlow = getReferencedProcessor(name);
    if (referencedFlow == null) {
        throw new RoutePathNotFoundException(createStaticMessage("No flow/sub-flow with name '%s' found", name), flowRefMessageProcessor);
    }
    // for subflows, we create a new one so it must be initialised manually
    if (!(referencedFlow instanceof Flow)) {
        if (referencedFlow instanceof SubflowMessageProcessorChainBuilder) {
            MessageProcessorChainBuilder chainBuilder = (MessageProcessorChainBuilder) referencedFlow;
            locator.find(flowRefMessageProcessor.getRootContainerLocation()).filter(c -> c instanceof Flow).map(c -> (Flow) c).ifPresent(f -> chainBuilder.setProcessingStrategy(f.getProcessingStrategy()));
            referencedFlow = chainBuilder.build();
        }
        initialiseIfNeeded(referencedFlow, muleContext);
        Map<QName, Object> annotations = new HashMap<>(referencedFlow.getAnnotations());
        annotations.put(ROOT_CONTAINER_NAME_KEY, getRootContainerLocation().toString());
        referencedFlow.setAnnotations(annotations);
        startIfNeeded(referencedFlow);
    }
    return (Processor) referencedFlow;
}
Also used : Flux.just(reactor.core.publisher.Flux.just) LoadingCache(com.google.common.cache.LoadingCache) Map(java.util.Map) LifecycleUtils.stopIfNeeded(org.mule.runtime.core.api.lifecycle.LifecycleUtils.stopIfNeeded) MuleRuntimeException(org.mule.runtime.api.exception.MuleRuntimeException) Operators.outputToTarget(org.mule.runtime.core.internal.util.rx.Operators.outputToTarget) Flow(org.mule.runtime.core.api.construct.Flow) CacheLoader(com.google.common.cache.CacheLoader) MessageProcessors.processWithChildContext(org.mule.runtime.core.privileged.processor.MessageProcessors.processWithChildContext) MessageProcessors(org.mule.runtime.core.privileged.processor.MessageProcessors) MessageProcessorChainBuilder(org.mule.runtime.core.privileged.processor.chain.MessageProcessorChainBuilder) CacheBuilder(com.google.common.cache.CacheBuilder) QName(javax.xml.namespace.QName) ExtendedExpressionManager(org.mule.runtime.core.api.el.ExtendedExpressionManager) ApplicationContextAware(org.springframework.context.ApplicationContextAware) Flux.from(reactor.core.publisher.Flux.from) HashMap(java.util.HashMap) LifecycleUtils.initialiseIfNeeded(org.mule.runtime.core.api.lifecycle.LifecycleUtils.initialiseIfNeeded) Processor(org.mule.runtime.core.api.processor.Processor) Inject(javax.inject.Inject) ConfigurationComponentLocator(org.mule.runtime.api.component.location.ConfigurationComponentLocator) MuleContext(org.mule.runtime.core.api.MuleContext) MuleException(org.mule.runtime.api.exception.MuleException) UncheckedExecutionException(com.google.common.util.concurrent.UncheckedExecutionException) Component(org.mule.runtime.api.component.Component) Flux.error(reactor.core.publisher.Flux.error) Disposable(org.mule.runtime.api.lifecycle.Disposable) AnnotatedProcessor(org.mule.runtime.core.privileged.processor.AnnotatedProcessor) AbstractComponentFactory(org.mule.runtime.dsl.api.component.AbstractComponentFactory) Logger(org.slf4j.Logger) MessageProcessors.processToApply(org.mule.runtime.core.privileged.processor.MessageProcessors.processToApply) SubflowMessageProcessorChainBuilder(org.mule.runtime.core.internal.processor.chain.SubflowMessageProcessorChainBuilder) Optional.ofNullable(java.util.Optional.ofNullable) I18nMessageFactory.createStaticMessage(org.mule.runtime.api.i18n.I18nMessageFactory.createStaticMessage) CoreEvent(org.mule.runtime.core.api.event.CoreEvent) Publisher(org.reactivestreams.Publisher) RoutePathNotFoundException(org.mule.runtime.core.privileged.routing.RoutePathNotFoundException) LifecycleUtils.startIfNeeded(org.mule.runtime.core.api.lifecycle.LifecycleUtils.startIfNeeded) BeansException(org.springframework.beans.BeansException) Mono(reactor.core.publisher.Mono) ApplicationContext(org.springframework.context.ApplicationContext) AbstractComponent(org.mule.runtime.api.component.AbstractComponent) LifecycleUtils.disposeIfNeeded(org.mule.runtime.core.api.lifecycle.LifecycleUtils.disposeIfNeeded) Flux(reactor.core.publisher.Flux) Stoppable(org.mule.runtime.api.lifecycle.Stoppable) NoSuchBeanDefinitionException(org.springframework.beans.factory.NoSuchBeanDefinitionException) LoggerFactory.getLogger(org.slf4j.LoggerFactory.getLogger) ComponentLocation(org.mule.runtime.api.component.location.ComponentLocation) MuleArtifactContext(org.mule.runtime.config.internal.MuleArtifactContext) RoutePathNotFoundException(org.mule.runtime.core.privileged.routing.RoutePathNotFoundException) Processor(org.mule.runtime.core.api.processor.Processor) AnnotatedProcessor(org.mule.runtime.core.privileged.processor.AnnotatedProcessor) HashMap(java.util.HashMap) QName(javax.xml.namespace.QName) MessageProcessorChainBuilder(org.mule.runtime.core.privileged.processor.chain.MessageProcessorChainBuilder) SubflowMessageProcessorChainBuilder(org.mule.runtime.core.internal.processor.chain.SubflowMessageProcessorChainBuilder) Component(org.mule.runtime.api.component.Component) AbstractComponent(org.mule.runtime.api.component.AbstractComponent) SubflowMessageProcessorChainBuilder(org.mule.runtime.core.internal.processor.chain.SubflowMessageProcessorChainBuilder) Flow(org.mule.runtime.core.api.construct.Flow)

Example 3 with MessageProcessorChainBuilder

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

Aggregations

Processor (org.mule.runtime.core.api.processor.Processor)3 MessageProcessorChainBuilder (org.mule.runtime.core.privileged.processor.chain.MessageProcessorChainBuilder)3 MessageProcessorChain (org.mule.runtime.core.privileged.processor.chain.MessageProcessorChain)2 CacheBuilder (com.google.common.cache.CacheBuilder)1 CacheLoader (com.google.common.cache.CacheLoader)1 LoadingCache (com.google.common.cache.LoadingCache)1 UncheckedExecutionException (com.google.common.util.concurrent.UncheckedExecutionException)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 Optional.ofNullable (java.util.Optional.ofNullable)1 Inject (javax.inject.Inject)1 QName (javax.xml.namespace.QName)1 AbstractComponent (org.mule.runtime.api.component.AbstractComponent)1 Component (org.mule.runtime.api.component.Component)1 ComponentLocation (org.mule.runtime.api.component.location.ComponentLocation)1 ConfigurationComponentLocator (org.mule.runtime.api.component.location.ConfigurationComponentLocator)1 MuleException (org.mule.runtime.api.exception.MuleException)1 MuleRuntimeException (org.mule.runtime.api.exception.MuleRuntimeException)1 I18nMessageFactory.createStaticMessage (org.mule.runtime.api.i18n.I18nMessageFactory.createStaticMessage)1 Disposable (org.mule.runtime.api.lifecycle.Disposable)1