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


Java AsyncCallback类代码示例

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


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

示例1: wrapProcessorInInterceptors

import org.apache.camel.AsyncCallback; //导入依赖的package包/类
public Processor wrapProcessorInInterceptors(final CamelContext context, final ProcessorDefinition<?> definition,
                                             final Processor target, final Processor nextTarget) throws Exception {

    // use DelegateAsyncProcessor to ensure the interceptor works well with the asynchronous routing
    // engine in Camel.
    // The target is the processor to continue routing to, which we must provide
    // in the constructor of the DelegateAsyncProcessor
    return new DelegateAsyncProcessor(target) {
        @Override
        public boolean process(Exchange exchange, AsyncCallback callback) {
            // we just want to count number of interceptions
            counter.incrementAndGet();

            // invoke processor to continue routing the message
            return processor.process(exchange, callback);
        }
    };
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:19,代码来源:AsyncEndpointCustomAsyncInterceptorTest.java

示例2: process

import org.apache.camel.AsyncCallback; //导入依赖的package包/类
@Override
public boolean process(Exchange exchange, AsyncCallback callback) {
    try {
        Object newHeader = expression.evaluate(exchange, Object.class);

        if (exchange.getException() != null) {
            // the expression threw an exception so we should break-out
            callback.done(true);
            return true;
        }

        boolean out = exchange.hasOut();
        Message old = out ? exchange.getOut() : exchange.getIn();

        String key = headerName.evaluate(exchange, String.class);
        old.setHeader(key, newHeader);

    } catch (Throwable e) {
        exchange.setException(e);
    }

    callback.done(true);
    return true;
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:25,代码来源:SetHeaderProcessor.java

示例3: processBatch

import org.apache.camel.AsyncCallback; //导入依赖的package包/类
@Override
public int processBatch(Queue<Object> exchanges) throws Exception {
    int processedExchanges = 0;
    while (!exchanges.isEmpty()) {
        final Exchange exchange = ObjectHelper.cast(Exchange.class, exchanges.poll());

        LOG.trace("Processing exchange [{}] started.", exchange);
        getAsyncProcessor().process(exchange, new AsyncCallback() {
            @Override
            public void done(boolean doneSync) {
                LOG.trace("Processing exchange [{}] done.", exchange);
            }
        });
        processedExchanges++;
    }
    return processedExchanges;
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:18,代码来源:DdbStreamConsumer.java

示例4: doBroadcast

import org.apache.camel.AsyncCallback; //导入依赖的package包/类
@SuppressWarnings("unchecked")
private void doBroadcast(final Exchange exchange, final AsyncCallback callback, IgniteCompute compute) throws Exception {
    Object job = exchange.getIn().getBody();

    if (IgniteCallable.class.isAssignableFrom(job.getClass())) {
        compute.broadcast((IgniteCallable<?>) job);
    } else if (IgniteRunnable.class.isAssignableFrom(job.getClass())) {
        compute.broadcast((IgniteRunnable) job);
    } else if (IgniteClosure.class.isAssignableFrom(job.getClass())) {
        compute.broadcast((IgniteClosure<Object, Object>) job, exchange.getIn().getHeader(IgniteConstants.IGNITE_COMPUTE_PARAMS));
    } else {
        throw new RuntimeCamelException(
                String.format("Ignite Compute endpoint with BROADCAST executionType is only " + "supported for IgniteCallable, IgniteRunnable or IgniteClosure payloads. The payload type was: %s.",
                        job.getClass().getName()));
    }
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:17,代码来源:IgniteComputeProducer.java

示例5: doApply

import org.apache.camel.AsyncCallback; //导入依赖的package包/类
@SuppressWarnings("unchecked")
private  <T, R1, R2> void doApply(final Exchange exchange, final AsyncCallback callback, IgniteCompute compute) throws Exception {
    IgniteClosure<T, R1> job = exchange.getIn().getBody(IgniteClosure.class);
    T params = (T) exchange.getIn().getHeader(IgniteConstants.IGNITE_COMPUTE_PARAMS);

    if (job == null || params == null) {
        throw new RuntimeCamelException(
                String.format("Ignite Compute endpoint with APPLY executionType is only " + "supported for IgniteClosure payloads with parameters. The payload type was: %s.",
                        exchange.getIn().getBody().getClass().getName()));
    }

    IgniteReducer<R1, R2> reducer = exchange.getIn().getHeader(IgniteConstants.IGNITE_COMPUTE_REDUCER, IgniteReducer.class);

    if (Collection.class.isAssignableFrom(params.getClass())) {
        Collection<T> colParams = (Collection<T>) params;
        if (reducer == null) {
            compute.apply(job, colParams);
        } else {
            compute.apply(job, colParams, reducer);
        }
    } else {
        compute.apply(job, params);
    }
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:25,代码来源:IgniteComputeProducer.java

示例6: process

import org.apache.camel.AsyncCallback; //导入依赖的package包/类
public boolean process(Exchange exchange, AsyncCallback callback) {
    String body = exchange.getIn().getBody(String.class);
    try {
        if ("x".equals(body)) {
            getProcessors().get(0).process(exchange);
        } else if ("y".equals(body)) {
            getProcessors().get(1).process(exchange);
        } else {
            getProcessors().get(2).process(exchange);
        }
    } catch (Throwable e) {
        exchange.setException(e);
    }
    callback.done(true);
    return true;
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:17,代码来源:ManagedCustomLoadBalancerTest.java

示例7: process

import org.apache.camel.AsyncCallback; //导入依赖的package包/类
@Override
public boolean process(Exchange exchange, AsyncCallback callback) {
    Message in = exchange.getIn();
    Message out = exchange.getOut();
    MessageHelper.copyHeaders(exchange.getIn(), out, true);

    Object body = in.getBody();

    if (endpoint.getSendMode() == IgniteMessagingSendMode.UNORDERED) {
        if (body instanceof Collection<?> && !endpoint.isTreatCollectionsAsCacheObjects()) {
            messaging.send(topicFor(exchange), (Collection<?>) body);
        } else {
            messaging.send(topicFor(exchange), body);
        }
    } else {
        messaging.sendOrdered(topicFor(exchange), body, endpoint.getTimeout());
    }

    IgniteHelper.maybePropagateIncomingBody(endpoint, in, out);

    return true;
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:23,代码来源:IgniteMessagingProducer.java

示例8: processAsynchronously

import org.apache.camel.AsyncCallback; //导入依赖的package包/类
private void processAsynchronously(final Exchange exchange, final MessageEvent messageEvent) {
    consumer.getAsyncProcessor().process(exchange, new AsyncCallback() {
        @Override
        public void done(boolean doneSync) {
            // send back response if the communication is synchronous
            try {
                if (consumer.getConfiguration().isSync()) {
                    sendResponse(messageEvent, exchange);
                }
            } catch (Throwable e) {
                consumer.getExceptionHandler().handleException(e);
            } finally {
                consumer.doneUoW(exchange);
            }
        }
    });
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:18,代码来源:ServerChannelHandler.java

示例9: processCreateBatchQuery

import org.apache.camel.AsyncCallback; //导入依赖的package包/类
private void processCreateBatchQuery(final Exchange exchange, final AsyncCallback callback) throws SalesforceException {
    JobInfo jobBody;
    String jobId;
    ContentType contentType;
    jobBody = exchange.getIn().getBody(JobInfo.class);
    String soqlQuery;
    if (jobBody != null) {
        jobId = jobBody.getId();
        contentType = jobBody.getContentType();
        // use SOQL query from header or endpoint config
        soqlQuery = getParameter(SOBJECT_QUERY, exchange, IGNORE_BODY, NOT_OPTIONAL);
    } else {
        jobId = getParameter(JOB_ID, exchange, IGNORE_BODY, NOT_OPTIONAL);
        contentType = ContentType.fromValue(
                getParameter(CONTENT_TYPE, exchange, IGNORE_BODY, NOT_OPTIONAL));
        // reuse SOBJECT_QUERY property
        soqlQuery = getParameter(SOBJECT_QUERY, exchange, USE_BODY, NOT_OPTIONAL);
    }
    bulkClient.createBatchQuery(jobId, soqlQuery, contentType,
            new BulkApiClient.BatchInfoResponseCallback() {
                @Override
                public void onResponse(BatchInfo batchInfo, SalesforceException ex) {
                    processResponse(exchange, batchInfo, ex, callback);
                }
            });
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:27,代码来源:BulkApiProcessor.java

示例10: itResumesFromAfterTheLastSeenSequenceNumberWhenAShardIteratorHasExpired

import org.apache.camel.AsyncCallback; //导入依赖的package包/类
@Test
public void itResumesFromAfterTheLastSeenSequenceNumberWhenAShardIteratorHasExpired() throws Exception {
    endpoint.setIteratorType(ShardIteratorType.LATEST);
    when(shardIteratorHandler.getShardIterator(anyString())).thenReturn("shard_iterator_b_000", "shard_iterator_b_001", "shard_iterator_b_001");
    Mockito.reset(amazonDynamoDBStreams);
    when(amazonDynamoDBStreams.getRecords(any(GetRecordsRequest.class)))
            .thenAnswer(recordsAnswer)
            .thenThrow(new ExpiredIteratorException("expired shard"))
            .thenAnswer(recordsAnswer);

    undertest.poll();
    undertest.poll();

    ArgumentCaptor<Exchange> exchangeCaptor = ArgumentCaptor.forClass(Exchange.class);
    verify(processor, times(3)).process(exchangeCaptor.capture(), any(AsyncCallback.class));
    verify(shardIteratorHandler, times(2)).getShardIterator(null); // first poll. Second poll, getRecords fails with an expired shard.
    verify(shardIteratorHandler).getShardIterator("9"); // second poll, with a resumeFrom.
    assertThat(exchangeCaptor.getAllValues().get(0).getIn().getBody(Record.class).getDynamodb().getSequenceNumber(), is("9"));
    assertThat(exchangeCaptor.getAllValues().get(1).getIn().getBody(Record.class).getDynamodb().getSequenceNumber(), is("11"));
    assertThat(exchangeCaptor.getAllValues().get(2).getIn().getBody(Record.class).getDynamodb().getSequenceNumber(), is("13"));
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:22,代码来源:DdbStreamConsumerTest.java

示例11: dispatchToInnerRoute

import org.apache.camel.AsyncCallback; //导入依赖的package包/类
private void dispatchToInnerRoute(BlockingQueue<Exchange> queue, final Exchange exchange) throws InterruptedException {
    Exchange result;

    if (exchange != null) {
        if (isRunAllowed()) {
            try {
                LOG.debug("Dispatching to inner route: {}", exchange);
                RouteboxDispatcher dispatcher = new RouteboxDispatcher(producer);
                result = dispatcher.dispatchAsync(getRouteboxEndpoint(), exchange); 
                processor.process(result, new AsyncCallback() {
                    public void done(boolean doneSync) {
                        // noop
                    }
                });
            } catch (Exception e) {
                getExceptionHandler().handleException("Error processing exchange", exchange, e);
            }
        } else {
            if (LOG.isWarnEnabled()) {
                LOG.warn("This consumer is stopped during polling an exchange, so putting it back on the seda queue: " + exchange);
            }                
            queue.put(exchange);
        }
    }
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:26,代码来源:RouteboxSedaConsumer.java

示例12: process

import org.apache.camel.AsyncCallback; //导入依赖的package包/类
public boolean process(Exchange exchange, AsyncCallback callback) {
    if (startTime == 0) {
        startTime = System.currentTimeMillis();
    }
    int receivedCount = receivedCounter.incrementAndGet();

    //only process if groupSize is set...otherwise we're in groupInterval mode
    if (groupSize != null) {
        if (receivedCount % groupSize == 0) {
            lastLogMessage = createLogMessage(exchange, receivedCount);
            log.log(lastLogMessage);
        }
    }

    callback.done(true);
    return true;
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:18,代码来源:ThroughputLogger.java

示例13: process

import org.apache.camel.AsyncCallback; //导入依赖的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

示例14: process

import org.apache.camel.AsyncCallback; //导入依赖的package包/类
@Override
public boolean process(Exchange exchange, AsyncCallback callback) {
    try {
        Object newProperty = expression.evaluate(exchange, Object.class);

        if (exchange.getException() != null) {
            // the expression threw an exception so we should break-out
            callback.done(true);
            return true;
        }

        String key = propertyName.evaluate(exchange, String.class);
        exchange.setProperty(key, newProperty);
    } catch (Throwable e) {
        exchange.setException(e);
    }

    callback.done(true);
    return true;
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:21,代码来源:SetPropertyProcessor.java

示例15: process

import org.apache.camel.AsyncCallback; //导入依赖的package包/类
@Override
public boolean process(Exchange exchange, AsyncCallback callback) {
    boolean matches = false;

    try {
        matches = matches(exchange);
    } catch (Exception e) {
        exchange.setException(e);
    }

    if (matches) {
        return processor.process(exchange, callback);
    } else {
        callback.done(true);
        return true;
    }
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:18,代码来源:FilterProcessor.java


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