当前位置: 首页>>代码示例>>Java>>正文


Java AggregationStrategy类代码示例

本文整理汇总了Java中org.apache.camel.processor.aggregate.AggregationStrategy的典型用法代码示例。如果您正苦于以下问题:Java AggregationStrategy类的具体用法?Java AggregationStrategy怎么用?Java AggregationStrategy使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


AggregationStrategy类属于org.apache.camel.processor.aggregate包,在下文中一共展示了AggregationStrategy类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: createCompositeProcessor

import org.apache.camel.processor.aggregate.AggregationStrategy; //导入依赖的package包/类
protected Processor createCompositeProcessor(RouteContext routeContext, List<Processor> list) throws Exception {
    final AggregationStrategy strategy = createAggregationStrategy(routeContext);

    boolean isParallelProcessing = getParallelProcessing() != null && getParallelProcessing();
    boolean isShareUnitOfWork = getShareUnitOfWork() != null && getShareUnitOfWork();
    boolean isStreaming = getStreaming() != null && getStreaming();
    boolean isStopOnException = getStopOnException() != null && getStopOnException();
    boolean isParallelAggregate = getParallelAggregate() != null && getParallelAggregate();

    boolean shutdownThreadPool = ProcessorDefinitionHelper.willCreateNewThreadPool(routeContext, this, isParallelProcessing);
    ExecutorService threadPool = ProcessorDefinitionHelper.getConfiguredExecutorService(routeContext, "Multicast", this, isParallelProcessing);

    long timeout = getTimeout() != null ? getTimeout() : 0;
    if (timeout > 0 && !isParallelProcessing) {
        throw new IllegalArgumentException("Timeout is used but ParallelProcessing has not been enabled.");
    }
    if (onPrepareRef != null) {
        onPrepare = CamelContextHelper.mandatoryLookup(routeContext.getCamelContext(), onPrepareRef, Processor.class);
    }

    MulticastProcessor answer = new MulticastProcessor(routeContext.getCamelContext(), list, strategy, isParallelProcessing,
                                  threadPool, shutdownThreadPool, isStreaming, isStopOnException, timeout, onPrepare, isShareUnitOfWork, isParallelAggregate);
    return answer;
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:25,代码来源:MulticastDefinition.java

示例2: createProcessor

import org.apache.camel.processor.aggregate.AggregationStrategy; //导入依赖的package包/类
@Override
public Processor createProcessor(RouteContext routeContext) throws Exception {

    // if no timeout then we should block, and there use a negative timeout
    long time = timeout != null ? timeout : -1;
    boolean isIgnoreInvalidEndpoint = getIgnoreInvalidEndpoint() != null && getIgnoreInvalidEndpoint();
    Expression exp = getExpression().createExpression(routeContext);

    PollEnricher enricher = new PollEnricher(exp, time);

    AggregationStrategy strategy = createAggregationStrategy(routeContext);
    if (strategy == null) {
        enricher.setDefaultAggregationStrategy();
    } else {
        enricher.setAggregationStrategy(strategy);
    }
    if (getAggregateOnException() != null) {
        enricher.setAggregateOnException(getAggregateOnException());
    }
    if (getCacheSize() != null) {
        enricher.setCacheSize(getCacheSize());
    }
    enricher.setIgnoreInvalidEndpoint(isIgnoreInvalidEndpoint);

    return enricher;
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:27,代码来源:PollEnrichDefinition.java

示例3: updateHeader

import org.apache.camel.processor.aggregate.AggregationStrategy; //导入依赖的package包/类
private AggregationStrategy updateHeader() {
    return new AggregationStrategy() {
        @Override
        public Exchange aggregate(Exchange oldExchange, Exchange newExchange) {
            if (oldExchange != null) {
                String processedFiles = oldExchange.getIn().getHeader(PROCESSED_FILES_HEADER_NAME, String.class);
                if (processedFiles == null) {
                    processedFiles = oldExchange.getIn().getHeader(TarIterator.TARFILE_ENTRY_NAME_HEADER, String.class);
                }
                processedFiles = processedFiles + "," + newExchange.getIn().getHeader(TarIterator.TARFILE_ENTRY_NAME_HEADER, String.class);
                newExchange.getIn().setHeader(PROCESSED_FILES_HEADER_NAME, processedFiles);
            }
            return newExchange;
        }
        
    };
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:18,代码来源:TarFileMultipleFilesSplitterTest.java

示例4: createProcessor

import org.apache.camel.processor.aggregate.AggregationStrategy; //导入依赖的package包/类
@Override
public Processor createProcessor(RouteContext routeContext) throws Exception {

    Expression exp = getExpression().createExpression(routeContext);
    boolean isShareUnitOfWork = getShareUnitOfWork() != null && getShareUnitOfWork();
    boolean isIgnoreInvalidEndpoint = getIgnoreInvalidEndpoint() != null && getIgnoreInvalidEndpoint();

    Enricher enricher = new Enricher(exp);
    enricher.setShareUnitOfWork(isShareUnitOfWork);
    enricher.setIgnoreInvalidEndpoint(isIgnoreInvalidEndpoint);
    AggregationStrategy strategy = createAggregationStrategy(routeContext);
    if (strategy != null) {
        enricher.setAggregationStrategy(strategy);
    }
    if (aggregateOnException != null) {
        enricher.setAggregateOnException(aggregateOnException);
    }
    return enricher;
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:20,代码来源:EnrichDefinition.java

示例5: createRouteBuilder

import org.apache.camel.processor.aggregate.AggregationStrategy; //导入依赖的package包/类
@Override
protected RouteBuilder createRouteBuilder() throws Exception {
    return new RouteBuilder() {
        @Override
        public void configure() throws Exception {
            AggregationStrategy aggregationStrategy = new AggregationStrategy() {
                @Override
                public Exchange aggregate(Exchange oldExchange, Exchange newExchange) {
                    if (oldExchange == null) {
                        return newExchange;
                    }
                    String oldBody = oldExchange.getIn().getBody(String.class);
                    String newBody = newExchange.getIn().getBody(String.class);
                    oldExchange.getIn().setBody(oldBody + "," + newBody);
                    return oldExchange;
                }
            };
            from("direct:input")
                    .aggregate(header("aggregationId"), aggregationStrategy)
                    .completionSize(3).completionTimeout(3000L)
                    .aggregationRepository(aggregationRepository)
                    .to("mock:output");
        }
    };
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:26,代码来源:CassandraAggregationTest.java

示例6: process

import org.apache.camel.processor.aggregate.AggregationStrategy; //导入依赖的package包/类
@Override
public boolean process(Exchange exchange, final AsyncCallback callback) {
    final AggregationStrategy strategy = getAggregationStrategy();

    // if no custom aggregation strategy is being used then fallback to keep the original
    // and propagate exceptions which is done by a per exchange specific aggregation strategy
    // to ensure it supports async routing
    if (strategy == null) {
        AggregationStrategy original = new UseOriginalAggregationStrategy(exchange, true);
        if (isShareUnitOfWork()) {
            original = new ShareUnitOfWorkAggregationStrategy(original);
        }
        setAggregationStrategyOnExchange(exchange, original);
    }

    return super.process(exchange, callback);
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:18,代码来源:Splitter.java

示例7: MulticastProcessor

import org.apache.camel.processor.aggregate.AggregationStrategy; //导入依赖的package包/类
public MulticastProcessor(CamelContext camelContext, Collection<Processor> processors, AggregationStrategy aggregationStrategy,
                          boolean parallelProcessing, ExecutorService executorService, boolean shutdownExecutorService, boolean streaming,
                          boolean stopOnException, long timeout, Processor onPrepare, boolean shareUnitOfWork,
                          boolean parallelAggregate) {
    notNull(camelContext, "camelContext");
    this.camelContext = camelContext;
    this.processors = processors;
    this.aggregationStrategy = aggregationStrategy;
    this.executorService = executorService;
    this.shutdownExecutorService = shutdownExecutorService;
    this.streaming = streaming;
    this.stopOnException = stopOnException;
    // must enable parallel if executor service is provided
    this.parallelProcessing = parallelProcessing || executorService != null;
    this.timeout = timeout;
    this.onPrepare = onPrepare;
    this.shareUnitOfWork = shareUnitOfWork;
    this.parallelAggregate = parallelAggregate;
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:20,代码来源:MulticastProcessor.java

示例8: getAggregationStrategy

import org.apache.camel.processor.aggregate.AggregationStrategy; //导入依赖的package包/类
protected AggregationStrategy getAggregationStrategy(Exchange exchange) {
    AggregationStrategy answer = null;

    // prefer to use per Exchange aggregation strategy over a global strategy
    if (exchange != null) {
        Map<?, ?> property = exchange.getProperty(Exchange.AGGREGATION_STRATEGY, Map.class);
        Map<Object, AggregationStrategy> map = CastUtils.cast(property);
        if (map != null) {
            answer = map.get(this);
        }
    }
    if (answer == null) {
        // fallback to global strategy
        answer = getAggregationStrategy();
    }
    return answer;
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:18,代码来源:MulticastProcessor.java

示例9: setAggregationStrategyOnExchange

import org.apache.camel.processor.aggregate.AggregationStrategy; //导入依赖的package包/类
/**
 * Sets the given {@link org.apache.camel.processor.aggregate.AggregationStrategy} on the {@link Exchange}.
 *
 * @param exchange            the exchange
 * @param aggregationStrategy the strategy
 */
protected void setAggregationStrategyOnExchange(Exchange exchange, AggregationStrategy aggregationStrategy) {
    Map<?, ?> property = exchange.getProperty(Exchange.AGGREGATION_STRATEGY, Map.class);
    Map<Object, AggregationStrategy> map = CastUtils.cast(property);
    if (map == null) {
        map = new ConcurrentHashMap<Object, AggregationStrategy>();
    } else {
        // it is not safe to use the map directly as the exchange doesn't have the deep copy of it's properties
        // we just create a new copy if we need to change the map
        map = new ConcurrentHashMap<Object, AggregationStrategy>(map);
    }
    // store the strategy using this processor as the key
    // (so we can store multiple strategies on the same exchange)
    map.put(this, aggregationStrategy);
    exchange.setProperty(Exchange.AGGREGATION_STRATEGY, map);
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:22,代码来源:MulticastProcessor.java

示例10: createRouteBuilder

import org.apache.camel.processor.aggregate.AggregationStrategy; //导入依赖的package包/类
@Override
protected RouteBuilder createRouteBuilder() throws Exception {
    return new RouteBuilder() {
        public void configure() throws Exception {
            from("direct:in")
                .to("mock:pickedUp")
                // using the async utility component to ensure that the async routing engine kicks in
                .enrich("async:out?reply=Reply", new AggregationStrategy() {
                    @Override
                    public Exchange aggregate(Exchange oldExchange, Exchange newExchange) {
                        throw new RuntimeException("Bang! Unhandled exception");
                    }
                });
            
        }
    };
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:18,代码来源:EnricherAsyncUnhandledExceptionTest.java

示例11: createRouteBuilder

import org.apache.camel.processor.aggregate.AggregationStrategy; //导入依赖的package包/类
@Override
protected RouteBuilder createRouteBuilder() throws Exception {
    return new RouteBuilder() {
        public void configure() throws Exception {
            from(uri)
                .aggregate(constant(true), new AggregationStrategy() {
                    public Exchange aggregate(Exchange oldExchange, Exchange newExchange) {
                        Exchange answer = oldExchange != null ? oldExchange : newExchange;
                        COUNTER.getAndIncrement();

                        Integer newIndex = newExchange.getIn().getHeader("index", Integer.class);
                        int total = SUM.addAndGet(newIndex);
                        answer.getIn().setHeader("total", total);

                        LOG.debug("Index: " + newIndex + ". Total so far: " + total);
                        return answer;
                    }
                }).completionTimeout(60000).completionPredicate(property(Exchange.AGGREGATED_SIZE).isEqualTo(100))
                .to("direct:foo");

            from("direct:foo").setBody().header("total").to("mock:result");
        }
    };
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:25,代码来源:AggregatorConcurrencyTest.java

示例12: createRouteBuilder

import org.apache.camel.processor.aggregate.AggregationStrategy; //导入依赖的package包/类
@Override
protected RouteBuilder createRouteBuilder() throws Exception {
    return new RouteBuilder() {
        @Override
        public void configure() throws Exception {
            errorHandler(deadLetterChannel("mock:error"));

            onException(CamelException.class).maximumRedeliveries(2);

            from("seda:start")
                .aggregate(header("id"),
                    new AggregationStrategy() {
                        public Exchange aggregate(Exchange oldExchange, Exchange newExchange) {
                            return newExchange;
                        }
                    }).completionSize(2).completionTimeout(500L)
                .to("mock:result");
        }
    };
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:21,代码来源:AggregatorAndOnExceptionTest.java

示例13: createRouteBuilder

import org.apache.camel.processor.aggregate.AggregationStrategy; //导入依赖的package包/类
protected RouteBuilder createRouteBuilder() throws Exception {
    return new RouteBuilder() {
        public void configure() throws Exception {
            from(timeOutEndpointUri).to("jms:queue:test.b");

            from("jms:queue:test.b").aggregate(header("cheese"), new AggregationStrategy() {
                public Exchange aggregate(Exchange oldExchange, Exchange newExchange) {
                    try {
                        Thread.sleep(2000);
                    } catch (InterruptedException e) {
                        LOG.error("aggregration delay sleep inturrepted", e);
                        fail("aggregration delay sleep inturrepted");
                    }
                    return newExchange;
                }
            }).completionTimeout(2000L).to("mock:result");

            from(multicastEndpointUri).to("jms:queue:point1", "jms:queue:point2", "jms:queue:point3");
            from("jms:queue:point1").process(new MyProcessor()).to("jms:queue:reply");
            from("jms:queue:point2").process(new MyProcessor()).to("jms:queue:reply");
            from("jms:queue:point3").process(new MyProcessor()).to("jms:queue:reply");
            from("jms:queue:reply").aggregate(header("cheese"), new UseLatestAggregationStrategy()).completionSize(3)
                .to("mock:reply");
        }
    };
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:27,代码来源:AggregratedJmsRouteTest.java

示例14: aggregate

import org.apache.camel.processor.aggregate.AggregationStrategy; //导入依赖的package包/类
/**
 * <a href="http://camel.apache.org/aggregator.html">Aggregator EIP:</a>
 * Creates an aggregator allowing you to combine a number of messages together into a single message.
 *
 * @param aggregationStrategy the strategy used for the aggregation
 * @return the expression clause to be used as builder to configure the correlation expression
 */
public ExpressionClause<AggregateDefinition> aggregate(AggregationStrategy aggregationStrategy) {
    AggregateDefinition answer = new AggregateDefinition();
    ExpressionClause<AggregateDefinition> clause = new ExpressionClause<AggregateDefinition>(answer);
    answer.setExpression(clause);
    answer.setAggregationStrategy(aggregationStrategy);
    addOutput(answer);
    return clause;
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:16,代码来源:ProcessorDefinition.java

示例15: Splitter

import org.apache.camel.processor.aggregate.AggregationStrategy; //导入依赖的package包/类
@Deprecated
public Splitter(CamelContext camelContext, Expression expression, Processor destination, AggregationStrategy aggregationStrategy,
                boolean parallelProcessing, ExecutorService executorService, boolean shutdownExecutorService,
                boolean streaming, boolean stopOnException, long timeout, Processor onPrepare, boolean useSubUnitOfWork) {
    this(camelContext, expression, destination, aggregationStrategy, parallelProcessing, executorService, shutdownExecutorService,
            streaming, stopOnException, timeout, onPrepare, useSubUnitOfWork, false);
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:8,代码来源:Splitter.java


注:本文中的org.apache.camel.processor.aggregate.AggregationStrategy类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。