本文整理汇总了Java中org.apache.camel.util.ExchangeHelper.createCorrelatedCopy方法的典型用法代码示例。如果您正苦于以下问题:Java ExchangeHelper.createCorrelatedCopy方法的具体用法?Java ExchangeHelper.createCorrelatedCopy怎么用?Java ExchangeHelper.createCorrelatedCopy使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.camel.util.ExchangeHelper
的用法示例。
在下文中一共展示了ExchangeHelper.createCorrelatedCopy方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: configureCopyExchange
import org.apache.camel.util.ExchangeHelper; //导入方法依赖的package包/类
private Exchange configureCopyExchange(Exchange exchange) {
// must use a copy as we dont want it to cause side effects of the original exchange
Exchange copy = ExchangeHelper.createCorrelatedCopy(exchange, false);
// set MEP to InOnly as this wire tap is a fire and forget
copy.setPattern(ExchangePattern.InOnly);
return copy;
}
示例2: createResourceExchange
import org.apache.camel.util.ExchangeHelper; //导入方法依赖的package包/类
/**
* Creates a new {@link DefaultExchange} instance from the given
* <code>exchange</code>. The resulting exchange's pattern is defined by
* <code>pattern</code>.
*
* @param source exchange to copy from.
* @param pattern exchange pattern to set.
* @return created exchange.
*/
protected Exchange createResourceExchange(Exchange source, ExchangePattern pattern) {
// copy exchange, and do not share the unit of work
Exchange target = ExchangeHelper.createCorrelatedCopy(source, false);
target.setPattern(pattern);
// if we share unit of work, we need to prepare the resource exchange
if (isShareUnitOfWork()) {
target.setProperty(Exchange.PARENT_UNIT_OF_WORK, source.getUnitOfWork());
// and then share the unit of work
target.setUnitOfWork(source.getUnitOfWork());
}
return target;
}
示例3: prepareExchange
import org.apache.camel.util.ExchangeHelper; //导入方法依赖的package包/类
/**
* Prepares the {@link Exchange} to send as onCompletion.
*
* @param exchange the current exchange
* @return the exchange to be routed in onComplete
*/
protected Exchange prepareExchange(Exchange exchange) {
Exchange answer;
if (isCreateCopy()) {
// for asynchronous routing we must use a copy as we dont want it
// to cause side effects of the original exchange
// (the original thread will run in parallel)
answer = ExchangeHelper.createCorrelatedCopy(exchange, false);
if (answer.hasOut()) {
// move OUT to IN (pipes and filters)
answer.setIn(answer.getOut());
answer.setOut(null);
}
// set MEP to InOnly as this onCompletion is a fire and forget
answer.setPattern(ExchangePattern.InOnly);
} else {
// use the exchange as-is
answer = exchange;
}
if (useOriginalBody) {
LOG.trace("Using the original IN message instead of current");
Message original = ExchangeHelper.getOriginalInMessage(exchange);
answer.setIn(original);
}
// add a header flag to indicate its a on completion exchange
answer.setProperty(Exchange.ON_COMPLETION, Boolean.TRUE);
return answer;
}
示例4: createProcessorExchangePair
import org.apache.camel.util.ExchangeHelper; //导入方法依赖的package包/类
/**
* This logic is similar to MulticastProcessor but we have to return a RecipientProcessorExchangePair instead
*/
protected ProcessorExchangePair createProcessorExchangePair(int index, Endpoint endpoint, Producer producer, Exchange exchange, ExchangePattern pattern) {
Processor prepared = producer;
// copy exchange, and do not share the unit of work
Exchange copy = ExchangeHelper.createCorrelatedCopy(exchange, false);
// if we share unit of work, we need to prepare the child exchange
if (isShareUnitOfWork()) {
prepareSharedUnitOfWork(copy, exchange);
}
// set property which endpoint we send to
setToEndpoint(copy, prepared);
// rework error handling to support fine grained error handling
RouteContext routeContext = exchange.getUnitOfWork() != null ? exchange.getUnitOfWork().getRouteContext() : null;
prepared = createErrorHandler(routeContext, copy, prepared);
// invoke on prepare on the exchange if specified
if (onPrepare != null) {
try {
onPrepare.process(copy);
} catch (Exception e) {
copy.setException(e);
}
}
// and create the pair
return new RecipientProcessorExchangePair(index, producerCache, endpoint, producer, prepared, copy, pattern);
}
示例5: aggregate
import org.apache.camel.util.ExchangeHelper; //导入方法依赖的package包/类
@Override
public Exchange aggregate(Exchange oldExchange, Exchange newExchange) {
Exchange exchange = oldExchange;
if (exchange == null) {
exchange = ExchangeHelper.createCorrelatedCopy(newExchange, true);
injector.prepareAggregationExchange(exchange);
}
// 1. Apply the condition and reject the aggregation if unmatched
if (conditionPredicate != null && !conditionPredicate.matches(newExchange)) {
LOG.trace("Dropped exchange {} from aggregation as predicate {} was not matched", newExchange, conditionPredicate);
return exchange;
}
// 2. Pick the appropriate element of the incoming message, casting it to the specified class
// If null, act accordingly based on storeNulls
E picked = null;
try {
picked = pickExpression.evaluate(newExchange, castAs);
} catch (TypeConversionException exception) {
if (!ignoreInvalidCasts) {
throw exception;
}
}
if (picked == null && !storeNulls) {
LOG.trace("Dropped exchange {} from aggregation as pick expression returned null and storing nulls is not enabled", newExchange);
return exchange;
}
if (collectionType == null) {
injectAsRawValue(exchange, picked);
} else {
injectAsCollection(exchange, picked);
}
return exchange;
}
示例6: prepareCopy
import org.apache.camel.util.ExchangeHelper; //导入方法依赖的package包/类
protected Exchange prepareCopy(Exchange exchange, boolean handover) {
// use a new copy of the exchange to route async (and use same message id)
Exchange copy = ExchangeHelper.createCorrelatedCopy(exchange, handover, true);
// set a new from endpoint to be the seda queue
copy.setFromEndpoint(endpoint);
return copy;
}
示例7: processDataSet
import org.apache.camel.util.ExchangeHelper; //导入方法依赖的package包/类
public void processDataSet(Exchange originalExchange, DataSet dataSet, int counter) throws Exception {
Exchange exchange = ExchangeHelper.createCorrelatedCopy(originalExchange, false);
Message in = exchange.getIn();
in.setBody(dataSet);
in.setHeader("CamelFlatpackCounter", counter);
loadBalancer.process(exchange);
}
示例8: prepareCopy
import org.apache.camel.util.ExchangeHelper; //导入方法依赖的package包/类
private Exchange prepareCopy(final Exchange exchange, final boolean handover) {
// use a new copy of the exchange to route async
final Exchange copy = ExchangeHelper.createCorrelatedCopy(exchange, handover);
// set a new from endpoint to be the disruptor
copy.setFromEndpoint(endpoint);
return copy;
}
示例9: iterator
import org.apache.camel.util.ExchangeHelper; //导入方法依赖的package包/类
@Override
public Iterator<ProcessorExchangePair> iterator() {
return new Iterator<ProcessorExchangePair>() {
private int index;
private boolean closed;
public boolean hasNext() {
if (closed) {
return false;
}
boolean answer = iterator.hasNext();
if (!answer) {
// we are now closed
closed = true;
// nothing more so we need to close the expression value in case it needs to be
try {
close();
} catch (IOException e) {
throw new RuntimeCamelException("Scanner aborted because of an IOException!", e);
}
}
return answer;
}
public ProcessorExchangePair next() {
Object part = iterator.next();
if (part != null) {
// create a correlated copy as the new exchange to be routed in the splitter from the copy
// and do not share the unit of work
Exchange newExchange = ExchangeHelper.createCorrelatedCopy(copy, false);
// If the splitter has an aggregation strategy
// then the StreamCache created by the child routes must not be
// closed by the unit of work of the child route, but by the unit of
// work of the parent route or grand parent route or grand grand parent route... (in case of nesting).
// Therefore, set the unit of work of the parent route as stream cache unit of work, if not already set.
if (newExchange.getProperty(Exchange.STREAM_CACHE_UNIT_OF_WORK) == null) {
newExchange.setProperty(Exchange.STREAM_CACHE_UNIT_OF_WORK, original.getUnitOfWork());
}
// if we share unit of work, we need to prepare the child exchange
if (isShareUnitOfWork()) {
prepareSharedUnitOfWork(newExchange, copy);
}
if (part instanceof Message) {
newExchange.setIn((Message) part);
} else {
Message in = newExchange.getIn();
in.setBody(part);
}
return createProcessorExchangePair(index++, getProcessors().iterator().next(), newExchange, routeContext);
} else {
return null;
}
}
public void remove() {
throw new UnsupportedOperationException("Remove is not supported by this iterator");
}
};
}
示例10: createProcessorExchangePairs
import org.apache.camel.util.ExchangeHelper; //导入方法依赖的package包/类
protected Iterable<ProcessorExchangePair> createProcessorExchangePairs(Exchange exchange) throws Exception {
List<ProcessorExchangePair> result = new ArrayList<ProcessorExchangePair>(processors.size());
StreamCache streamCache = null;
if (isParallelProcessing() && exchange.getIn().getBody() instanceof StreamCache) {
// in parallel processing case, the stream must be copied, therefore get the stream
streamCache = (StreamCache) exchange.getIn().getBody();
}
int index = 0;
for (Processor processor : processors) {
// copy exchange, and do not share the unit of work
Exchange copy = ExchangeHelper.createCorrelatedCopy(exchange, false);
if (streamCache != null) {
if (index > 0) {
// copy it otherwise parallel processing is not possible,
// because streams can only be read once
StreamCache copiedStreamCache = streamCache.copy(copy);
if (copiedStreamCache != null) {
copy.getIn().setBody(copiedStreamCache);
}
}
}
// If the multi-cast processor has an aggregation strategy
// then the StreamCache created by the child routes must not be
// closed by the unit of work of the child route, but by the unit of
// work of the parent route or grand parent route or grand grand parent route ...(in case of nesting).
// Set therefore the unit of work of the parent route as stream cache unit of work,
// if it is not already set.
if (copy.getProperty(Exchange.STREAM_CACHE_UNIT_OF_WORK) == null) {
copy.setProperty(Exchange.STREAM_CACHE_UNIT_OF_WORK, exchange.getUnitOfWork());
}
// if we share unit of work, we need to prepare the child exchange
if (isShareUnitOfWork()) {
prepareSharedUnitOfWork(copy, exchange);
}
// and add the pair
RouteContext routeContext = exchange.getUnitOfWork() != null ? exchange.getUnitOfWork().getRouteContext() : null;
result.add(createProcessorExchangePair(index++, processor, copy, routeContext));
}
if (exchange.getException() != null) {
// force any exceptions occurred during creation of exchange paris to be thrown
// before returning the answer;
throw exchange.getException();
}
return result;
}