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

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


The following commit(s) were added to refs/heads/camel-3.20.x by this push:
     new fadcf664b9b CAMEL-18846: camel-main - Performance overhead due to 
emitting events not needed
fadcf664b9b is described below

commit fadcf664b9bee5f0383b575e25d2069ab4015ad6
Author: Claus Ibsen <claus.ib...@gmail.com>
AuthorDate: Wed Dec 28 12:01:25 2022 +0100

    CAMEL-18846: camel-main - Performance overhead due to emitting events not 
needed
---
 .../resources/META-INF/camel-main-configuration-metadata.json      | 2 +-
 core/camel-main/src/main/docs/main.adoc                            | 2 +-
 .../src/main/java/org/apache/camel/main/BaseMainSupport.java       | 5 ++---
 .../java/org/apache/camel/main/DefaultConfigurationProperties.java | 3 +--
 .../main/java/org/apache/camel/main/MainDurationEventNotifier.java | 7 ++++++-
 .../src/main/java/org/apache/camel/main/MainSupport.java           | 2 +-
 6 files changed, 12 insertions(+), 9 deletions(-)

diff --git 
a/core/camel-main/src/generated/resources/META-INF/camel-main-configuration-metadata.json
 
b/core/camel-main/src/generated/resources/META-INF/camel-main-configuration-metadata.json
index b9836b00584..d2d09c2a980 100644
--- 
a/core/camel-main/src/generated/resources/META-INF/camel-main-configuration-metadata.json
+++ 
b/core/camel-main/src/generated/resources/META-INF/camel-main-configuration-metadata.json
@@ -95,7 +95,7 @@
     { "name": "camel.main.routesReloadEnabled", "description": "Used for 
enabling automatic routes reloading. If enabled then Camel will watch for file 
changes in the given reload directory, and trigger reloading routes if files 
are changed.", "sourceType": 
"org.apache.camel.main.DefaultConfigurationProperties", "type": "boolean", 
"javaType": "boolean", "defaultValue": "false" },
     { "name": "camel.main.routesReloadPattern", "description": "Used for 
inclusive filtering of routes from directories. Typical used for specifying to 
accept routes in XML or YAML files, such as .yaml,.xml. Multiple patterns can 
be specified separated by comma.", "sourceType": 
"org.apache.camel.main.DefaultConfigurationProperties", "type": "string", 
"javaType": "java.lang.String" },
     { "name": "camel.main.routesReloadRemoveAllRoutes", "description": "When 
reloading routes should all existing routes be stopped and removed. By default, 
Camel will stop and remove all existing routes before reloading routes. This 
ensures that only the reloaded routes will be active. If disabled then only 
routes with the same route id is updated, and any existing routes are continued 
to run.", "sourceType": "org.apache.camel.main.DefaultConfigurationProperties", 
"type": "boolean", "ja [...]
-    { "name": "camel.main.routesReloadRestartDuration", "description": 
"Whether to restart max duration when routes are reloaded. For example if max 
duration is 60 seconds, and a route is reloaded after 25 seconds, then this 
will restart the count and wait 60 seconds again.", "sourceType": 
"org.apache.camel.main.DefaultConfigurationProperties", "type": "boolean", 
"javaType": "boolean", "defaultValue": true },
+    { "name": "camel.main.routesReloadRestartDuration", "description": 
"Whether to restart max duration when routes are reloaded. For example if max 
duration is 60 seconds, and a route is reloaded after 25 seconds, then this 
will restart the count and wait 60 seconds again.", "sourceType": 
"org.apache.camel.main.DefaultConfigurationProperties", "type": "boolean", 
"javaType": "boolean", "defaultValue": "false" },
     { "name": "camel.main.shutdownLogInflightExchangesOnTimeout", 
"description": "Sets whether to log information about the inflight Exchanges 
which are still running during a shutdown which didn't complete without the 
given timeout. This requires to enable the option 
inflightRepositoryBrowseEnabled.", "sourceType": 
"org.apache.camel.main.DefaultConfigurationProperties", "type": "boolean", 
"javaType": "boolean", "defaultValue": true },
     { "name": "camel.main.shutdownNowOnTimeout", "description": "Sets whether 
to force shutdown of all consumers when a timeout occurred and thus not all 
consumers was shutdown within that period. You should have good reasons to set 
this option to false as it means that the routes keep running and is halted 
abruptly when CamelContext has been shutdown.", "sourceType": 
"org.apache.camel.main.DefaultConfigurationProperties", "type": "boolean", 
"javaType": "boolean", "defaultValue": true },
     { "name": "camel.main.shutdownRoutesInReverseOrder", "description": "Sets 
whether routes should be shutdown in reverse or the same order as they were 
started.", "sourceType": 
"org.apache.camel.main.DefaultConfigurationProperties", "type": "boolean", 
"javaType": "boolean", "defaultValue": true },
diff --git a/core/camel-main/src/main/docs/main.adoc 
b/core/camel-main/src/main/docs/main.adoc
index 044462aaf6c..d441f5b8a35 100644
--- a/core/camel-main/src/main/docs/main.adoc
+++ b/core/camel-main/src/main/docs/main.adoc
@@ -106,7 +106,7 @@ The camel.main supports 118 options, which are listed below.
 | *camel.main.routesReloadEnabled* | Used for enabling automatic routes 
reloading. If enabled then Camel will watch for file changes in the given 
reload directory, and trigger reloading routes if files are changed. | false | 
boolean
 | *camel.main.routesReloadPattern* | Used for inclusive filtering of routes 
from directories. Typical used for specifying to accept routes in XML or YAML 
files, such as .yaml,.xml. Multiple patterns can be specified separated by 
comma. |  | String
 | *camel.main.routesReloadRemove{zwsp}AllRoutes* | When reloading routes 
should all existing routes be stopped and removed. By default, Camel will stop 
and remove all existing routes before reloading routes. This ensures that only 
the reloaded routes will be active. If disabled then only routes with the same 
route id is updated, and any existing routes are continued to run. | true | 
boolean
-| *camel.main.routesReloadRestart{zwsp}Duration* | Whether to restart max 
duration when routes are reloaded. For example if max duration is 60 seconds, 
and a route is reloaded after 25 seconds, then this will restart the count and 
wait 60 seconds again. | true | boolean
+| *camel.main.routesReloadRestart{zwsp}Duration* | Whether to restart max 
duration when routes are reloaded. For example if max duration is 60 seconds, 
and a route is reloaded after 25 seconds, then this will restart the count and 
wait 60 seconds again. | false | boolean
 | *camel.main.shutdownLogInflight{zwsp}ExchangesOnTimeout* | Sets whether to 
log information about the inflight Exchanges which are still running during a 
shutdown which didn't complete without the given timeout. This requires to 
enable the option inflightRepositoryBrowseEnabled. | true | boolean
 | *camel.main.shutdownNowOn{zwsp}Timeout* | Sets whether to force shutdown of 
all consumers when a timeout occurred and thus not all consumers was shutdown 
within that period. You should have good reasons to set this option to false as 
it means that the routes keep running and is halted abruptly when CamelContext 
has been shutdown. | true | boolean
 | *camel.main.shutdownRoutesIn{zwsp}ReverseOrder* | Sets whether routes should 
be shutdown in reverse or the same order as they were started. | true | boolean
diff --git 
a/core/camel-main/src/main/java/org/apache/camel/main/BaseMainSupport.java 
b/core/camel-main/src/main/java/org/apache/camel/main/BaseMainSupport.java
index 7a6a99ddf69..552cc495319 100644
--- a/core/camel-main/src/main/java/org/apache/camel/main/BaseMainSupport.java
+++ b/core/camel-main/src/main/java/org/apache/camel/main/BaseMainSupport.java
@@ -62,10 +62,10 @@ import org.apache.camel.spi.RouteTemplateParameterSource;
 import org.apache.camel.spi.StartupStepRecorder;
 import org.apache.camel.support.CamelContextHelper;
 import org.apache.camel.support.DefaultContextReloadStrategy;
-import org.apache.camel.support.EventNotifierSupport;
 import org.apache.camel.support.LifecycleStrategySupport;
 import org.apache.camel.support.PropertyBindingSupport;
 import org.apache.camel.support.ResourceHelper;
+import org.apache.camel.support.SimpleEventNotifierSupport;
 import org.apache.camel.support.service.BaseService;
 import org.apache.camel.support.startup.LoggingStartupStepRecorder;
 import org.apache.camel.util.FileUtil;
@@ -713,8 +713,7 @@ public abstract class BaseMainSupport extends BaseService {
         // we want to log the property placeholder summary after routes has 
been started,
         // but before camel context logs that it has been started, so we need 
to use an event listener
         if (standalone && 
mainConfigurationProperties.isAutoConfigurationLogSummary()) {
-            camelContext.getManagementStrategy().addEventNotifier(new 
EventNotifierSupport() {
-                // TODO: ignore as much as possible
+            camelContext.getManagementStrategy().addEventNotifier(new 
SimpleEventNotifierSupport() {
                 @Override
                 public boolean isEnabled(CamelEvent event) {
                     return event instanceof 
CamelEvent.CamelContextRoutesStartedEvent;
diff --git 
a/core/camel-main/src/main/java/org/apache/camel/main/DefaultConfigurationProperties.java
 
b/core/camel-main/src/main/java/org/apache/camel/main/DefaultConfigurationProperties.java
index 887973c35a2..429a219cbec 100644
--- 
a/core/camel-main/src/main/java/org/apache/camel/main/DefaultConfigurationProperties.java
+++ 
b/core/camel-main/src/main/java/org/apache/camel/main/DefaultConfigurationProperties.java
@@ -118,8 +118,7 @@ public abstract class DefaultConfigurationProperties<T> {
     private String routesReloadPattern;
     @Metadata(defaultValue = "true")
     private boolean routesReloadRemoveAllRoutes = true;
-    @Metadata(defaultValue = "true")
-    private boolean routesReloadRestartDuration = true;
+    private boolean routesReloadRestartDuration;
     private boolean lightweight;
     @Metadata(defaultValue = "default", enums = "default,prototype,pooled")
     private String exchangeFactory = "default";
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 66a7432fb73..5ab8b289292 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
@@ -62,6 +62,11 @@ public class MainDurationEventNotifier extends 
EventNotifierSupport {
         this.restartDuration = restartDuration;
         this.action = action.toLowerCase();
         this.doneMessages = new AtomicInteger();
+
+        if (maxMessages == 0 && maxIdleSeconds == 0) {
+            // we do not need exchange events
+            setIgnoreExchangeEvents(true);
+        }
     }
 
     @Override
@@ -102,7 +107,7 @@ public class MainDurationEventNotifier extends 
EventNotifierSupport {
             if (result && shutdownStrategy.isRunAllowed()) {
                 if ("shutdown".equalsIgnoreCase(action)) {
                     LOG.info("Duration max messages triggering shutdown of the 
JVM");
-                    // use thread to shutdown Camel as otherwise we would 
block current thread
+                    // 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)) {
diff --git 
a/core/camel-main/src/main/java/org/apache/camel/main/MainSupport.java 
b/core/camel-main/src/main/java/org/apache/camel/main/MainSupport.java
index a2f2e4c28f7..cb97aed4570 100644
--- a/core/camel-main/src/main/java/org/apache/camel/main/MainSupport.java
+++ b/core/camel-main/src/main/java/org/apache/camel/main/MainSupport.java
@@ -314,7 +314,7 @@ public abstract class MainSupport extends BaseMainSupport {
 
     @Override
     protected void configureLifecycle(CamelContext camelContext) throws 
Exception {
-        if (mainConfigurationProperties.getDurationMaxSeconds() > 0
+        if ((mainConfigurationProperties.getDurationMaxSeconds() > 0 && 
mainConfigurationProperties.isRoutesReloadRestartDuration())
                 || mainConfigurationProperties.getDurationMaxMessages() > 0
                 || mainConfigurationProperties.getDurationMaxIdleSeconds() > 
0) {
             // register lifecycle, so we can trigger to shutdown the JVM when 
maximum number of messages has been processed

Reply via email to