Search in sources :

Example 1 with StreamCaching

use of org.apache.camel.processor.interceptor.StreamCaching in project camel by apache.

the class ProcessorDefinition method addInterceptStrategies.

/**
     * Adds the given list of interceptors to the channel.
     *
     * @param routeContext  the route context
     * @param channel       the channel to add strategies
     * @param strategies    list of strategies to add.
     */
protected void addInterceptStrategies(RouteContext routeContext, Channel channel, List<InterceptStrategy> strategies) {
    for (InterceptStrategy strategy : strategies) {
        if (!routeContext.isStreamCaching() && strategy instanceof StreamCaching) {
            // stream cache is disabled so we should not add it
            continue;
        }
        if (!routeContext.isHandleFault() && strategy instanceof HandleFault) {
            // handle fault is disabled so we should not add it
            continue;
        }
        if (strategy instanceof Delayer) {
            if (routeContext.getDelayer() == null || routeContext.getDelayer() <= 0) {
                // delayer is disabled so we should not add it
                continue;
            } else {
                // replace existing delayer as delayer have individual configuration
                Iterator<InterceptStrategy> it = channel.getInterceptStrategies().iterator();
                while (it.hasNext()) {
                    InterceptStrategy existing = it.next();
                    if (existing instanceof Delayer) {
                        it.remove();
                    }
                }
                // add the new correct delayer
                channel.addInterceptStrategy(strategy);
                continue;
            }
        }
        // add strategy
        channel.addInterceptStrategy(strategy);
    }
}
Also used : Delayer(org.apache.camel.processor.interceptor.Delayer) InterceptStrategy(org.apache.camel.spi.InterceptStrategy) StreamCaching(org.apache.camel.processor.interceptor.StreamCaching) HandleFault(org.apache.camel.processor.interceptor.HandleFault)

Aggregations

Delayer (org.apache.camel.processor.interceptor.Delayer)1 HandleFault (org.apache.camel.processor.interceptor.HandleFault)1 StreamCaching (org.apache.camel.processor.interceptor.StreamCaching)1 InterceptStrategy (org.apache.camel.spi.InterceptStrategy)1