本文整理汇总了Java中org.apache.camel.util.ExchangeHelper.copyResults方法的典型用法代码示例。如果您正苦于以下问题:Java ExchangeHelper.copyResults方法的具体用法?Java ExchangeHelper.copyResults怎么用?Java ExchangeHelper.copyResults使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.camel.util.ExchangeHelper
的用法示例。
在下文中一共展示了ExchangeHelper.copyResults方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: consumed
import org.apache.camel.util.ExchangeHelper; //导入方法依赖的package包/类
public void consumed(Exchange result) {
if (processedConsumers.incrementAndGet() == expectedConsumers || result.getException() != null
&& !resultHandled.getAndSet(true)) {
// all consumers are done processing or an exception occurred
//SEDA Does not configure an aggregator in the internally used MulticastProcessor
//As a result, the behaviour of SEDA in case of multicast is to only copy the results on an error
if (result.getException() != null) {
ExchangeHelper.copyResults(getExchange(), result);
}
performSynchronization();
}
}
示例2: done
import org.apache.camel.util.ExchangeHelper; //导入方法依赖的package包/类
public void done(boolean doneSync) {
// we only have to handle async completion of the pipeline
if (doneSync) {
return;
}
while (shouldFailOver(copy)) {
// can we still run
if (!isRunAllowed()) {
log.trace("Run not allowed, will reject executing exchange: {}", exchange);
if (exchange.getException() == null) {
exchange.setException(new RejectedExecutionException());
}
// we cannot process so invoke callback
callback.done(false);
}
attempts.incrementAndGet();
// are we exhausted by attempts?
if (maximumFailoverAttempts > -1 && attempts.get() > maximumFailoverAttempts) {
log.trace("Breaking out of failover after {} failover attempts", attempts);
break;
}
index.incrementAndGet();
counter.incrementAndGet();
if (index.get() >= processors.size()) {
// out of bounds
if (isRoundRobin()) {
log.trace("Failover is round robin enabled and therefore starting from the first endpoint");
index.set(0);
counter.set(0);
} else {
// no more processors to try
log.trace("Breaking out of failover as we reached the end of endpoints to use for failover");
break;
}
}
// try again but prepare exchange before we failover
copy = prepareExchangeForFailover(exchange);
Processor processor = processors.get(index.get());
// try to failover using the next processor
doneSync = processExchange(processor, exchange, copy, attempts, index, callback, processors);
if (!doneSync) {
log.trace("Processing exchangeId: {} is continued being processed asynchronously", exchange.getExchangeId());
// the remainder of the failover will be completed async
// so we break out now, then the callback will be invoked which then continue routing from where we left here
return;
}
}
// remember last good index
lastGoodIndex.set(index.get());
// and copy the current result to original so it will contain this result of this eip
if (copy != null) {
ExchangeHelper.copyResults(exchange, copy);
}
log.debug("Failover complete for exchangeId: {} >>> {}", exchange.getExchangeId(), exchange);
// signal callback we are done
callback.done(false);
}
示例3: process
import org.apache.camel.util.ExchangeHelper; //导入方法依赖的package包/类
@Override
public boolean process(Exchange exchange, AsyncCallback callback) {
// use atomic integer to be able to pass reference and keep track on the values
AtomicInteger index = new AtomicInteger();
AtomicInteger count = new AtomicInteger();
AtomicBoolean doWhile = new AtomicBoolean();
try {
if (expression != null) {
// Intermediate conversion to String is needed when direct conversion to Integer is not available
// but evaluation result is a textual representation of a numeric value.
String text = expression.evaluate(exchange, String.class);
int num = ExchangeHelper.convertToMandatoryType(exchange, Integer.class, text);
count.set(num);
} else {
boolean result = predicate.matches(exchange);
doWhile.set(result);
}
} catch (Exception e) {
exchange.setException(e);
callback.done(true);
return true;
}
// we hold on to the original Exchange in case it's needed for copies
final Exchange original = exchange;
// per-iteration exchange
Exchange target = exchange;
// set the size before we start
if (predicate == null) {
exchange.setProperty(Exchange.LOOP_SIZE, count);
}
// loop synchronously
while ((predicate != null && doWhile.get()) || (index.get() < count.get())) {
// and prepare for next iteration
// if (!copy) target = exchange; else copy of original
target = prepareExchange(exchange, index.get(), original);
// the following process method will in the done method re-evaluate the predicate
// so we do not need to do it here as well
boolean sync = process(target, callback, index, count, doWhile, original);
if (!sync) {
LOG.trace("Processing exchangeId: {} is continued being processed asynchronously", target.getExchangeId());
// the remainder of the loop will be completed async
// so we break out now, then the callback will be invoked which then continue routing from where we left here
return false;
}
LOG.trace("Processing exchangeId: {} is continued being processed synchronously", target.getExchangeId());
// check for error if so we should break out
if (!continueProcessing(target, "so breaking out of loop", LOG)) {
break;
}
}
// we are done so prepare the result
ExchangeHelper.copyResults(exchange, target);
LOG.trace("Processing complete for exchangeId: {} >>> {}", exchange.getExchangeId(), exchange);
callback.done(true);
return true;
}
示例4: doDone
import org.apache.camel.util.ExchangeHelper; //导入方法依赖的package包/类
/**
* Common work which must be done when we are done multicasting.
* <p/>
* This logic applies for both running synchronous and asynchronous as there are multiple exist points
* when using the asynchronous routing engine. And therefore we want the logic in one method instead
* of being scattered.
*
* @param original the original exchange
* @param subExchange the current sub exchange, can be <tt>null</tt> for the synchronous part
* @param pairs the pairs with the exchanges to process
* @param callback the callback
* @param doneSync the <tt>doneSync</tt> parameter to call on callback
* @param forceExhaust whether or not error handling is exhausted
*/
protected void doDone(Exchange original, Exchange subExchange, final Iterable<ProcessorExchangePair> pairs,
AsyncCallback callback, boolean doneSync, boolean forceExhaust) {
// we are done so close the pairs iterator
if (pairs != null && pairs instanceof Closeable) {
IOHelper.close((Closeable) pairs, "pairs", LOG);
}
AggregationStrategy strategy = getAggregationStrategy(subExchange);
if (strategy instanceof DelegateAggregationStrategy) {
strategy = ((DelegateAggregationStrategy) strategy).getDelegate();
}
// invoke the on completion callback
if (strategy instanceof CompletionAwareAggregationStrategy) {
((CompletionAwareAggregationStrategy) strategy).onCompletion(subExchange);
}
// cleanup any per exchange aggregation strategy
removeAggregationStrategyFromExchange(original);
// we need to know if there was an exception, and if the stopOnException option was enabled
// also we would need to know if any error handler has attempted redelivery and exhausted
boolean stoppedOnException = false;
boolean exception = false;
boolean exhaust = forceExhaust || subExchange != null && (subExchange.getException() != null || ExchangeHelper.isRedeliveryExhausted(subExchange));
if (original.getException() != null || subExchange != null && subExchange.getException() != null) {
// there was an exception and we stopped
stoppedOnException = isStopOnException();
exception = true;
}
// must copy results at this point
if (subExchange != null) {
if (stoppedOnException) {
// if we stopped due an exception then only propagate the exception
original.setException(subExchange.getException());
} else {
// copy the current result to original so it will contain this result of this eip
ExchangeHelper.copyResults(original, subExchange);
}
}
// .. and then if there was an exception we need to configure the redelivery exhaust
// for example the noErrorHandler will not cause redelivery exhaust so if this error
// handled has been in use, then the exhaust would be false (if not forced)
if (exception) {
// multicast uses error handling on its output processors and they have tried to redeliver
// so we shall signal back to the other error handlers that we are exhausted and they should not
// also try to redeliver as we will then do that twice
original.setProperty(Exchange.REDELIVERY_EXHAUSTED, exhaust);
}
callback.done(doneSync);
}
示例5: process
import org.apache.camel.util.ExchangeHelper; //导入方法依赖的package包/类
public boolean process(Exchange exchange, AsyncCallback callback) {
Iterator<Processor> processors = getProcessors().iterator();
Exchange nextExchange = exchange;
boolean first = true;
while (continueRouting(processors, nextExchange)) {
if (first) {
first = false;
} else {
// prepare for next run
nextExchange = createNextExchange(nextExchange);
}
// get the next processor
Processor processor = processors.next();
AsyncProcessor async = AsyncProcessorConverterHelper.convert(processor);
boolean sync = process(exchange, nextExchange, callback, processors, async);
// continue as long its being processed synchronously
if (!sync) {
LOG.trace("Processing exchangeId: {} is continued being processed asynchronously", exchange.getExchangeId());
// the remainder of the pipeline will be completed async
// so we break out now, then the callback will be invoked which then continue routing from where we left here
return false;
}
LOG.trace("Processing exchangeId: {} is continued being processed synchronously", exchange.getExchangeId());
// check for error if so we should break out
if (!continueProcessing(nextExchange, "so breaking out of pipeline", LOG)) {
break;
}
}
// logging nextExchange as it contains the exchange that might have altered the payload and since
// we are logging the completion if will be confusing if we log the original instead
// we could also consider logging the original and the nextExchange then we have *before* and *after* snapshots
LOG.trace("Processing complete for exchangeId: {} >>> {}", exchange.getExchangeId(), nextExchange);
// copy results back to the original exchange
ExchangeHelper.copyResults(exchange, nextExchange);
callback.done(true);
return true;
}
示例6: consumed
import org.apache.camel.util.ExchangeHelper; //导入方法依赖的package包/类
@Override
public void consumed(Exchange result) {
ExchangeHelper.copyResults(getExchange(), result);
performSynchronization();
}
示例7: finalizeAggregate
import org.apache.camel.util.ExchangeHelper; //导入方法依赖的package包/类
/**
* Creates the actual aggregation result of the processor
* This method is called by {@link #processNext(Exchange)} to calculate the
* aggregation result of the splitter. The base implementation in this class
* simply copies the results of the aggregate into the original exchange.
* Sub classes should call this base method implementation to ensure
* compatibility with upcoming version.
*
* @param origExchange the exchange that was originally passed to {@link #process(Exchange)}.
* The base implementation changes the content of this exchange to
* ensure that further processing in the route is performed with
* the aggregated result.
* @param aggregate the aggregation result. This is the exchange that was determined
* by passing all processed sub exchanges to the {@link AggregationStrategy}
* defined by {@link #aggregate(AggregationStrategy)}. This parameter
* can be {@code null} if the {@link AggregationStrategy} returned
* null.
*/
protected void finalizeAggregate(Exchange origExchange, Exchange aggregate) {
if (aggregate != null) {
ExchangeHelper.copyResults(origExchange, aggregate);
}
}