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/02/28 07:58:45 UTC

[camel] branch main updated (82bae503a78 -> cb14edd0e4f)

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

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


    from 82bae503a78 (chores) camel-base-engine: fix misplaced comment
     new 94322d2c2b9 CAMEL-19060: avoid a potentially costly call to AtomicInteger.get() when notifying that the exchange had been created
     new cb14edd0e4f CAMEL-19058: use type checks instead of instance checks for handling event notifications

The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 .../camel/main/MainDurationEventNotifier.java      | 36 ++++++++++++----------
 1 file changed, 20 insertions(+), 16 deletions(-)


[camel] 02/02: CAMEL-19058: use type checks instead of instance checks for handling event notifications

Posted by or...@apache.org.
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 cb14edd0e4f4746333e3aed780d0f44dbb6696ca
Author: Otavio Rodolfo Piske <an...@gmail.com>
AuthorDate: Mon Feb 13 20:22:20 2023 +0100

    CAMEL-19058: use type checks instead of instance checks for handling event notifications
---
 .../camel/main/MainDurationEventNotifier.java      | 32 ++++++++++++----------
 1 file changed, 17 insertions(+), 15 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 2e6ae1df989..f87a8f5c76d 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
@@ -23,10 +23,6 @@ import java.util.concurrent.atomic.AtomicInteger;
 
 import org.apache.camel.CamelContext;
 import org.apache.camel.spi.CamelEvent;
-import org.apache.camel.spi.CamelEvent.ExchangeCompletedEvent;
-import org.apache.camel.spi.CamelEvent.ExchangeCreatedEvent;
-import org.apache.camel.spi.CamelEvent.ExchangeFailedEvent;
-import org.apache.camel.spi.CamelEvent.RouteReloadedEvent;
 import org.apache.camel.support.EventNotifierSupport;
 import org.apache.camel.util.StopWatch;
 import org.slf4j.Logger;
@@ -78,15 +74,13 @@ public class MainDurationEventNotifier extends EventNotifierSupport {
         }
     }
 
-    protected void doNotify(CamelEvent event) throws Exception {
+    protected void doNotify(CamelEvent event) {
         // ignore any event that is received if shutdown is in process
         if (!shutdownStrategy.isRunAllowed()) {
             return;
         }
 
-        boolean begin = event instanceof ExchangeCreatedEvent;
-        boolean complete = event instanceof ExchangeCompletedEvent || event instanceof ExchangeFailedEvent;
-        boolean reloaded = event instanceof RouteReloadedEvent;
+        final boolean reloaded = event.getType() == CamelEvent.Type.RouteReloaded;
 
         if (reloaded) {
             if (restartDuration) {
@@ -100,7 +94,10 @@ public class MainDurationEventNotifier extends EventNotifierSupport {
             return;
         }
 
-        if (maxMessages > 0 && complete) {
+        boolean complete = false;
+        if (maxMessages > 0) {
+            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);
@@ -120,19 +117,24 @@ public class MainDurationEventNotifier extends EventNotifierSupport {
             }
         }
 
+
         // idle reacts on both incoming and complete messages
-        if (maxIdleSeconds > 0 && (begin || complete)) {
-            if (watch != null) {
-                LOG.trace("Message activity so restarting stop watch");
-                watch.restart();
+        if (maxIdleSeconds > 0) {
+            final boolean begin = event.getType() == CamelEvent.Type.ExchangeCreated;
+
+            if (begin || complete) {
+                if (watch != null) {
+                    LOG.trace("Message activity so restarting stop watch");
+                    watch.restart();
+                }
             }
         }
     }
 
     @Override
     public boolean isEnabled(CamelEvent event) {
-        return event instanceof ExchangeCreatedEvent || event instanceof ExchangeCompletedEvent
-                || event instanceof ExchangeFailedEvent || event instanceof RouteReloadedEvent;
+        return event.getType() == CamelEvent.Type.ExchangeCreated || event.getType() == CamelEvent.Type.ExchangeCreated
+                || event.getType() == CamelEvent.Type.ExchangeFailed || event.getType() == CamelEvent.Type.RouteReloaded;
     }
 
     @Override


[camel] 01/02: CAMEL-19060: avoid a potentially costly call to AtomicInteger.get() when notifying that the exchange had been created

Posted by or...@apache.org.
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 94322d2c2b99ab2b98d1fc9474bdb0c31eace1e7
Author: Otavio Rodolfo Piske <an...@gmail.com>
AuthorDate: Wed Feb 22 15:57:09 2023 +0100

    CAMEL-19060: avoid a potentially costly call to AtomicInteger.get() when notifying that the exchange had been created
---
 .../main/java/org/apache/camel/main/MainDurationEventNotifier.java    | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

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 9dd78738ad0..2e6ae1df989 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
@@ -102,7 +102,9 @@ public class MainDurationEventNotifier extends EventNotifierSupport {
 
         if (maxMessages > 0 && complete) {
             boolean result = doneMessages.incrementAndGet() >= maxMessages;
-            LOG.trace("Duration max messages check {} >= {} -> {}", doneMessages.get(), maxMessages, result);
+            if (LOG.isTraceEnabled()) {
+                LOG.trace("Duration max messages check {} >= {} -> {}", doneMessages.get(), maxMessages, result);
+            }
 
             if (result && shutdownStrategy.isRunAllowed()) {
                 if ("shutdown".equalsIgnoreCase(action)) {