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
The following commit(s) were added to refs/heads/main by this push:
new 9dd9535 camel-jbang: made the stop options more flexible (#5854)
9dd9535 is described below
commit 9dd9535198578bdb892a4f4a5c1a7ec5c1e582a7
Author: Otavio Rodolfo Piske <[email protected]>
AuthorDate: Wed Jul 21 14:55:35 2021 +0200
camel-jbang: made the stop options more flexible (#5854)
- implemented support for --stop for stopping on demand
- added support for maxMessages for stopping after a certain number of
messages have been processed
---
.../camel-jbang-main/dist/CamelJBang.java | 44 ++++++++++++++++++++--
.../examples/jms-amqp-10-sink-binding.yaml | 2 +-
.../src/main/jbang/main/CamelJBang.java | 44 ++++++++++++++++++++--
3 files changed, 81 insertions(+), 9 deletions(-)
diff --git a/dsl/camel-jbang/camel-jbang-main/dist/CamelJBang.java
b/dsl/camel-jbang/camel-jbang-main/dist/CamelJBang.java
index 6fb1d5a..0b67afb 100755
--- a/dsl/camel-jbang/camel-jbang-main/dist/CamelJBang.java
+++ b/dsl/camel-jbang/camel-jbang-main/dist/CamelJBang.java
@@ -72,7 +72,7 @@ import picocli.CommandLine.Parameters;
class Run implements Callable<Integer> {
private CamelContext context;
- @Parameters(description = "The path to the kamelet binding", arity = "1")
+ @Parameters(description = "The path to the kamelet binding", arity =
"0..1")
private String binding;
@Option(names = { "-h", "--help" }, usageHelp = true, description =
"Display the help and sub-commands")
@@ -81,6 +81,12 @@ class Run implements Callable<Integer> {
@Option(names = { "--debug-level" }, defaultValue = "info", description =
"Default debug level")
private String debugLevel;
+ @Option(names = { "--stop" }, description = "Stop all running instances of
Camel JBang")
+ private boolean stopRequested;
+
+ @Option(names = { "--max-messages" }, defaultValue = "0", description =
"Max number of messages to process before stopping")
+ private int maxMessages;
+
class ShutdownRoute extends RouteBuilder {
private File lockFile;
@@ -96,6 +102,39 @@ class Run implements Callable<Integer> {
@Override
public Integer call() throws Exception {
+ System.setProperty("camel.main.name", "CamelJBang");
+
+ if (stopRequested) {
+ stop();
+ } else {
+ run();
+ }
+
+ return 0;
+ }
+
+ private int stop() {
+ File currentDir = new File(".");
+
+ File[] lockFiles = currentDir.listFiles(f ->
f.getName().endsWith(".camel.lock"));
+
+ for (File lockFile : lockFiles) {
+ System.out.println("Removing file " + lockFile);
+ if (!lockFile.delete()) {
+ System.out.println("Failed to remove lock file " + lockFile);
+ }
+ }
+
+ return 0;
+ }
+
+ private int run() throws Exception {
+ if (maxMessages > 0) {
+ System.setProperty("camel.main.durationMaxMessages",
String.valueOf(maxMessages));
+ }
+
+ System.setProperty("camel.main.routes-include-pattern", "file:" +
binding);
+
switch (debugLevel) {
case "trace":
Configurator.setRootLevel(Level.TRACE);
@@ -125,9 +164,6 @@ class Run implements Callable<Integer> {
return 1;
}
- System.setProperty("camel.main.routes-include-pattern", "file:" +
binding);
- System.setProperty("camel.main.name", "CamelJBang");
-
System.out.println("Starting Camel JBang!");
KameletMain main = new KameletMain();
diff --git
a/dsl/camel-jbang/camel-jbang-main/examples/jms-amqp-10-sink-binding.yaml
b/dsl/camel-jbang/camel-jbang-main/examples/jms-amqp-10-sink-binding.yaml
index f4608a8..1501851 100644
--- a/dsl/camel-jbang/camel-jbang-main/examples/jms-amqp-10-sink-binding.yaml
+++ b/dsl/camel-jbang/camel-jbang-main/examples/jms-amqp-10-sink-binding.yaml
@@ -18,7 +18,7 @@
from:
uri: "kamelet:timer-source"
parameters:
- period: 12399
+ period: 1000
# You can override it using jbang run -D=message="new message"
CamelJbang.java opts...
message: "Hello Camel JBang"
steps:
diff --git
a/dsl/camel-jbang/camel-jbang-main/src/main/jbang/main/CamelJBang.java
b/dsl/camel-jbang/camel-jbang-main/src/main/jbang/main/CamelJBang.java
index a39eb09..743c8e2 100755
--- a/dsl/camel-jbang/camel-jbang-main/src/main/jbang/main/CamelJBang.java
+++ b/dsl/camel-jbang/camel-jbang-main/src/main/jbang/main/CamelJBang.java
@@ -72,7 +72,7 @@ import picocli.CommandLine.Parameters;
class Run implements Callable<Integer> {
private CamelContext context;
- @Parameters(description = "The path to the kamelet binding", arity = "1")
+ @Parameters(description = "The path to the kamelet binding", arity =
"0..1")
private String binding;
@Option(names = { "-h", "--help" }, usageHelp = true, description =
"Display the help and sub-commands")
@@ -81,6 +81,12 @@ class Run implements Callable<Integer> {
@Option(names = { "--debug-level" }, defaultValue = "info", description =
"Default debug level")
private String debugLevel;
+ @Option(names = { "--stop" }, description = "Stop all running instances of
Camel JBang")
+ private boolean stopRequested;
+
+ @Option(names = { "--max-messages" }, defaultValue = "0", description =
"Max number of messages to process before stopping")
+ private int maxMessages;
+
class ShutdownRoute extends RouteBuilder {
private File lockFile;
@@ -96,6 +102,39 @@ class Run implements Callable<Integer> {
@Override
public Integer call() throws Exception {
+ System.setProperty("camel.main.name", "CamelJBang");
+
+ if (stopRequested) {
+ stop();
+ } else {
+ run();
+ }
+
+ return 0;
+ }
+
+ private int stop() {
+ File currentDir = new File(".");
+
+ File[] lockFiles = currentDir.listFiles(f ->
f.getName().endsWith(".camel.lock"));
+
+ for (File lockFile : lockFiles) {
+ System.out.println("Removing file " + lockFile);
+ if (!lockFile.delete()) {
+ System.out.println("Failed to remove lock file " + lockFile);
+ }
+ }
+
+ return 0;
+ }
+
+ private int run() throws Exception {
+ if (maxMessages > 0) {
+ System.setProperty("camel.main.durationMaxMessages",
String.valueOf(maxMessages));
+ }
+
+ System.setProperty("camel.main.routes-include-pattern", "file:" +
binding);
+
switch (debugLevel) {
case "trace":
Configurator.setRootLevel(Level.TRACE);
@@ -125,9 +164,6 @@ class Run implements Callable<Integer> {
return 1;
}
- System.setProperty("camel.main.routes-include-pattern", "file:" +
binding);
- System.setProperty("camel.main.name", "CamelJBang");
-
System.out.println("Starting Camel JBang!");
KameletMain main = new KameletMain();