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


Java DefaultConsumer类代码示例

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


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

示例1: getResultsProcessed

import org.apache.camel.impl.DefaultConsumer; //导入依赖的package包/类
/**
 * Utility method for Consumers to process API method invocation result.
 * @param consumer Consumer that wants to process results.
 * @param result result of API method invocation.
 * @param splitResult true if the Consumer wants to split result using {@link org.apache.camel.util.component.ResultInterceptor#splitResult(Object)} method.
 * @param <T> Consumer class that extends DefaultConsumer and implements {@link org.apache.camel.util.component.ResultInterceptor}.
 * @return number of result exchanges processed.
 * @throws Exception on error.
 */
public static <T extends DefaultConsumer & ResultInterceptor> int getResultsProcessed(
    T consumer, Object result, boolean splitResult) throws Exception {

    // process result according to type
    if (result != null && splitResult) {
        // try to split the result
        final Object resultArray = consumer.splitResult(result);

        if (resultArray != result && resultArray.getClass().isArray()) {
            // create an exchange for every element
            final int length = Array.getLength(resultArray);
            for (int i = 0; i < length; i++) {
                processResult(consumer, result, Array.get(resultArray, i));
            }
            return length;
        }
    }

    processResult(consumer, result, result);
    return 1; // number of messages polled
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:31,代码来源:ApiConsumerHelper.java

示例2: processResult

import org.apache.camel.impl.DefaultConsumer; //导入依赖的package包/类
private static <T extends DefaultConsumer & ResultInterceptor> void processResult(T consumer, Object methodResult, Object result)
    throws Exception {

    Exchange exchange = consumer.getEndpoint().createExchange();
    exchange.getIn().setBody(result);

    consumer.interceptResult(methodResult, exchange);
    try {
        // send message to next processor in the route
        consumer.getProcessor().process(exchange);
    } finally {
        // log exception if an exception occurred and was not handled
        final Exception exception = exchange.getException();
        if (exception != null) {
            consumer.getExceptionHandler().handleException("Error processing exchange", exchange, exception);
        }
    }
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:19,代码来源:ApiConsumerHelper.java

示例3: process

import org.apache.camel.impl.DefaultConsumer; //导入依赖的package包/类
@Override
public void process(final Exchange exchange) throws Exception {
    final int count = getHeaderValue(exchange, HEADER_ITERATIONS);
    final int threads = getHeaderValue(exchange, HEADER_THREADS);
    PerformanceTestEndpoint endpoint = (PerformanceTestEndpoint)getEndpoint();
    if (endpoint != null) {
        final DefaultConsumer consumer = (DefaultConsumer)endpoint.getConsumer();
        ExecutorService executor = exchange.getContext().getExecutorServiceManager().newFixedThreadPool(this, "perf", threads);
        CompletionService<Exchange> tasks = new ExecutorCompletionService<Exchange>(executor);

        // StopWatch watch = new StopWatch();  // if we want to clock how long it takes
        for (int i = 0; i < count; i++) {
            tasks.submit(new Callable<Exchange>() {
                @Override
                public Exchange call() throws Exception {
                    Exchange exch = ExchangeHelper.createCopy(exchange, false);
                    try {
                        consumer.getProcessor().process(exch);
                    } catch (final Exception e) {
                        exch.setException(e);
                    }
                    return exch;
                }
            });
        }
        
        for (int i = 0; i < count; i++) {
            // Future<Exchange> result = tasks.take();
            tasks.take();       // wait for all exchanges to complete
        }
    }
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:33,代码来源:PerformanceTestComponent.java

示例4: createConsumer

import org.apache.camel.impl.DefaultConsumer; //导入依赖的package包/类
@Override
public Consumer createConsumer(Processor processor) throws Exception {
    return new DefaultConsumer(this, processor) {
        @Override
        protected void doStart() throws Exception {
            processors.add(getProcessor());
        }
        
        @Override
        protected void doStop() throws Exception {
            processors.remove(getProcessor());                   
        }
    };
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:15,代码来源:TradeExecutorComponent.java

示例5: getConsumers

import org.apache.camel.impl.DefaultConsumer; //导入依赖的package包/类
protected Set<DefaultConsumer> getConsumers() {
    return consumers;
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:4,代码来源:ApnsEndpoint.java


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