You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by or...@apache.org on 2023/08/22 17:54:56 UTC

[camel] branch camel-4.0.x updated: CAMEL-19775: add missing check for ExchangeCompleted event (#11175)

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

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


The following commit(s) were added to refs/heads/camel-4.0.x by this push:
     new 1b2a31df792 CAMEL-19775: add missing check for ExchangeCompleted event (#11175)
1b2a31df792 is described below

commit 1b2a31df7923d10714ec7de8b06001f86c22ac4b
Author: Otavio Rodolfo Piske <or...@users.noreply.github.com>
AuthorDate: Tue Aug 22 19:54:50 2023 +0200

    CAMEL-19775: add missing check for ExchangeCompleted event (#11175)
---
 .../camel/main/MainDurationEventNotifier.java      | 36 ++++++++++++----------
 1 file changed, 19 insertions(+), 17 deletions(-)

diff --git a/core/camel-main/src/main/java/org/apache/camel/main/MainDurationEventNotifier.java b/core/camel-main/src/main/java/org/apache/camel/main/MainDurationEventNotifier.java
index 020cea8a283..daecdbffeea 100644
--- a/core/camel-main/src/main/java/org/apache/camel/main/MainDurationEventNotifier.java
+++ b/core/camel-main/src/main/java/org/apache/camel/main/MainDurationEventNotifier.java
@@ -96,24 +96,26 @@ public class MainDurationEventNotifier extends EventNotifierSupport {
 
         boolean complete = false;
         if (maxMessages > 0) {
-            complete = event.getType() == CamelEvent.Type.ExchangeCompleted
-                    || event.getType() == CamelEvent.Type.ExchangeFailed;
+             complete = event.getType() == CamelEvent.Type.ExchangeCompleted || event.getType() == CamelEvent.Type.ExchangeFailed;
 
-            boolean result = doneMessages.incrementAndGet() >= maxMessages;
-            if (LOG.isTraceEnabled()) {
-                LOG.trace("Duration max messages check {} >= {} -> {}", doneMessages.get(), maxMessages, result);
-            }
+            if (complete) {
+                boolean result = doneMessages.incrementAndGet() >= maxMessages;
+                if (LOG.isTraceEnabled()) {
+                    LOG.trace("Duration max messages check {} >= {} -> {}", doneMessages.get(), maxMessages, result);
+                }
 
-            if (result && shutdownStrategy.isRunAllowed()) {
-                if ("shutdown".equalsIgnoreCase(action)) {
-                    LOG.info("Duration max messages triggering shutdown of the JVM");
-                    // use thread to shut down Camel as otherwise we would block current thread
-                    camelContext.getExecutorServiceManager().newThread("CamelMainShutdownCamelContext", this::shutdownTask)
-                            .start();
-                } else if ("stop".equalsIgnoreCase(action)) {
-                    LOG.info("Duration max messages triggering stopping all routes");
-                    // use thread to stop routes as otherwise we would block current thread
-                    camelContext.getExecutorServiceManager().newThread("CamelMainShutdownCamelContext", this::stopTask).start();
+                if (result && shutdownStrategy.isRunAllowed()) {
+                    if ("shutdown".equalsIgnoreCase(action)) {
+                        LOG.info("Duration max messages triggering shutdown of the JVM");
+                        // use thread to shut down Camel as otherwise we would block current thread
+                        camelContext.getExecutorServiceManager().newThread("CamelMainShutdownCamelContext", this::shutdownTask)
+                                .start();
+                    } else if ("stop".equalsIgnoreCase(action)) {
+                        LOG.info("Duration max messages triggering stopping all routes");
+                        // use thread to stop routes as otherwise we would block current thread
+                        camelContext.getExecutorServiceManager().newThread("CamelMainShutdownCamelContext", this::stopTask)
+                                .start();
+                    }
                 }
             }
         }
@@ -133,7 +135,7 @@ public class MainDurationEventNotifier extends EventNotifierSupport {
 
     @Override
     public boolean isEnabled(CamelEvent event) {
-        return event.getType() == CamelEvent.Type.ExchangeCreated || event.getType() == CamelEvent.Type.ExchangeCreated
+        return event.getType() == CamelEvent.Type.ExchangeCreated || event.getType() == CamelEvent.Type.ExchangeCompleted
                 || event.getType() == CamelEvent.Type.ExchangeFailed || event.getType() == CamelEvent.Type.RouteReloaded;
     }