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 aab002283f4f CAMEL-24706: camel-main - camel.main.duration accepts a
value with a unit (15s, 2m) as an alias of durationMaxSeconds (#26364)
aab002283f4f is described below
commit aab002283f4fbb14731dba32f6fa66d314ba6799
Author: Claus Ibsen <[email protected]>
AuthorDate: Sun Sep 13 16:48:38 2026 +0200
CAMEL-24706: camel-main - camel.main.duration accepts a value with a unit
(15s, 2m) as an alias of durationMaxSeconds (#26364)
* CAMEL-24706: camel-main - camel.main.duration accepts a value with a unit
(15s, 2m) as an alias of durationMaxSeconds
Squash of the 1 commits on fix/CAMEL-24706 (the run-by-run history is on
bench/after-run).
camel-main - camel.main.duration as an alias of durationMaxSeconds that
accepts a time unit (15s, 2m, 1h)
Co-Authored-By: Claude Fable 5.1 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Bp3538HRBPMQkb5ta9xRaj
* Regen
* CAMEL-24706: camel-main - withDurationMaxSeconds keeps its javadoc
Review note on PR 26364: withDuration had been inserted between the javadoc
and the method it belongs to.
Co-authored-by: Claude Fable 5.1 <[email protected]>
---
.../org/apache/camel/catalog/docs/main.adoc | 3 +-
.../main/camel-main-configuration-metadata.json | 1 +
.../MainConfigurationPropertiesConfigurer.java | 4 ++
.../camel-main-configuration-metadata.json | 1 +
core/camel-main/src/main/docs/main.adoc | 3 +-
.../camel/main/DefaultConfigurationProperties.java | 32 ++++++++++++
.../apache/camel/main/MainDurationAliasTest.java | 60 ++++++++++++++++++++++
7 files changed, 102 insertions(+), 2 deletions(-)
diff --git
a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/docs/main.adoc
b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/docs/main.adoc
index 6d76d8603150..04b5439aa5f8 100644
---
a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/docs/main.adoc
+++
b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/docs/main.adoc
@@ -19,7 +19,7 @@ The following tables lists all the options:
// main options: START
=== Camel Main configurations
-The camel.main supports 130 options, which are listed below.
+The camel.main supports 131 options, which are listed below.
[width="100%",cols="2,5,^1,2",options="header"]
|===
@@ -56,6 +56,7 @@ The camel.main supports 130 options, which are listed below.
| `camel.main.dumpRoutesOutput` | Whether to save route dumps to an output
file. If the output is a filename, then all content is saved to this file. If
the output is a directory name, then one or more files are saved to the
directory, where the names are based on the original source file names, or auto
generated names. | | String
| `camel.main.dumpRoutesResolvePlaceholders` | Whether to resolve property
placeholders in the dumped output. Default is true. | true | boolean
| `camel.main.dumpRoutesUriAsParameters` | When dumping routes to YAML format,
then this option controls whether endpoint URIs should be expanded into a
key/value parameters. | false | boolean
+| `camel.main.duration` | For how long to keep running before automatic
terminating the JVM, as a duration with a time unit such as 15s, 2m or 1h (a
plain number is seconds). An alias of durationMaxSeconds that accepts a unit. |
| String
| `camel.main.durationHitExitCode` | Sets the exit code for the application if
duration was hit | | int
| `camel.main.durationMaxAction` | Controls whether the Camel application
should shutdown the JVM, or stop all routes, when duration max is triggered. |
shutdown | String
| `camel.main.durationMaxIdleSeconds` | To specify for how long time in
seconds Camel can be idle before automatic terminating the JVM. You can use
this to run Camel for a short while. | | int
diff --git
a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/main/camel-main-configuration-metadata.json
b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/main/camel-main-configuration-metadata.json
index b2548a1b6a2e..63884fca7e36 100644
---
a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/main/camel-main-configuration-metadata.json
+++
b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/main/camel-main-configuration-metadata.json
@@ -70,6 +70,7 @@
{ "name": "camel.main.dumpRoutesOutput", "required": false, "description":
"Whether to save route dumps to an output file. If the output is a filename,
then all content is saved to this file. If the output is a directory name, then
one or more files are saved to the directory, where the names are based on the
original source file names, or auto generated names.", "sourceType":
"org.apache.camel.main.DefaultConfigurationProperties", "type": "string",
"javaType": "java.lang.String", "s [...]
{ "name": "camel.main.dumpRoutesResolvePlaceholders", "required": false,
"description": "Whether to resolve property placeholders in the dumped output.
Default is true.", "sourceType":
"org.apache.camel.main.DefaultConfigurationProperties", "type": "boolean",
"javaType": "boolean", "defaultValue": true, "secret": false },
{ "name": "camel.main.dumpRoutesUriAsParameters", "required": false,
"description": "When dumping routes to YAML format, then this option controls
whether endpoint URIs should be expanded into a key\/value parameters.",
"sourceType": "org.apache.camel.main.DefaultConfigurationProperties", "type":
"boolean", "javaType": "boolean", "defaultValue": false, "secret": false },
+ { "name": "camel.main.duration", "required": false, "description": "For
how long to keep running before automatic terminating the JVM, as a duration
with a time unit such as 15s, 2m or 1h (a plain number is seconds). An alias of
durationMaxSeconds that accepts a unit.", "sourceType":
"org.apache.camel.main.DefaultConfigurationProperties", "type": "string",
"javaType": "java.lang.String", "secret": false },
{ "name": "camel.main.durationHitExitCode", "required": false,
"description": "Sets the exit code for the application if duration was hit",
"sourceType": "org.apache.camel.main.MainConfigurationProperties", "type":
"integer", "javaType": "int", "secret": false },
{ "name": "camel.main.durationMaxAction", "required": false,
"description": "Controls whether the Camel application should shutdown the JVM,
or stop all routes, when duration max is triggered.", "sourceType":
"org.apache.camel.main.DefaultConfigurationProperties", "type": "enum",
"javaType": "java.lang.String", "defaultValue": "shutdown", "secret": false,
"enum": [ "shutdown", "stop" ] },
{ "name": "camel.main.durationMaxIdleSeconds", "required": false,
"description": "To specify for how long time in seconds Camel can be idle
before automatic terminating the JVM. You can use this to run Camel for a short
while.", "sourceType": "org.apache.camel.main.DefaultConfigurationProperties",
"type": "integer", "javaType": "int", "secret": false },
diff --git
a/core/camel-main/src/generated/java/org/apache/camel/main/MainConfigurationPropertiesConfigurer.java
b/core/camel-main/src/generated/java/org/apache/camel/main/MainConfigurationPropertiesConfigurer.java
index ef8872d49c93..c4757a38ff27 100644
---
a/core/camel-main/src/generated/java/org/apache/camel/main/MainConfigurationPropertiesConfigurer.java
+++
b/core/camel-main/src/generated/java/org/apache/camel/main/MainConfigurationPropertiesConfigurer.java
@@ -54,6 +54,7 @@ public class MainConfigurationPropertiesConfigurer extends
org.apache.camel.supp
map.put("DumpRoutesOutput", java.lang.String.class);
map.put("DumpRoutesResolvePlaceholders", boolean.class);
map.put("DumpRoutesUriAsParameters", boolean.class);
+ map.put("Duration", java.lang.String.class);
map.put("DurationHitExitCode", int.class);
map.put("DurationMaxAction", java.lang.String.class);
map.put("DurationMaxIdleSeconds", int.class);
@@ -221,6 +222,7 @@ public class MainConfigurationPropertiesConfigurer extends
org.apache.camel.supp
case "dumpRoutesResolvePlaceholders":
target.setDumpRoutesResolvePlaceholders(property(camelContext, boolean.class,
value)); return true;
case "dumproutesuriasparameters":
case "dumpRoutesUriAsParameters":
target.setDumpRoutesUriAsParameters(property(camelContext, boolean.class,
value)); return true;
+ case "duration": target.setDuration(property(camelContext,
java.lang.String.class, value)); return true;
case "durationhitexitcode":
case "durationHitExitCode":
target.setDurationHitExitCode(property(camelContext, int.class, value)); return
true;
case "durationmaxaction":
@@ -487,6 +489,7 @@ public class MainConfigurationPropertiesConfigurer extends
org.apache.camel.supp
case "dumpRoutesResolvePlaceholders": return boolean.class;
case "dumproutesuriasparameters":
case "dumpRoutesUriAsParameters": return boolean.class;
+ case "duration": return java.lang.String.class;
case "durationhitexitcode":
case "durationHitExitCode": return int.class;
case "durationmaxaction":
@@ -749,6 +752,7 @@ public class MainConfigurationPropertiesConfigurer extends
org.apache.camel.supp
case "dumpRoutesResolvePlaceholders": return
target.isDumpRoutesResolvePlaceholders();
case "dumproutesuriasparameters":
case "dumpRoutesUriAsParameters": return
target.isDumpRoutesUriAsParameters();
+ case "duration": return target.getDuration();
case "durationhitexitcode":
case "durationHitExitCode": return target.getDurationHitExitCode();
case "durationmaxaction":
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 b2548a1b6a2e..63884fca7e36 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
@@ -70,6 +70,7 @@
{ "name": "camel.main.dumpRoutesOutput", "required": false, "description":
"Whether to save route dumps to an output file. If the output is a filename,
then all content is saved to this file. If the output is a directory name, then
one or more files are saved to the directory, where the names are based on the
original source file names, or auto generated names.", "sourceType":
"org.apache.camel.main.DefaultConfigurationProperties", "type": "string",
"javaType": "java.lang.String", "s [...]
{ "name": "camel.main.dumpRoutesResolvePlaceholders", "required": false,
"description": "Whether to resolve property placeholders in the dumped output.
Default is true.", "sourceType":
"org.apache.camel.main.DefaultConfigurationProperties", "type": "boolean",
"javaType": "boolean", "defaultValue": true, "secret": false },
{ "name": "camel.main.dumpRoutesUriAsParameters", "required": false,
"description": "When dumping routes to YAML format, then this option controls
whether endpoint URIs should be expanded into a key\/value parameters.",
"sourceType": "org.apache.camel.main.DefaultConfigurationProperties", "type":
"boolean", "javaType": "boolean", "defaultValue": false, "secret": false },
+ { "name": "camel.main.duration", "required": false, "description": "For
how long to keep running before automatic terminating the JVM, as a duration
with a time unit such as 15s, 2m or 1h (a plain number is seconds). An alias of
durationMaxSeconds that accepts a unit.", "sourceType":
"org.apache.camel.main.DefaultConfigurationProperties", "type": "string",
"javaType": "java.lang.String", "secret": false },
{ "name": "camel.main.durationHitExitCode", "required": false,
"description": "Sets the exit code for the application if duration was hit",
"sourceType": "org.apache.camel.main.MainConfigurationProperties", "type":
"integer", "javaType": "int", "secret": false },
{ "name": "camel.main.durationMaxAction", "required": false,
"description": "Controls whether the Camel application should shutdown the JVM,
or stop all routes, when duration max is triggered.", "sourceType":
"org.apache.camel.main.DefaultConfigurationProperties", "type": "enum",
"javaType": "java.lang.String", "defaultValue": "shutdown", "secret": false,
"enum": [ "shutdown", "stop" ] },
{ "name": "camel.main.durationMaxIdleSeconds", "required": false,
"description": "To specify for how long time in seconds Camel can be idle
before automatic terminating the JVM. You can use this to run Camel for a short
while.", "sourceType": "org.apache.camel.main.DefaultConfigurationProperties",
"type": "integer", "javaType": "int", "secret": false },
diff --git a/core/camel-main/src/main/docs/main.adoc
b/core/camel-main/src/main/docs/main.adoc
index 6d76d8603150..04b5439aa5f8 100644
--- a/core/camel-main/src/main/docs/main.adoc
+++ b/core/camel-main/src/main/docs/main.adoc
@@ -19,7 +19,7 @@ The following tables lists all the options:
// main options: START
=== Camel Main configurations
-The camel.main supports 130 options, which are listed below.
+The camel.main supports 131 options, which are listed below.
[width="100%",cols="2,5,^1,2",options="header"]
|===
@@ -56,6 +56,7 @@ The camel.main supports 130 options, which are listed below.
| `camel.main.dumpRoutesOutput` | Whether to save route dumps to an output
file. If the output is a filename, then all content is saved to this file. If
the output is a directory name, then one or more files are saved to the
directory, where the names are based on the original source file names, or auto
generated names. | | String
| `camel.main.dumpRoutesResolvePlaceholders` | Whether to resolve property
placeholders in the dumped output. Default is true. | true | boolean
| `camel.main.dumpRoutesUriAsParameters` | When dumping routes to YAML format,
then this option controls whether endpoint URIs should be expanded into a
key/value parameters. | false | boolean
+| `camel.main.duration` | For how long to keep running before automatic
terminating the JVM, as a duration with a time unit such as 15s, 2m or 1h (a
plain number is seconds). An alias of durationMaxSeconds that accepts a unit. |
| String
| `camel.main.durationHitExitCode` | Sets the exit code for the application if
duration was hit | | int
| `camel.main.durationMaxAction` | Controls whether the Camel application
should shutdown the JVM, or stop all routes, when duration max is triggered. |
shutdown | String
| `camel.main.durationMaxIdleSeconds` | To specify for how long time in
seconds Camel can be idle before automatic terminating the JVM. You can use
this to run Camel for a short while. | | int
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 494afca5058c..1cd03a600c5b 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
@@ -39,6 +39,7 @@ public abstract class DefaultConfigurationProperties<T> {
@Metadata(defaultValue = "Default", enums =
"Verbose,Default,Brief,Oneline,Off")
private StartupSummaryLevel startupSummaryLevel;
private int durationMaxSeconds;
+ private String duration;
private int durationMaxIdleSeconds;
private int durationMaxMessages;
@Metadata(defaultValue = "shutdown", enums = "shutdown,stop")
@@ -233,6 +234,28 @@ public abstract class DefaultConfigurationProperties<T> {
this.durationMaxSeconds = durationMaxSeconds;
}
+ public String getDuration() {
+ return duration;
+ }
+
+ /**
+ * For how long to keep running before automatic terminating the JVM, as a
duration with a time unit such as 15s, 2m
+ * or 1h (a plain number is seconds). An alias of durationMaxSeconds that
accepts a unit.
+ */
+ public void setDuration(String duration) {
+ this.duration = duration;
+ if (duration != null && !duration.isBlank()) {
+ String text = duration.trim();
+ if (text.matches("\\d+")) {
+ // a plain number is seconds, as durationMaxSeconds
+ this.durationMaxSeconds = Integer.parseInt(text);
+ } else {
+ long millis =
org.apache.camel.util.TimeUtils.toMilliSeconds(text);
+ this.durationMaxSeconds = (int) Math.max(1, (millis + 999) /
1000);
+ }
+ }
+ }
+
public int getDurationMaxIdleSeconds() {
return durationMaxIdleSeconds;
}
@@ -1825,6 +1848,15 @@ public abstract class DefaultConfigurationProperties<T> {
return (T) this;
}
+ /**
+ * For how long to keep running before automatic terminating the JVM, as a
duration with a time unit such as 15s, 2m
+ * or 1h (a plain number is seconds). An alias of durationMaxSeconds that
accepts a unit.
+ */
+ public T withDuration(String duration) {
+ setDuration(duration);
+ return (T) this;
+ }
+
/**
* To specify for how long time in seconds to keep running the JVM before
automatic terminating the JVM. You can use
* this to run Camel for a short while.
diff --git
a/core/camel-main/src/test/java/org/apache/camel/main/MainDurationAliasTest.java
b/core/camel-main/src/test/java/org/apache/camel/main/MainDurationAliasTest.java
new file mode 100644
index 000000000000..7f06cea4a25e
--- /dev/null
+++
b/core/camel-main/src/test/java/org/apache/camel/main/MainDurationAliasTest.java
@@ -0,0 +1,60 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.main;
+
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
+/**
+ * CAMEL-24706: camel.main.duration is an alias of durationMaxSeconds that
accepts a time unit.
+ */
+public class MainDurationAliasTest {
+
+ @Test
+ public void testDurationWithUnit() {
+ MainConfigurationProperties config = new MainConfigurationProperties();
+ config.setDuration("15s");
+ assertEquals(15, config.getDurationMaxSeconds());
+ config.setDuration("2m");
+ assertEquals(120, config.getDurationMaxSeconds());
+ config.setDuration("1h");
+ assertEquals(3600, config.getDurationMaxSeconds());
+ config.setDuration("500ms");
+ assertEquals(1, config.getDurationMaxSeconds());
+ }
+
+ @Test
+ public void testPlainNumberIsSeconds() {
+ MainConfigurationProperties config = new MainConfigurationProperties();
+ config.setDuration("30");
+ assertEquals(30, config.getDurationMaxSeconds());
+ }
+
+ @Test
+ public void testDurationAsProperty() throws Exception {
+ Main main = new Main();
+ main.addInitialProperty("camel.main.duration", "45s");
+ main.configure().withDurationMaxMessages(0);
+ try {
+ main.start();
+ assertEquals(45, main.configure().getDurationMaxSeconds());
+ } finally {
+ main.stop();
+ }
+ }
+}