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

davsclaus 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 7da8929b60fc CAMEL-26474: camel-management - StatisticCounter: do not 
update the counter with 0 (#28818)
7da8929b60fc is described below

commit 7da8929b60fc1e3100d8089804238c3fa19b9b87
Author: Adriano Machado <[email protected]>
AuthorDate: Mon Nov 2 01:30:17 2026 -0500

    CAMEL-26474: camel-management - StatisticCounter: do not update the counter 
with 0 (#28818)
    
    …ounter with 0
    
    LongAdder.add(0) still does a compare and set on a shared cell, and most
    nodes of a fast route complete within a millisecond, so the total processing
    time was updated with 0 for the processor, route and context counters on
    almost every node.
    
    _Claude Code on behalf of Adriano Machado (@ammachado)_
    
    _This was generated by an AI agent and may contain inaccuracies.
    Please verify before relying on it._
    
    Co-authored-by: Claude Opus 5.5 <[email protected]>
---
 .../camel/management/mbean/StatisticCounter.java   |  5 ++++-
 .../mbean/ManagedPerformanceCounterTest.java       | 25 ++++++++++++++++++++++
 2 files changed, 29 insertions(+), 1 deletion(-)

diff --git 
a/core/camel-management/src/main/java/org/apache/camel/management/mbean/StatisticCounter.java
 
b/core/camel-management/src/main/java/org/apache/camel/management/mbean/StatisticCounter.java
index c96ed77fd542..b2ffed7eeb87 100644
--- 
a/core/camel-management/src/main/java/org/apache/camel/management/mbean/StatisticCounter.java
+++ 
b/core/camel-management/src/main/java/org/apache/camel/management/mbean/StatisticCounter.java
@@ -28,7 +28,10 @@ public class StatisticCounter extends Statistic {
 
     @Override
     public void updateValue(long newValue) {
-        value.add(newValue);
+        // most routes complete within a millisecond, so the total time is 
usually updated with 0
+        if (newValue != 0) {
+            value.add(newValue);
+        }
     }
 
     @Override
diff --git 
a/core/camel-management/src/test/java/org/apache/camel/management/mbean/ManagedPerformanceCounterTest.java
 
b/core/camel-management/src/test/java/org/apache/camel/management/mbean/ManagedPerformanceCounterTest.java
index 956fca9195f2..cb56c36ef800 100644
--- 
a/core/camel-management/src/test/java/org/apache/camel/management/mbean/ManagedPerformanceCounterTest.java
+++ 
b/core/camel-management/src/test/java/org/apache/camel/management/mbean/ManagedPerformanceCounterTest.java
@@ -58,6 +58,31 @@ public class ManagedPerformanceCounterTest {
         context.close();
     }
 
+    @Test
+    public void testExchangeWithinAMillisecondCountsButAddsNoTime() {
+        // the counter skips updates of 0 as most nodes take no measurable 
time, but the exchange must still count
+        Exchange exchange = new DefaultExchange(context);
+        counter.completedExchange(exchange, 5);
+        counter.completedExchange(exchange, 0);
+        counter.completedExchange(exchange, 7);
+
+        assertEquals(3, counter.getExchangesCompleted());
+        assertEquals(12, counter.getTotalProcessingTime());
+        assertEquals(4, counter.getMeanProcessingTime());
+        assertEquals(0, counter.getMinProcessingTime());
+    }
+
+    @Test
+    public void testInflightGoesDownWhenAnExchangeCompletes() {
+        // decrementing is a negative update of the same counter
+        Exchange exchange = new DefaultExchange(context);
+        counter.processExchange(exchange, "processor");
+        counter.processExchange(exchange, "processor");
+        counter.completedExchange(exchange, 0);
+
+        assertEquals(1, counter.getExchangesInflight());
+    }
+
     @Test
     public void testMeanIsUnsetUntilAnExchangeCompletes() {
         // monitoring tools rely on -1 meaning no data, which is not the same 
as a mean of 0 ms

Reply via email to