Search in sources :

Example 1 with IdAware

use of org.apache.camel.spi.IdAware in project camel by apache.

the class ProcessorDefinition method makeProcessorImpl.

private Processor makeProcessorImpl(RouteContext routeContext) throws Exception {
    Processor processor = null;
    // allow any custom logic before we create the processor
    preCreateProcessor();
    // resolve properties before we create the processor
    ProcessorDefinitionHelper.resolvePropertyPlaceholders(routeContext.getCamelContext(), this);
    // resolve constant fields (eg Exchange.FILE_NAME)
    ProcessorDefinitionHelper.resolveKnownConstantFields(this);
    // also resolve properties and constant fields on embedded expressions
    ProcessorDefinition<?> me = (ProcessorDefinition<?>) this;
    if (me instanceof ExpressionNode) {
        ExpressionNode exp = (ExpressionNode) me;
        ExpressionDefinition expressionDefinition = exp.getExpression();
        if (expressionDefinition != null) {
            // resolve properties before we create the processor
            ProcessorDefinitionHelper.resolvePropertyPlaceholders(routeContext.getCamelContext(), expressionDefinition);
            // resolve constant fields (eg Exchange.FILE_NAME)
            ProcessorDefinitionHelper.resolveKnownConstantFields(expressionDefinition);
        }
    }
    // at first use custom factory
    if (routeContext.getCamelContext().getProcessorFactory() != null) {
        processor = routeContext.getCamelContext().getProcessorFactory().createProcessor(routeContext, this);
    }
    // fallback to default implementation if factory did not create the processor
    if (processor == null) {
        processor = createProcessor(routeContext);
    }
    // inject id
    if (processor instanceof IdAware) {
        String id = this.idOrCreate(routeContext.getCamelContext().getNodeIdFactory());
        ((IdAware) processor).setId(id);
    }
    if (processor == null) {
        // no processor to make
        return null;
    }
    return wrapProcessor(routeContext, processor);
}
Also used : InterceptEndpointProcessor(org.apache.camel.processor.InterceptEndpointProcessor) Processor(org.apache.camel.Processor) IdAware(org.apache.camel.spi.IdAware) ExpressionDefinition(org.apache.camel.model.language.ExpressionDefinition)

Example 2 with IdAware

use of org.apache.camel.spi.IdAware in project camel by apache.

the class ProcessorDefinition method createOutputsProcessorImpl.

protected Processor createOutputsProcessorImpl(RouteContext routeContext, Collection<ProcessorDefinition<?>> outputs) throws Exception {
    List<Processor> list = new ArrayList<Processor>();
    for (ProcessorDefinition<?> output : outputs) {
        // allow any custom logic before we create the processor
        output.preCreateProcessor();
        // resolve properties before we create the processor
        ProcessorDefinitionHelper.resolvePropertyPlaceholders(routeContext.getCamelContext(), output);
        // resolve constant fields (eg Exchange.FILE_NAME)
        ProcessorDefinitionHelper.resolveKnownConstantFields(output);
        // also resolve properties and constant fields on embedded expressions
        ProcessorDefinition<?> me = (ProcessorDefinition<?>) output;
        if (me instanceof ExpressionNode) {
            ExpressionNode exp = (ExpressionNode) me;
            ExpressionDefinition expressionDefinition = exp.getExpression();
            if (expressionDefinition != null) {
                // resolve properties before we create the processor
                ProcessorDefinitionHelper.resolvePropertyPlaceholders(routeContext.getCamelContext(), expressionDefinition);
                // resolve constant fields (eg Exchange.FILE_NAME)
                ProcessorDefinitionHelper.resolveKnownConstantFields(expressionDefinition);
            }
        }
        Processor processor = createProcessor(routeContext, output);
        // inject id
        if (processor instanceof IdAware) {
            String id = output.idOrCreate(routeContext.getCamelContext().getNodeIdFactory());
            ((IdAware) processor).setId(id);
        }
        if (output instanceof Channel && processor == null) {
            continue;
        }
        Processor channel = wrapChannel(routeContext, processor, output);
        list.add(channel);
    }
    // if more than one output wrap than in a composite processor else just keep it as is
    Processor processor = null;
    if (!list.isEmpty()) {
        if (list.size() == 1) {
            processor = list.get(0);
        } else {
            processor = createCompositeProcessor(routeContext, list);
        }
    }
    return processor;
}
Also used : InterceptEndpointProcessor(org.apache.camel.processor.InterceptEndpointProcessor) Processor(org.apache.camel.Processor) IdAware(org.apache.camel.spi.IdAware) Channel(org.apache.camel.Channel) DefaultChannel(org.apache.camel.processor.interceptor.DefaultChannel) ArrayList(java.util.ArrayList) ExpressionDefinition(org.apache.camel.model.language.ExpressionDefinition)

Example 3 with IdAware

use of org.apache.camel.spi.IdAware in project camel by apache.

the class EventDrivenConsumerRoute method doFilter.

@SuppressWarnings("unchecked")
private void doFilter(String pattern, Navigate<Processor> nav, List<Processor> match) {
    List<Processor> list = nav.next();
    if (list != null) {
        for (Processor proc : list) {
            String id = null;
            if (proc instanceof IdAware) {
                id = ((IdAware) proc).getId();
            }
            if (EndpointHelper.matchPattern(id, pattern)) {
                match.add(proc);
            }
            if (proc instanceof Navigate) {
                Navigate<Processor> child = (Navigate<Processor>) proc;
                doFilter(pattern, child, match);
            }
        }
    }
}
Also used : Processor(org.apache.camel.Processor) IdAware(org.apache.camel.spi.IdAware) Navigate(org.apache.camel.Navigate)

Aggregations

Processor (org.apache.camel.Processor)3 IdAware (org.apache.camel.spi.IdAware)3 ExpressionDefinition (org.apache.camel.model.language.ExpressionDefinition)2 InterceptEndpointProcessor (org.apache.camel.processor.InterceptEndpointProcessor)2 ArrayList (java.util.ArrayList)1 Channel (org.apache.camel.Channel)1 Navigate (org.apache.camel.Navigate)1 DefaultChannel (org.apache.camel.processor.interceptor.DefaultChannel)1