This is an automated email from the ASF dual-hosted git repository. davsclaus pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/camel.git
commit 3fbd153c41c88ad496232c5471511b2f8948400c Author: Claus Ibsen <claus.ib...@gmail.com> AuthorDate: Sun Jan 19 10:32:42 2020 +0100 CAMEL-14354: Optimize core --- .../org/apache/camel/processor/SendProcessor.java | 35 ++++++++++++---------- 1 file changed, 19 insertions(+), 16 deletions(-) diff --git a/core/camel-base/src/main/java/org/apache/camel/processor/SendProcessor.java b/core/camel-base/src/main/java/org/apache/camel/processor/SendProcessor.java index 1aaa98f..6c20e6c 100644 --- a/core/camel-base/src/main/java/org/apache/camel/processor/SendProcessor.java +++ b/core/camel-base/src/main/java/org/apache/camel/processor/SendProcessor.java @@ -140,24 +140,27 @@ public class SendProcessor extends AsyncProcessorSupport implements Traceable, E watch = null; } - try { - log.debug(">>>> {} {}", destination, exchange); - return producer.process(exchange, new AsyncCallback() { - @Override - public void done(boolean doneSync) { - try { - // restore previous MEP - target.setPattern(existingPattern); - // emit event that the exchange was sent to the endpoint - if (watch != null) { - long timeTaken = watch.taken(); - EventHelper.notifyExchangeSent(target.getContext(), target, destination, timeTaken); - } - } finally { - callback.done(doneSync); + // optimize to only create a new callback if really needed, otherwise we can use the provided callback as-is + AsyncCallback ac = callback; + boolean newCallback = watch != null || existingPattern != target.getPattern(); + if (newCallback) { + ac = doneSync -> { + try { + // restore previous MEP + target.setPattern(existingPattern); + // emit event that the exchange was sent to the endpoint + if (watch != null) { + long timeTaken = watch.taken(); + EventHelper.notifyExchangeSent(target.getContext(), target, destination, timeTaken); } + } finally { + callback.done(doneSync); } - }); + }; + } + try { + log.debug(">>>> {} {}", destination, exchange); + return producer.process(exchange, ac); } catch (Throwable throwable) { exchange.setException(throwable); callback.done(true);