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
commit 9bb2d25defe5c5541f73eb700430cd7b2f0dd90e Author: Otavio Rodolfo Piske <[email protected]> AuthorDate: Thu Apr 11 13:35:12 2024 +0200 (chores) camel-core-processor: extract independent code snippets from large code blocks --- .../org/apache/camel/processor/PollEnricher.java | 31 +++++++++++++--------- .../org/apache/camel/processor/RoutingSlip.java | 21 +++++++++------ .../errorhandler/RedeliveryErrorHandler.java | 27 +++++++++---------- 3 files changed, 44 insertions(+), 35 deletions(-) diff --git a/core/camel-core-processor/src/main/java/org/apache/camel/processor/PollEnricher.java b/core/camel-core-processor/src/main/java/org/apache/camel/processor/PollEnricher.java index e13ec57ed88..4b7dd9af37c 100644 --- a/core/camel-core-processor/src/main/java/org/apache/camel/processor/PollEnricher.java +++ b/core/camel-core-processor/src/main/java/org/apache/camel/processor/PollEnricher.java @@ -263,19 +263,7 @@ public class PollEnricher extends AsyncProcessorSupport implements IdAware, Rout } // grab the real delegate consumer that performs the actual polling - Consumer delegate = consumer; - if (consumer instanceof EventDrivenPollingConsumer) { - delegate = ((EventDrivenPollingConsumer) consumer).getDelegateConsumer(); - } - - // is the consumer bridging the error handler? - boolean bridgeErrorHandler = false; - if (delegate instanceof DefaultConsumer) { - ExceptionHandler handler = ((DefaultConsumer) delegate).getExceptionHandler(); - if (handler instanceof BridgeExceptionHandlerToErrorHandler) { - bridgeErrorHandler = true; - } - } + final boolean bridgeErrorHandler = isBridgeErrorHandler(consumer); Exchange resourceExchange; try { @@ -398,6 +386,23 @@ public class PollEnricher extends AsyncProcessorSupport implements IdAware, Rout return true; } + private static boolean isBridgeErrorHandler(PollingConsumer consumer) { + Consumer delegate = consumer; + if (consumer instanceof EventDrivenPollingConsumer) { + delegate = ((EventDrivenPollingConsumer) consumer).getDelegateConsumer(); + } + + // is the consumer bridging the error handler? + boolean bridgeErrorHandler = false; + if (delegate instanceof DefaultConsumer) { + ExceptionHandler handler = ((DefaultConsumer) delegate).getExceptionHandler(); + if (handler instanceof BridgeExceptionHandlerToErrorHandler) { + bridgeErrorHandler = true; + } + } + return bridgeErrorHandler; + } + protected static Object prepareRecipient(Exchange exchange, Object recipient) throws NoTypeConversionAvailableException { if (recipient instanceof Endpoint || recipient instanceof NormalizedEndpointUri) { return recipient; diff --git a/core/camel-core-processor/src/main/java/org/apache/camel/processor/RoutingSlip.java b/core/camel-core-processor/src/main/java/org/apache/camel/processor/RoutingSlip.java index aa43fa974cf..b9544f5a462 100644 --- a/core/camel-core-processor/src/main/java/org/apache/camel/processor/RoutingSlip.java +++ b/core/camel-core-processor/src/main/java/org/apache/camel/processor/RoutingSlip.java @@ -498,14 +498,7 @@ public class RoutingSlip extends AsyncProcessorSupport implements Traceable, IdA } // prepare and process the routing slip - final boolean prototypeEndpoint = prototype; - AsyncCallback cbNext = doneNext -> { - // and stop prototype endpoints - if (prototypeEndpoint) { - ServiceHelper.stopAndShutdownService(nextEndpoint); - } - cb.done(doneNext); - }; + final AsyncCallback cbNext = getNextCallback(prototype, nextEndpoint, cb); boolean sync = processExchange(nextEndpoint, current, original, cbNext, iter, prototype); current = prepareExchangeForRoutingSlip(current, nextEndpoint); @@ -539,6 +532,18 @@ public class RoutingSlip extends AsyncProcessorSupport implements Traceable, IdA }); } + private static AsyncCallback getNextCallback(boolean prototype, Endpoint nextEndpoint, AsyncCallback cb) { + final boolean prototypeEndpoint = prototype; + AsyncCallback cbNext = doneNext -> { + // and stop prototype endpoints + if (prototypeEndpoint) { + ServiceHelper.stopAndShutdownService(nextEndpoint); + } + cb.done(doneNext); + }; + return cbNext; + } + @Override protected void doStart() throws Exception { if (producerCache == null) { diff --git a/core/camel-core-processor/src/main/java/org/apache/camel/processor/errorhandler/RedeliveryErrorHandler.java b/core/camel-core-processor/src/main/java/org/apache/camel/processor/errorhandler/RedeliveryErrorHandler.java index 21c66770330..9c4d2b57870 100644 --- a/core/camel-core-processor/src/main/java/org/apache/camel/processor/errorhandler/RedeliveryErrorHandler.java +++ b/core/camel-core-processor/src/main/java/org/apache/camel/processor/errorhandler/RedeliveryErrorHandler.java @@ -515,13 +515,7 @@ public abstract class RedeliveryErrorHandler extends ErrorHandlerSupport if (!found) { // okay before adding suppression then we must be sure its not referring to same method // which otherwise can lead to add the same exception over and over again - StackTraceElement[] ste1 = e.getStackTrace(); - StackTraceElement[] ste2 = previous.getStackTrace(); - boolean same = false; - if (ste1 != null && ste2 != null && ste1.length > 0 && ste2.length > 0) { - same = ste1[0].getClassName().equals(ste2[0].getClassName()) - && ste1[0].getLineNumber() == ste2[0].getLineNumber(); - } + final boolean same = isSame(e, previous); if (!same) { e.addSuppressed(previous); } @@ -1018,13 +1012,7 @@ public abstract class RedeliveryErrorHandler extends ErrorHandlerSupport if (!found) { // okay before adding suppression then we must be sure its not referring to same method // which otherwise can lead to add the same exception over and over again - StackTraceElement[] ste1 = e.getStackTrace(); - StackTraceElement[] ste2 = previous.getStackTrace(); - boolean same = false; - if (ste1 != null && ste2 != null && ste1.length > 0 && ste2.length > 0) { - same = ste1[0].getClassName().equals(ste2[0].getClassName()) - && ste1[0].getLineNumber() == ste2[0].getLineNumber(); - } + final boolean same = isSame(e, previous); if (!same) { e.addSuppressed(previous); } @@ -1605,6 +1593,17 @@ public abstract class RedeliveryErrorHandler extends ErrorHandlerSupport } } + private static boolean isSame(Exception e, Throwable previous) { + StackTraceElement[] ste1 = e.getStackTrace(); + StackTraceElement[] ste2 = previous.getStackTrace(); + boolean same = false; + if (ste1 != null && ste2 != null && ste1.length > 0 && ste2.length > 0) { + same = ste1[0].getClassName().equals(ste2[0].getClassName()) + && ste1[0].getLineNumber() == ste2[0].getLineNumber(); + } + return same; + } + /** * Prepares the redelivery counter and boolean flag for the failure handle processor */
