This is an automated email from the ASF dual-hosted git repository.

orpiske pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel.git


The following commit(s) were added to refs/heads/main by this push:
     new b86569124f6 (chores) camel-base-engine: cleanup duplicated code
b86569124f6 is described below

commit b86569124f69b42a4b2e9041fda6df16e76c327c
Author: Otavio Rodolfo Piske <angusyo...@gmail.com>
AuthorDate: Tue Feb 14 17:21:27 2023 +0100

    (chores) camel-base-engine: cleanup duplicated code
---
 .../apache/camel/impl/engine/AdviceIterator.java   | 45 ++++++++++++++++++++++
 .../camel/impl/engine/CamelInternalProcessor.java  | 16 +-------
 .../impl/engine/SharedCamelInternalProcessor.java  | 14 +------
 3 files changed, 48 insertions(+), 27 deletions(-)

diff --git 
a/core/camel-base-engine/src/main/java/org/apache/camel/impl/engine/AdviceIterator.java
 
b/core/camel-base-engine/src/main/java/org/apache/camel/impl/engine/AdviceIterator.java
new file mode 100644
index 00000000000..4ec157d9af4
--- /dev/null
+++ 
b/core/camel-base-engine/src/main/java/org/apache/camel/impl/engine/AdviceIterator.java
@@ -0,0 +1,45 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.camel.impl.engine;
+
+import java.util.List;
+
+import org.apache.camel.Exchange;
+import org.apache.camel.spi.CamelInternalProcessorAdvice;
+
+final class AdviceIterator {
+    private AdviceIterator() {
+
+    }
+
+    static void runAfterTasks(List<? extends CamelInternalProcessorAdvice> 
advices, Object[] states, Exchange exchange) {
+        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
+            }
+        }
+    }
+}
diff --git 
a/core/camel-base-engine/src/main/java/org/apache/camel/impl/engine/CamelInternalProcessor.java
 
b/core/camel-base-engine/src/main/java/org/apache/camel/impl/engine/CamelInternalProcessor.java
index 096585d5ff8..14022ccf156 100644
--- 
a/core/camel-base-engine/src/main/java/org/apache/camel/impl/engine/CamelInternalProcessor.java
+++ 
b/core/camel-base-engine/src/main/java/org/apache/camel/impl/engine/CamelInternalProcessor.java
@@ -245,19 +245,7 @@ public class CamelInternalProcessor extends 
DelegateAsyncProcessor implements In
         @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
-                    }
-                }
+                AdviceIterator.runAfterTasks(advices, states, exchange);
             } finally {
                 // ----------------------------------------------------------
                 // CAMEL END USER - DEBUG ME HERE +++ START +++
@@ -813,10 +801,10 @@ public class CamelInternalProcessor extends 
DelegateAsyncProcessor implements In
                 UnitOfWorkHelper.doneUow(uow, exchange);
             }
 
-            // after UoW is done lets pop the route context which must be done 
on every existing UoW
             if (route != null && existing != null) {
                 existing.popRoute();
             }
+            // after UoW is done lets pop the route context which must be done 
on every existing UoW
         }
 
         protected UnitOfWork createUnitOfWork(Exchange exchange) {
diff --git 
a/core/camel-base-engine/src/main/java/org/apache/camel/impl/engine/SharedCamelInternalProcessor.java
 
b/core/camel-base-engine/src/main/java/org/apache/camel/impl/engine/SharedCamelInternalProcessor.java
index 2d9dfc68fdb..6ae6ed90103 100644
--- 
a/core/camel-base-engine/src/main/java/org/apache/camel/impl/engine/SharedCamelInternalProcessor.java
+++ 
b/core/camel-base-engine/src/main/java/org/apache/camel/impl/engine/SharedCamelInternalProcessor.java
@@ -263,19 +263,7 @@ public class SharedCamelInternalProcessor implements 
SharedInternalProcessor {
 
             // we should call after in reverse order
             try {
-                for (int i = advices != null ? advices.size() - 1 : -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
-                    }
-                }
+                AdviceIterator.runAfterTasks(advices, states, exchange);
             } finally {
                 // ----------------------------------------------------------
                 // CAMEL END USER - DEBUG ME HERE +++ START +++

Reply via email to