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 <[email protected]>
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;
     }
 

Reply via email to