This is an automated email from the ASF dual-hosted git repository. davsclaus pushed a commit to branch uc in repository https://gitbox.apache.org/repos/asf/camel.git
commit c65abb257852a1109e759490398c1286451ead20 Author: Claus Ibsen <claus.ib...@gmail.com> AuthorDate: Sat Jun 22 15:16:40 2024 +0200 CAMEL-20879: camel-core: remote vs local endpoints counters --- .../java/org/apache/camel/spi/InflightRepository.java | 5 +++++ .../camel/impl/engine/DefaultInflightRepository.java | 8 ++++++++ .../org/apache/camel/impl/console/InflightConsole.java | 5 +++-- .../dsl/jbang/core/commands/process/CamelRouteStatus.java | 6 ++++-- .../dsl/jbang/core/commands/process/ListInflight.java | 15 +++++++++++++++ 5 files changed, 35 insertions(+), 4 deletions(-) diff --git a/core/camel-api/src/main/java/org/apache/camel/spi/InflightRepository.java b/core/camel-api/src/main/java/org/apache/camel/spi/InflightRepository.java index 9c837ad8a92..a4704984055 100644 --- a/core/camel-api/src/main/java/org/apache/camel/spi/InflightRepository.java +++ b/core/camel-api/src/main/java/org/apache/camel/spi/InflightRepository.java @@ -58,6 +58,11 @@ public interface InflightRepository extends StaticService { */ String getFromRouteId(); + /** + * Whether the endpoint is remote where the exchange originates (started) + */ + boolean isFromRemoteEndpoint(); + /** * The id of the route where the exchange currently is being processed * <p/> diff --git a/core/camel-base-engine/src/main/java/org/apache/camel/impl/engine/DefaultInflightRepository.java b/core/camel-base-engine/src/main/java/org/apache/camel/impl/engine/DefaultInflightRepository.java index 53cd68e0187..c606fb47730 100644 --- a/core/camel-base-engine/src/main/java/org/apache/camel/impl/engine/DefaultInflightRepository.java +++ b/core/camel-base-engine/src/main/java/org/apache/camel/impl/engine/DefaultInflightRepository.java @@ -261,6 +261,14 @@ public class DefaultInflightRepository extends ServiceSupport implements Infligh return exchange.getFromRouteId(); } + @Override + public boolean isFromRemoteEndpoint() { + if (exchange.getFromEndpoint() != null) { + return exchange.getFromEndpoint().isRemote(); + } + return false; + } + @Override public String getAtRouteId() { return ExchangeHelper.getAtRouteId(exchange); diff --git a/core/camel-console/src/main/java/org/apache/camel/impl/console/InflightConsole.java b/core/camel-console/src/main/java/org/apache/camel/impl/console/InflightConsole.java index 3ad4d5f2583..ca46de51dc7 100644 --- a/core/camel-console/src/main/java/org/apache/camel/impl/console/InflightConsole.java +++ b/core/camel-console/src/main/java/org/apache/camel/impl/console/InflightConsole.java @@ -57,8 +57,8 @@ public class InflightConsole extends AbstractDevConsole { if (repo.isInflightBrowseEnabled()) { for (InflightRepository.InflightExchange ie : repo.browse(filter, max, false)) { String age = TimeUtils.printDuration(ie.getDuration(), true); - sb.append(String.format("\n %s (from: %s at: %s/%s age: %s)", - ie.getExchange().getExchangeId(), ie.getFromRouteId(), ie.getAtRouteId(), ie.getNodeId(), age)); + sb.append(String.format("\n %s (from: %s at: %s/%s remote: %b age: %s)", + ie.getExchange().getExchangeId(), ie.getFromRouteId(), ie.getAtRouteId(), ie.getNodeId(), ie.isFromRemoteEndpoint(), age)); } } @@ -82,6 +82,7 @@ public class InflightConsole extends AbstractDevConsole { JsonObject props = new JsonObject(); props.put("exchangeId", ie.getExchange().getExchangeId()); props.put("fromRouteId", ie.getFromRouteId()); + props.put("fromRemoteEndpoint", ie.isFromRemoteEndpoint()); props.put("atRouteId", ie.getAtRouteId()); props.put("nodeId", ie.getNodeId()); props.put("elapsed", ie.getElapsed()); diff --git a/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/process/CamelRouteStatus.java b/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/process/CamelRouteStatus.java index 186411cce04..ac3eb7464f4 100644 --- a/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/process/CamelRouteStatus.java +++ b/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/process/CamelRouteStatus.java @@ -96,9 +96,11 @@ public class CamelRouteStatus extends ProcessWatchCommand { row.pid = Long.toString(ph.pid()); row.routeId = o.getString("routeId"); row.from = o.getString("from"); - row.remote = o.getBooleanOrDefault("remote", false); - if (row.remote) { + Boolean bool = o.getBoolean("remote"); + if (bool != null) { + // older camel versions does not include this information remoteVisible.set(true); + row.remote = bool; } row.source = o.getString("source"); row.state = o.getString("state"); diff --git a/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/process/ListInflight.java b/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/process/ListInflight.java index b65dd342f48..e0c39a4ccfb 100644 --- a/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/process/ListInflight.java +++ b/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/process/ListInflight.java @@ -19,6 +19,7 @@ package org.apache.camel.dsl.jbang.core.commands.process; import java.util.ArrayList; import java.util.Arrays; import java.util.List; +import java.util.concurrent.atomic.AtomicBoolean; import com.github.freva.asciitable.AsciiTable; import com.github.freva.asciitable.Column; @@ -52,6 +53,7 @@ public class ListInflight extends ProcessWatchCommand { public Integer doProcessWatchCall() throws Exception { List<Row> rows = new ArrayList<>(); + AtomicBoolean remoteVisible = new AtomicBoolean(); List<Long> pids = findPids(name); ProcessHandle.allProcesses() .filter(ph -> pids.contains(ph.pid())) @@ -81,6 +83,12 @@ public class ListInflight extends ProcessWatchCommand { jo = (JsonObject) arr.get(i); row.exchangeId = jo.getString("exchangeId"); row.fromRouteId = jo.getString("fromRouteId"); + Boolean bool = jo.getBoolean("fromRemoteEndpoint"); + if (bool != null) { + // older camel versions does not include this information + remoteVisible.set(true); + row.fromRemoteEndpoint = bool; + } row.atRouteId = jo.getString("atRouteId"); row.nodeId = jo.getString("nodeId"); row.elapsed = jo.getLong("elapsed"); @@ -101,6 +109,8 @@ public class ListInflight extends ProcessWatchCommand { new Column().header("NAME").dataAlign(HorizontalAlign.LEFT).maxWidth(30, OverflowBehaviour.ELLIPSIS_RIGHT) .with(r -> r.name), new Column().header("EXCHANGE-ID").dataAlign(HorizontalAlign.LEFT).with(r -> r.exchangeId), + new Column().header("REMOTE").visible(remoteVisible.get()).dataAlign(HorizontalAlign.CENTER) + .with(this::getRemote), new Column().header("ROUTE").dataAlign(HorizontalAlign.LEFT).maxWidth(25, OverflowBehaviour.ELLIPSIS_RIGHT) .with(r -> r.atRouteId), new Column().header("ID").dataAlign(HorizontalAlign.LEFT).maxWidth(25, OverflowBehaviour.ELLIPSIS_RIGHT) @@ -139,6 +149,10 @@ public class ListInflight extends ProcessWatchCommand { return TimeUtils.printDuration(r.elapsed); } + private String getRemote(Row r) { + return r.fromRemoteEndpoint ? "x" : ""; + } + private static class Row implements Cloneable { String pid; String name; @@ -146,6 +160,7 @@ public class ListInflight extends ProcessWatchCommand { long uptime; String exchangeId; String fromRouteId; + boolean fromRemoteEndpoint; String atRouteId; String nodeId; long elapsed;