如何识别是否所有节点都已处理。

时间:2015-06-12 17:43:18

标签: apache-camel

我创建了一个添加到上下文的拦截器。此拦截器正在为路径中的每个节点执行。但我想确定何时完成所有节点的处理并执行某些操作。

public class MyInterceptStrategy implements InterceptStrategy {

public int count = 0;

@Override
public Processor wrapProcessorInInterceptors(final CamelContext context,
        final ProcessorDefinition<?> definition, final Processor target,
        final Processor nextTarget) throws Exception {
    return new DelegateAsyncProcessor(new Processor() {

        @Override
        public void process(Exchange exchange) throws Exception {
            count++;
            target.process(exchange);
            //if this is the last node print the message "all nodes processed" and count is "count"
            //System.out.println(count);
        }
    }) {

    };

}

}

UPDATE:尝试这样做以获得节点的总数,但这会返回所有路由中的所有节点,而不仅仅是有资格进行处理的节点。

public int getTotalProcessors(CamelContext context) {
    int totalProcessorsCount = 0;
    for (Route r : context.getRoutes()) {
        totalProcessorsCount = totalProcessorsCount + r.getRouteContext().getRoute().getOutputs().size();
    }
    return totalProcessorsCount;
}

0 个答案:

没有答案