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 11d4eab0f695d4011cda56503f6feea5290bb443 Author: Claus Ibsen <claus.ib...@gmail.com> AuthorDate: Sun Feb 2 14:02:59 2020 +0100 CAMEL-14354: camel-core optimize. Lets use a inner class for the after task instead of lambda so we have nicer strackrrace and can better understand them. --- .../camel/processor/CamelInternalProcessor.java | 76 ++++++++++++++-------- 1 file changed, 48 insertions(+), 28 deletions(-) diff --git a/core/camel-base/src/main/java/org/apache/camel/processor/CamelInternalProcessor.java b/core/camel-base/src/main/java/org/apache/camel/processor/CamelInternalProcessor.java index f2a7c7e..6b8265e 100644 --- a/core/camel-base/src/main/java/org/apache/camel/processor/CamelInternalProcessor.java +++ b/core/camel-base/src/main/java/org/apache/camel/processor/CamelInternalProcessor.java @@ -146,6 +146,53 @@ public class CamelInternalProcessor extends DelegateAsyncProcessor { return null; } + /** + * Callback task to process the advices after processing. + */ + private class AsyncAfterTask implements AsyncCallback { + + private final Object[] states; + private final Exchange exchange; + private final AsyncCallback originalCallback; + + private AsyncAfterTask(Object[] states, Exchange exchange, AsyncCallback originalCallback) { + this.states = states; + this.exchange = exchange; + this.originalCallback = originalCallback; + } + + @Override + @SuppressWarnings("unchecked") + public void done(boolean doneSync) { + try { + for (int i = advices.size() - 1, j = states.length - 1; i >= 0; i--) { + CamelInternalProcessorAdvice task = advices.get(i); + Object state = null; + if (task.hasState()) { + state = states[j--]; + } + try { + task.after(exchange, state); + } catch (Throwable e) { + exchange.setException(e); + // allow all advices to complete even if there was an exception + } + } + } finally { + // ---------------------------------------------------------- + // CAMEL END USER - DEBUG ME HERE +++ START +++ + // ---------------------------------------------------------- + // callback must be called + if (originalCallback != null) { + reactiveExecutor.schedule(originalCallback); + } + // ---------------------------------------------------------- + // CAMEL END USER - DEBUG ME HERE +++ END +++ + // ---------------------------------------------------------- + } + } + } + @Override @SuppressWarnings("unchecked") public boolean process(Exchange exchange, AsyncCallback originalCallback) { @@ -187,34 +234,7 @@ public class CamelInternalProcessor extends DelegateAsyncProcessor { } // create internal callback which will execute the advices in reverse order when done - AsyncCallback callback = doneSync -> { - try { - for (int i = advices.size() - 1, j = states.length - 1; i >= 0; i--) { - CamelInternalProcessorAdvice task = advices.get(i); - Object state = null; - if (task.hasState()) { - state = states[j--]; - } - try { - task.after(exchange, state); - } catch (Throwable e) { - exchange.setException(e); - // allow all advices to complete even if there was an exception - } - } - } finally { - // ---------------------------------------------------------- - // CAMEL END USER - DEBUG ME HERE +++ START +++ - // ---------------------------------------------------------- - // callback must be called - if (originalCallback != null) { - reactiveExecutor.schedule(originalCallback); - } - // ---------------------------------------------------------- - // CAMEL END USER - DEBUG ME HERE +++ END +++ - // ---------------------------------------------------------- - } - }; + AsyncCallback callback = new AsyncAfterTask(states, exchange, originalCallback); if (exchange.isTransacted()) { // must be synchronized for transacted exchanges