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 9ce3d99a904f chore: camel-jbang - the route diagram, the topology and
the architecture show the messages moving (#29947)
9ce3d99a904f is described below
commit 9ce3d99a904f3f2a0604444d534d819707e57c5a
Author: Claus Ibsen <[email protected]>
AuthorDate: Sun Nov 15 08:57:47 2026 +0100
chore: camel-jbang - the route diagram, the topology and the architecture
show the messages moving (#29947)
A route diagram, the topology and the architecture now show the messages
moving: dots go along the arrows at the pace of the messages into the step (or
route, or group) below, faster and closer together when busier, and red when
most fail there. Each zoom level has its own form (dots, lit heads, lit lines,
a light over the overview steps). The architecture adds up the counts of the
running routes per group (ArchitectureFlow), with red dots into Error handling
and, with e on, dots to a [...]
The rates come from the counts the diagram already loads, so the
integration does no extra work, and frames are only drawn while something
moves. w turns the flow off and on, kept as camel.tui.diagramFlow. New:
FlowAnimation, FlowDots, FlowFeed, ArchitectureFlow, with tests, and a Live
Flow section with GIFs in camel-jbang-tui-diagram.adoc.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
---
.../jbang/camel-tui-diagram-architecture-flow.gif | Bin 0 -> 201667 bytes
.../images/jbang/camel-tui-diagram-live-flow.gif | Bin 0 -> 174109 bytes
.../jbang/camel-tui-diagram-topology-flow.gif | Bin 0 -> 78798 bytes
.../ROOT/pages/camel-jbang-tui-diagram.adoc | 38 +++
.../core/commands/tui/AbstractDiagramTab.java | 11 +
.../jbang/core/commands/tui/ArchitectureFlow.java | 197 +++++++++++++
.../jbang/core/commands/tui/ArchitectureView.java | 24 ++
.../dsl/jbang/core/commands/tui/CamelMonitor.java | 2 +-
.../jbang/core/commands/tui/DiagramSupport.java | 5 +-
.../dsl/jbang/core/commands/tui/DiagramTab.java | 16 +
.../jbang/core/commands/tui/RouteDiagramZoom.java | 25 ++
.../dsl/jbang/core/commands/tui/RoutesTab.java | 1 +
.../dsl/jbang/core/commands/tui/TabRegistry.java | 5 +
.../core/commands/tui/diagram/FlowAnimation.java | 241 +++++++++++++++
.../jbang/core/commands/tui/diagram/FlowDots.java | 183 ++++++++++++
.../jbang/core/commands/tui/diagram/FlowFeed.java | 41 +++
.../commands/tui/diagram/RouteDiagramWidget.java | 123 +++++++-
.../tui/diagram/TopologyDiagramWidget.java | 98 +++++++
.../src/main/resources/tui/help/diagram.md | 42 ++-
.../src/main/resources/tui/help/routes.md | 2 +
.../core/commands/tui/ArchitectureFlowTest.java | 186 ++++++++++++
.../commands/tui/diagram/FlowAnimationTest.java | 178 ++++++++++++
.../core/commands/tui/diagram/FlowDotsTest.java | 322 +++++++++++++++++++++
.../commands/tui/diagram/TopologyFlowTest.java | 208 +++++++++++++
24 files changed, 1942 insertions(+), 6 deletions(-)
diff --git
a/docs/user-manual/modules/ROOT/images/jbang/camel-tui-diagram-architecture-flow.gif
b/docs/user-manual/modules/ROOT/images/jbang/camel-tui-diagram-architecture-flow.gif
new file mode 100644
index 000000000000..f0157eb7fd70
Binary files /dev/null and
b/docs/user-manual/modules/ROOT/images/jbang/camel-tui-diagram-architecture-flow.gif
differ
diff --git
a/docs/user-manual/modules/ROOT/images/jbang/camel-tui-diagram-live-flow.gif
b/docs/user-manual/modules/ROOT/images/jbang/camel-tui-diagram-live-flow.gif
new file mode 100644
index 000000000000..71ff0e53fdad
Binary files /dev/null and
b/docs/user-manual/modules/ROOT/images/jbang/camel-tui-diagram-live-flow.gif
differ
diff --git
a/docs/user-manual/modules/ROOT/images/jbang/camel-tui-diagram-topology-flow.gif
b/docs/user-manual/modules/ROOT/images/jbang/camel-tui-diagram-topology-flow.gif
new file mode 100644
index 000000000000..0dbe5b4e4132
Binary files /dev/null and
b/docs/user-manual/modules/ROOT/images/jbang/camel-tui-diagram-topology-flow.gif
differ
diff --git a/docs/user-manual/modules/ROOT/pages/camel-jbang-tui-diagram.adoc
b/docs/user-manual/modules/ROOT/pages/camel-jbang-tui-diagram.adoc
index 493061bef0cd..bbf1e35eee0f 100644
--- a/docs/user-manual/modules/ROOT/pages/camel-jbang-tui-diagram.adoc
+++ b/docs/user-manual/modules/ROOT/pages/camel-jbang-tui-diagram.adoc
@@ -16,6 +16,8 @@ See xref:camel-jbang-tui.adoc[Camel TUI] for getting started
and the other pages
topology and in a route, and in a box of its own in the architecture
* <<_external_endpoints,*External endpoints*>> -- what the integration
consumes from and sends to outside
* <<_metrics_and_source_code,*Metrics and source*>> -- throughput and timing
on the boxes, and the source a box comes from
+* <<_live_flow,*Live flow*>> -- dots move along the arrows where the messages
go, in a route, between the routes and
+ between the groups of the architecture, and a stuck step is marked
* <<_body_types,*Body types*>> -- the types of the bodies each step has been
reached with, on the arrows into the steps
== Route Topology Diagram
@@ -241,6 +243,41 @@ Press *e* to cycle through three modes for external
endpoints:
* Press *c* to view the source code of the selected route, with syntax
highlighting
* Press *b* (or *n*) to switch between the business view (labels) and the
technical view (route ids and endpoints)
+=== Live Flow
+
+With the metrics on, a route diagram and the topology show where the messages
go while the integration runs, so the
+busy part stands out at a glance, not only as counts that go up. The
architecture shows it between its groups. Press *w* to turn it off and on; the
choice is kept
+for the next start.
+
+* *Dots on the arrows* move along an arrow while messages reach the step below
it: the more messages a second, the
+ faster and closer together they are. They are red when most of the messages
fail there.
+* At the compact level the head of an arrow lights up as a dot comes in. At
the bare and overview levels the lines light
+ up instead, as a dot would look like the mark of a step there. The overview
has hardly any lines between its steps, so
+ there the light passes over the steps themselves. The steps keep the colours
of their kind at every level.
+* *In the topology* the dots go along the edges into the routes that get
messages, at the pace of the route they go
+ into. An edge from a route that gets no messages has none, even when the
route it goes into gets them from another
+ one.
+* *In the architecture* the dots go along a link between two groups at the
pace of the messages into the routes of the
+ group it goes to, from the routes of the group it comes from. With *x* on,
red dots go into the Error handling box at
+ the pace the routes of a group fail, handled or not, so where the failures
go shows at a glance. With *e* on, the dots
+ come in from an external system at the pace of the route that consumes from
it, and go out to one at the pace of the
+ messages the integration counts for that endpoint (else of the route that
sends to it). The architecture is
+ read from the source files, so this needs the integration running: a source
route counts when it is matched to a
+ running route, by its id or, without one, by the endpoint it consumes from.
+* *A stuck step* of a route diagram, where exchanges wait and none has
finished for a few seconds, has a spinner in its top border, with how
+ many wait and how long ago the step last finished one (`⠹ 3 inflight ·
12s`), or `none done` when it never did, such
+ as a call to a system that does not answer.
+
+The rates come from the counts the diagram loads about once a second, so the
flow costs the integration nothing more.
+The dots move in between, about 12 frames a second, and only while something
moves: an idle integration draws no
+frames.
+
+image::jbang/camel-tui-diagram-live-flow.gif[The orders route with the live
flow: dots go along the arrows and split at the choice, most of them to the
warehouse branch; then the sync route, whose delay step is stuck with 219
exchanges and none done]
+
+image::jbang/camel-tui-diagram-topology-flow.gif[The topology with the live
flow: dots from orders to vip and ship, and on to audit; none from the manual
route, which sends no messages]
+
+image::jbang/camel-tui-diagram-architecture-flow.gif[The architecture with the
live flow and its external systems: dots in from the file inbox through intake
to fulfilment and on to reporting, out to the file archive, and red dots from
fulfilment into the error handling]
+
=== Body Types
When the integration runs with the message history on, such as with `camel run
--dev`, Camel keeps the body types
@@ -305,6 +342,7 @@ camel-xml-io, while a Spring Boot or Quarkus application
may not.
| *Esc* | Go back (previous route or topology)
| *t* | Jump to topology view
| *m* | Toggle metrics overlay
+| *w* | The live flow on or off: dots on the arrows the messages go along, in
a route, the topology and the architecture, and the stuck steps of a route
marked
| *y* | In a route: show the body types each step has been reached with,
beside the arrows into the steps
| *+* / *-* | In a route, the topology and the architecture: zoom in or out
(detailed, compact, bare, and in a route overview)
| *z* | In a route, the topology and the architecture: fit, the most detail in
which it fits the screen
diff --git
a/dsl/camel-jbang/camel-jbang-plugin-tui/src/main/java/org/apache/camel/dsl/jbang/core/commands/tui/AbstractDiagramTab.java
b/dsl/camel-jbang/camel-jbang-plugin-tui/src/main/java/org/apache/camel/dsl/jbang/core/commands/tui/AbstractDiagramTab.java
index ad941094a4b1..ec4b247a472a 100644
---
a/dsl/camel-jbang/camel-jbang-plugin-tui/src/main/java/org/apache/camel/dsl/jbang/core/commands/tui/AbstractDiagramTab.java
+++
b/dsl/camel-jbang/camel-jbang-plugin-tui/src/main/java/org/apache/camel/dsl/jbang/core/commands/tui/AbstractDiagramTab.java
@@ -81,6 +81,11 @@ abstract class AbstractDiagramTab extends AbstractTab {
return diagram.isShowDiagram();
}
+ /** The route diagram on screen shows messages moving, and its next frame
is due. */
+ boolean isFlowFrameDue() {
+ return diagram.isShowDiagram() && diagramMetrics &&
diagram.zoom.flow().frameDue();
+ }
+
/**
* The source shown over the diagram while its search is typed, or the go
to node popup, which filters by typing.
*/
@@ -171,6 +176,12 @@ abstract class AbstractDiagramTab extends AbstractTab {
ctx.backgroundExecutor.execute(diagram.zoom::persist);
return true;
}
+ if (ke.isCharIgnoreCase('w')) {
+ // the messages moving through the route and between the routes:
dots on the arrows
+ diagram.zoom.flow().setEnabled(!diagram.zoom.flow().isEnabled());
+ ctx.backgroundExecutor.execute(diagram.zoom::persist);
+ return true;
+ }
if (!topologyMode && detailMode) {
if (ke.isPageUp() || ke.isKey(KeyCode.PAGE_UP)) {
detail.scrollBy(-10);
diff --git
a/dsl/camel-jbang/camel-jbang-plugin-tui/src/main/java/org/apache/camel/dsl/jbang/core/commands/tui/ArchitectureFlow.java
b/dsl/camel-jbang/camel-jbang-plugin-tui/src/main/java/org/apache/camel/dsl/jbang/core/commands/tui/ArchitectureFlow.java
new file mode 100644
index 000000000000..ad50aeda267e
--- /dev/null
+++
b/dsl/camel-jbang/camel-jbang-plugin-tui/src/main/java/org/apache/camel/dsl/jbang/core/commands/tui/ArchitectureFlow.java
@@ -0,0 +1,197 @@
+/*
+ * 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.dsl.jbang.core.commands.tui;
+
+import java.util.HashMap;
+import java.util.LinkedHashMap;
+import java.util.LinkedHashSet;
+import java.util.List;
+import java.util.Locale;
+import java.util.Map;
+import java.util.Set;
+import java.util.function.UnaryOperator;
+
+import org.apache.camel.dsl.jbang.core.commands.ai.ProjectCapabilities;
+import
org.apache.camel.dsl.jbang.core.commands.ai.ProjectCapabilities.Capabilities;
+import org.apache.camel.dsl.jbang.core.commands.ai.ProjectCapabilities.Group;
+import
org.apache.camel.dsl.jbang.core.commands.ai.ProjectCapabilities.GroupLink;
+import org.apache.camel.dsl.jbang.core.commands.ai.ProjectOverview;
+import
org.apache.camel.dsl.jbang.core.commands.tui.diagram.FlowAnimation.Reading;
+import org.apache.camel.dsl.jbang.core.commands.tui.diagram.FlowFeed;
+
+/**
+ * The messages moving between the groups of the architecture, from the counts
of the running routes: along a link, the
+ * messages into the routes of one group from the routes of the other; into
the error handling, in red, the failures of
+ * the routes of a group; from an external system into a group and out to one,
the messages of the endpoint. The
+ * architecture is read from the source, so a source route counts only when it
is matched to a running route (by its id,
+ * or as {@link RouteKeys} matches a route without one).
+ */
+final class ArchitectureFlow {
+
+ private ArchitectureFlow() {
+ }
+
+ /**
+ * The feed of the dots of the architecture, or null when the integration
does not run the routes of the project.
+ *
+ * @param endpoints the endpoints of the running routes, with their
messages
+ * @param runningId the running id of a source route key
+ */
+ static FlowFeed feed(
+ ProjectOverview.Overview overview, Capabilities caps,
List<RouteInfo> routes, List<EndpointInfo> endpoints,
+ UnaryOperator<String> runningId) {
+ if (overview == null || caps == null || routes == null ||
routes.isEmpty()) {
+ return null;
+ }
+ Map<String, RouteInfo> byId = new HashMap<>();
+ routes.forEach(r -> byId.put(r.routeId, r));
+ // the running route of each source route key
+ Map<String, RouteInfo> running = new HashMap<>();
+ for (String key : caps.groupOf().keySet()) {
+ RouteInfo r = byId.get(runningId.apply(key));
+ if (r != null) {
+ running.put(key, r);
+ }
+ }
+ if (running.isEmpty()) {
+ return null;
+ }
+ Map<String, Reading> readings = new HashMap<>();
+ running.forEach((key, r) -> readings.put("route/" + key, new
Reading(r, r.total, r.failed, 0)));
+ Map<String, FlowFeed.Edge> edges = new HashMap<>();
+ links(overview, caps, running, readings, edges);
+ failures(caps, running, readings, edges);
+ systems(overview, caps, running, endpoints != null ? endpoints :
List.of(), readings, edges);
+ return new FlowFeed(readings, edges);
+ }
+
+ /** Along a link of two groups: the messages into the routes of the one
from the routes of the other. */
+ private static void links(
+ ProjectOverview.Overview overview, Capabilities caps, Map<String,
RouteInfo> running,
+ Map<String, Reading> readings, Map<String, FlowFeed.Edge> edges) {
+ Map<String, Set<String>> targets = new LinkedHashMap<>();
+ Map<String, Set<String>> senders = new LinkedHashMap<>();
+ for (ProjectOverview.Link l : overview.links()) {
+ String from = caps.groupOf().get(l.from());
+ String to = caps.groupOf().get(l.to());
+ if (l.onError() || from == null || to == null || from.equals(to)
+ || ProjectCapabilities.ERRORS.equals(to) ||
!running.containsKey(l.to())) {
+ continue;
+ }
+ String id = FlowFeed.edgeId(from, to);
+ targets.computeIfAbsent(id, k -> new
LinkedHashSet<>()).add(l.to());
+ if (running.containsKey(l.from())) {
+ senders.computeIfAbsent(id, k -> new
LinkedHashSet<>()).add("route/" + l.from());
+ }
+ }
+ targets.forEach((id, keys) -> {
+ long total = 0;
+ long failed = 0;
+ for (String key : keys) {
+ total += running.get(key).total;
+ failed += running.get(key).failed;
+ }
+ // a reload brings new routes: the first of them tells a new
reading from the frames in between
+ readings.put("link/" + id, new
Reading(running.get(keys.iterator().next()), total, failed, 0));
+ edges.put(id, new FlowFeed.Edge("link/" + id,
List.copyOf(senders.getOrDefault(id, Set.of()))));
+ });
+ }
+
+ /**
+ * From an external system into a group, and from a group out to one, as
the boxes of the systems link them. In: the
+ * messages of the route that consumes from it, as a route gets its
messages from its one consumer (a polling
+ * consumer, such as a file one, counts no hits of its endpoint). Out: the
messages sent to the endpoint as the
+ * integration counts them, else of the route that sends to it.
+ */
+ private static void systems(
+ ProjectOverview.Overview overview, Capabilities caps, Map<String,
RouteInfo> running,
+ List<EndpointInfo> endpoints, Map<String, Reading> readings,
Map<String, FlowFeed.Edge> edges) {
+ Map<String, Long> totals = new LinkedHashMap<>();
+ Map<String, Object> sources = new HashMap<>();
+ for (ProjectOverview.SystemUse use : overview.systems()) {
+ String group = caps.groupOf().get(use.route());
+ RouteInfo route = running.get(use.route());
+ if (group == null || route == null) {
+ continue;
+ }
+ boolean in = "in".equals(use.direction());
+ String system = ArchitectureView.systemId(use.name(), in);
+ String id = in ? FlowFeed.edgeId(system, group) :
FlowFeed.edgeId(group, system);
+ EndpointInfo endpoint = in ? null : endpoint(endpoints, use,
route.routeId);
+ totals.merge(id, endpoint != null ? endpoint.hits : route.total,
Long::sum);
+ // a reload brings new endpoints and routes: a new reading
+ sources.putIfAbsent(id, endpoint != null ? endpoint : route);
+ }
+ totals.forEach((id, total) -> {
+ String key = "system/" + id;
+ readings.put(key, new Reading(sources.get(id), total, 0, 0));
+ edges.put(id, new FlowFeed.Edge(key, List.of()));
+ });
+ }
+
+ /** The running endpoint of a use of a system: the same scheme and path,
direction and route. */
+ private static EndpointInfo endpoint(List<EndpointInfo> endpoints,
ProjectOverview.SystemUse use, String routeId) {
+ String key = endpointKey(use.uri());
+ for (EndpointInfo e : endpoints) {
+ if (routeId.equals(e.routeId) &&
use.direction().equals(e.direction) && e.uri != null
+ && key.equals(endpointKey(e.uri))) {
+ return e;
+ }
+ }
+ return null;
+ }
+
+ /** The scheme and path of an endpoint uri, as the source and the running
integration write it alike. */
+ static String endpointKey(String uri) {
+ int q = uri.indexOf('?');
+ String u = q >= 0 ? uri.substring(0, q) : uri;
+ int c = u.indexOf(':');
+ if (c < 0) {
+ return u;
+ }
+ String path = u.substring(c + 1);
+ return u.substring(0, c).toLowerCase(Locale.ROOT) + ":" +
(path.startsWith("//") ? path.substring(2) : path);
+ }
+
+ /** Into the error handling: the failures of the routes of a group,
handled or not, in red. */
+ private static void failures(
+ Capabilities caps, Map<String, RouteInfo> running, Map<String,
Reading> readings,
+ Map<String, FlowFeed.Edge> edges) {
+ Map<String, Group> groups = new HashMap<>();
+ caps.groups().forEach(g -> groups.put(g.id(), g));
+ for (GroupLink link : caps.links()) {
+ Group g = groups.get(link.from());
+ if (!ProjectCapabilities.ERRORS.equals(link.to()) || g == null) {
+ continue;
+ }
+ long failures = 0;
+ RouteInfo first = null;
+ for (String key : g.routes()) {
+ RouteInfo r = running.get(key);
+ if (r != null) {
+ failures += r.failed + r.failuresHandled;
+ first = first == null ? r : first;
+ }
+ }
+ if (first != null) {
+ String key = "errors/" + g.id();
+ readings.put(key, new Reading(first, failures, failures, 0));
+ edges.put(FlowFeed.edgeId(g.id(), ProjectCapabilities.ERRORS),
new FlowFeed.Edge(key, List.of()));
+ }
+ }
+ }
+}
diff --git
a/dsl/camel-jbang/camel-jbang-plugin-tui/src/main/java/org/apache/camel/dsl/jbang/core/commands/tui/ArchitectureView.java
b/dsl/camel-jbang/camel-jbang-plugin-tui/src/main/java/org/apache/camel/dsl/jbang/core/commands/tui/ArchitectureView.java
index d3bc17e738c4..cfa01a546ff9 100644
---
a/dsl/camel-jbang/camel-jbang-plugin-tui/src/main/java/org/apache/camel/dsl/jbang/core/commands/tui/ArchitectureView.java
+++
b/dsl/camel-jbang/camel-jbang-plugin-tui/src/main/java/org/apache/camel/dsl/jbang/core/commands/tui/ArchitectureView.java
@@ -55,6 +55,7 @@ import
org.apache.camel.dsl.jbang.core.commands.ai.ProjectCapabilities.Capabilit
import org.apache.camel.dsl.jbang.core.commands.ai.ProjectCapabilities.Group;
import
org.apache.camel.dsl.jbang.core.commands.ai.ProjectCapabilities.GroupLink;
import org.apache.camel.dsl.jbang.core.commands.ai.ProjectOverview;
+import org.apache.camel.dsl.jbang.core.commands.tui.diagram.FlowFeed;
import org.apache.camel.dsl.jbang.core.commands.tui.diagram.RouteDensity;
import
org.apache.camel.dsl.jbang.core.commands.tui.diagram.TopologyDiagramWidget;
import
org.apache.camel.dsl.jbang.core.commands.tui.diagram.TopologyDiagramWidget.NodeLine;
@@ -115,6 +116,8 @@ final class ArchitectureView {
private long lastCheck;
private long summaryModified;
private String lastGroup;
+ /** Whether the messages move between the groups: the Diagram tab's w, one
setting with the topology's. */
+ private boolean flowOn = true;
ArchitectureView(MonitorContext ctx, Consumer<Group> openGroup) {
this(ctx, openGroup, () -> true);
@@ -586,6 +589,24 @@ final class ArchitectureView {
// ---- rendering ----
+ void setFlowOn(boolean flowOn) {
+ this.flowOn = flowOn;
+ }
+
+ /** The next frame of the messages moving between the groups is due. */
+ boolean isFlowFrameDue() {
+ return active && support.zoom.flow().frameDue();
+ }
+
+ private FlowFeed flowFeed() {
+ IntegrationInfo info = ctx != null ? ctx.findSelectedIntegration() :
null;
+ Path d = dir;
+ return info == null || d == null
+ ? null
+ : ArchitectureFlow.feed(overview, capabilities, info.routes,
info.endpoints,
+ key -> RouteKeys.runningId(d, key));
+ }
+
void render(Frame frame, Rect area, String integrationName) {
render(frame, area, integrationName, List.of());
}
@@ -617,6 +638,9 @@ final class ArchitectureView {
spans.addAll(titleSuffix);
title = Line.from(spans);
}
+ // the messages moving between the groups, at the counts of the
running routes
+ support.zoom.flow().setEnabled(flowOn);
+ support.zoom.setFlowFeed(flowOn ? flowFeed() : null);
Group selected = selectedGroup();
if (selected != null && area.width() > 70) {
List<Rect> chunks = Layout.horizontal()
diff --git
a/dsl/camel-jbang/camel-jbang-plugin-tui/src/main/java/org/apache/camel/dsl/jbang/core/commands/tui/CamelMonitor.java
b/dsl/camel-jbang/camel-jbang-plugin-tui/src/main/java/org/apache/camel/dsl/jbang/core/commands/tui/CamelMonitor.java
index 89f6d0790875..cfc5907bfae9 100644
---
a/dsl/camel-jbang/camel-jbang-plugin-tui/src/main/java/org/apache/camel/dsl/jbang/core/commands/tui/CamelMonitor.java
+++
b/dsl/camel-jbang/camel-jbang-plugin-tui/src/main/java/org/apache/camel/dsl/jbang/core/commands/tui/CamelMonitor.java
@@ -1702,7 +1702,7 @@ public class CamelMonitor extends CamelCommand {
// refreshed by the next data-refresh redraw, which is bounded by
{@code interval}.
// Without this gate the tick loop forced a full redraw on every tick
(~25/s at the
// default 40ms tick rate) even while idle.
- return dataRefreshed || needsAnimationRedraw(
+ return dataRefreshed || tabRegistry.isFlowFrameDue() ||
needsAnimationRedraw(
shellPanel.isOpen(),
aiPanel.isOpen(),
logPinAnim.isAnimating(),
diff --git
a/dsl/camel-jbang/camel-jbang-plugin-tui/src/main/java/org/apache/camel/dsl/jbang/core/commands/tui/DiagramSupport.java
b/dsl/camel-jbang/camel-jbang-plugin-tui/src/main/java/org/apache/camel/dsl/jbang/core/commands/tui/DiagramSupport.java
index e77f407025ed..02dd3503176c 100644
---
a/dsl/camel-jbang/camel-jbang-plugin-tui/src/main/java/org/apache/camel/dsl/jbang/core/commands/tui/DiagramSupport.java
+++
b/dsl/camel-jbang/camel-jbang-plugin-tui/src/main/java/org/apache/camel/dsl/jbang/core/commands/tui/DiagramSupport.java
@@ -931,7 +931,8 @@ class DiagramSupport {
highlightRouteIds(), false)
.withAiDescriptions(aiDescriptions(),
Theme.aiAssisted()).withNodeLines(nodeLines)
.withGroups(groupTags,
groupColors).withErrorLayer(layoutShowErrorPaths ? errorLayer : null)
-
.withErrorMarks(errorMarkRouteIds()).withDensity(topologyDensity);
+
.withErrorMarks(errorMarkRouteIds()).withDensity(topologyDensity)
+ .withFlow(zoom.flow(), zoom.flowFeed());
}
/** A layout engine whose boxes the widget draws the given number of
columns wide. */
@@ -1569,7 +1570,7 @@ class DiagramSupport {
.withDensity(zoom.densityOf(routeLayout)).withFoldedSteps(zoom.foldedStepsOf(routeLayout))
.withErrorFrame(layoutShowErrorPaths ?
routeErrorFrames.get(currentRouteId) : null)
.withErrorMark(errorMarkRouteIds().contains(currentRouteId))
- .withBodyTypes(showBodyTypes).withBodyKindMarks(true);
+
.withBodyTypes(showBodyTypes).withBodyKindMarks(true).withFlow(zoom.flow());
var widget = widgets.get();
int totalRows = widget.getTotalRows();
diff --git
a/dsl/camel-jbang/camel-jbang-plugin-tui/src/main/java/org/apache/camel/dsl/jbang/core/commands/tui/DiagramTab.java
b/dsl/camel-jbang/camel-jbang-plugin-tui/src/main/java/org/apache/camel/dsl/jbang/core/commands/tui/DiagramTab.java
index 30800a8d4a40..40064bb77b9d 100644
---
a/dsl/camel-jbang/camel-jbang-plugin-tui/src/main/java/org/apache/camel/dsl/jbang/core/commands/tui/DiagramTab.java
+++
b/dsl/camel-jbang/camel-jbang-plugin-tui/src/main/java/org/apache/camel/dsl/jbang/core/commands/tui/DiagramTab.java
@@ -131,6 +131,12 @@ class DiagramTab extends AbstractDiagramTab {
architecture.refresh();
return true;
}
+ if (ke.isCharIgnoreCase('w')) {
+ // the messages moving between the groups: one setting with
the topology's and the route's
+
diagram.zoom.flow().setEnabled(!diagram.zoom.flow().isEnabled());
+ ctx.backgroundExecutor.execute(diagram.zoom::persist);
+ return true;
+ }
return architecture.handleKeyEvent(ke);
}
if (diagram.isShowDiagram() && ke.isChar('s')) {
@@ -352,6 +358,12 @@ class DiagramTab extends AbstractDiagramTab {
// ---- zoom levels (CAMEL-25147) ----
/** The level shown: the capability groups, the topology of all routes, or
one route's diagram. */
+ @Override
+ boolean isFlowFrameDue() {
+ // the architecture draws the messages moving between its groups with
a flow of its own
+ return architecture.isActive() ? architecture.isFlowFrameDue() :
super.isFlowFrameDue();
+ }
+
Level level() {
if (architecture.isActive()) {
return Level.ARCHITECTURE;
@@ -537,6 +549,7 @@ class DiagramTab extends AbstractDiagramTab {
new SubViewBar.Toggle("u", "utility",
architecture.isShowUtility() ? "on" : "off"),
new SubViewBar.Toggle("x", "errors",
diagram.isShowErrorPaths() ? "on" : "off"),
new SubViewBar.Toggle("e", "external",
architecture.isShowExternal() ? "edges" : "off"),
+ new SubViewBar.Toggle("w", "flow",
diagram.zoom.flow().isEnabled() ? "on" : "off"),
new SubViewBar.Toggle("+/-", "",
architecture.zoomLabel()));
case TOPOLOGY -> {
List<SubViewBar.Toggle> toggles = new ArrayList<>();
@@ -547,6 +560,7 @@ class DiagramTab extends AbstractDiagramTab {
}
toggles.add(new SubViewBar.Toggle("x", "errors",
errorsToggle()));
toggles.add(new SubViewBar.Toggle("m", "metrics", metrics));
+ toggles.add(new SubViewBar.Toggle("w", "flow",
diagram.zoom.flow().isEnabled() ? "on" : "off"));
toggles.add(new SubViewBar.Toggle(
"e", "external",
switch (externalMode) {
@@ -562,6 +576,7 @@ class DiagramTab extends AbstractDiagramTab {
case ROUTE -> List.of(view, new SubViewBar.Toggle("x", "errors",
errorsToggle()),
new SubViewBar.Toggle("+/-", "",
diagram.zoom.label(diagram.getRouteLayout(drillDownRouteId))),
new SubViewBar.Toggle("m", "metrics", metrics),
+ new SubViewBar.Toggle("w", "flow",
diagram.zoom.flow().isEnabled() ? "on" : "off"),
new SubViewBar.Toggle("y", "types",
diagram.isShowBodyTypes() ? "on" : "off"),
new SubViewBar.Toggle("d", "detail", detailMode ? "on" :
"off"), panelsToggle());
};
@@ -599,6 +614,7 @@ class DiagramTab extends AbstractDiagramTab {
}
if (architecture.isActive()) {
+ architecture.setFlowOn(diagram.zoom.flow().isEnabled());
architecture.render(frame, area, info.name, List.of());
return;
}
diff --git
a/dsl/camel-jbang/camel-jbang-plugin-tui/src/main/java/org/apache/camel/dsl/jbang/core/commands/tui/RouteDiagramZoom.java
b/dsl/camel-jbang/camel-jbang-plugin-tui/src/main/java/org/apache/camel/dsl/jbang/core/commands/tui/RouteDiagramZoom.java
index acfca22415fa..6c7697adea33 100644
---
a/dsl/camel-jbang/camel-jbang-plugin-tui/src/main/java/org/apache/camel/dsl/jbang/core/commands/tui/RouteDiagramZoom.java
+++
b/dsl/camel-jbang/camel-jbang-plugin-tui/src/main/java/org/apache/camel/dsl/jbang/core/commands/tui/RouteDiagramZoom.java
@@ -40,6 +40,8 @@ import
org.apache.camel.diagram.RouteDiagramLayoutEngine.RouteInfo;
import org.apache.camel.diagram.RouteDiagramLayoutEngine.TreeNode;
import org.apache.camel.diagram.RouteErrorFrame;
import org.apache.camel.diagram.TopologyErrorFrame;
+import org.apache.camel.dsl.jbang.core.commands.tui.diagram.FlowAnimation;
+import org.apache.camel.dsl.jbang.core.commands.tui.diagram.FlowFeed;
import org.apache.camel.dsl.jbang.core.commands.tui.diagram.RouteDensity;
import org.apache.camel.dsl.jbang.core.commands.tui.diagram.RouteDiagramWidget;
@@ -62,6 +64,8 @@ final class RouteDiagramZoom {
static final String PROP_GROUP_FOLDS = "camel.tui.groupFolds";
/** Whether the mini panels over the diagram (the map and the route tree)
are shown: false when hidden. */
static final String PROP_DIAGRAM_PANELS = "camel.tui.diagramPanels";
+ /** Whether the messages move through the route diagram (w): false when
turned off. */
+ static final String PROP_DIAGRAM_FLOW = "camel.tui.diagramFlow";
/** The selected step to select again once the route is laid out anew, and
its row on the screen. */
record Restore(int index, int row, int screenRow) {
@@ -77,6 +81,9 @@ final class RouteDiagramZoom {
private volatile RouteDensity density = DEFAULT;
private volatile boolean fit;
private volatile boolean panels = true;
+ // the messages moving through the route on screen: drawn and moved on the
UI thread only
+ private final FlowAnimation flow = new FlowAnimation();
+ private volatile FlowFeed flowFeed;
// the routes the History tab laid out whole, to lay them out again when
the zoom changes
private volatile Whole whole;
@@ -105,6 +112,7 @@ final class RouteDiagramZoom {
try {
zoom.setting(TuiUserConfig.read(PROP_ROUTE_ZOOM));
zoom.panels =
!"false".equals(TuiUserConfig.read(PROP_DIAGRAM_PANELS));
+
zoom.flow.setEnabled(!"false".equals(TuiUserConfig.read(PROP_DIAGRAM_FLOW)));
zoom.foldSetting(TuiUserConfig.read(PROP_ROUTE_FOLDS));
String groups = TuiUserConfig.read(PROP_GROUP_FOLDS);
if (groups != null && !groups.isBlank()) {
@@ -125,6 +133,7 @@ final class RouteDiagramZoom {
try {
TuiUserConfig.write(PROP_ROUTE_ZOOM, setting());
TuiUserConfig.write(PROP_DIAGRAM_PANELS, panels ? null : "false");
+ TuiUserConfig.write(PROP_DIAGRAM_FLOW, flow.isEnabled() ? null :
"false");
TuiUserConfig.write(PROP_ROUTE_FOLDS, foldSetting());
TuiUserConfig.write(PROP_GROUP_FOLDS, foldedGroups.isEmpty() ?
null : String.join(",", foldedGroups));
} catch (RuntimeException e) {
@@ -188,6 +197,22 @@ final class RouteDiagramZoom {
panels = !panels;
}
+ /**
+ * The messages moving through the route diagram and the topology, with
the metrics on: dots on the arrows.
+ */
+ FlowAnimation flow() {
+ return flow;
+ }
+
+ /** The counts the dots of a topology whose boxes are not the running
routes (the architecture) move at, or null. */
+ FlowFeed flowFeed() {
+ return flowFeed;
+ }
+
+ void setFlowFeed(FlowFeed flowFeed) {
+ this.flowFeed = flowFeed;
+ }
+
boolean isFit() {
return fit;
}
diff --git
a/dsl/camel-jbang/camel-jbang-plugin-tui/src/main/java/org/apache/camel/dsl/jbang/core/commands/tui/RoutesTab.java
b/dsl/camel-jbang/camel-jbang-plugin-tui/src/main/java/org/apache/camel/dsl/jbang/core/commands/tui/RoutesTab.java
index c510691eb068..a721f4737d44 100644
---
a/dsl/camel-jbang/camel-jbang-plugin-tui/src/main/java/org/apache/camel/dsl/jbang/core/commands/tui/RoutesTab.java
+++
b/dsl/camel-jbang/camel-jbang-plugin-tui/src/main/java/org/apache/camel/dsl/jbang/core/commands/tui/RoutesTab.java
@@ -736,6 +736,7 @@ class RoutesTab extends AbstractDiagramTab {
List<SubViewBar.Toggle> toggles = new ArrayList<>();
if (diagramShown) {
toggles.add(new SubViewBar.Toggle("m", "metrics", diagramMetrics ?
"on" : "off"));
+ toggles.add(new SubViewBar.Toggle("w", "flow",
diagram.zoom.flow().isEnabled() ? "on" : "off"));
if (topologyMode) {
toggles.add(new SubViewBar.Toggle("+/-", "",
diagram.zoom.label(diagram.getTopologyDensity())));
toggles.add(new SubViewBar.Toggle(
diff --git
a/dsl/camel-jbang/camel-jbang-plugin-tui/src/main/java/org/apache/camel/dsl/jbang/core/commands/tui/TabRegistry.java
b/dsl/camel-jbang/camel-jbang-plugin-tui/src/main/java/org/apache/camel/dsl/jbang/core/commands/tui/TabRegistry.java
index 36cac9bc77e0..b39f8028bb87 100644
---
a/dsl/camel-jbang/camel-jbang-plugin-tui/src/main/java/org/apache/camel/dsl/jbang/core/commands/tui/TabRegistry.java
+++
b/dsl/camel-jbang/camel-jbang-plugin-tui/src/main/java/org/apache/camel/dsl/jbang/core/commands/tui/TabRegistry.java
@@ -265,6 +265,11 @@ class TabRegistry {
// ---- Tab access ----
+ /** The tab on screen is a route diagram with messages moving through it:
it is time for its next frame. */
+ boolean isFlowFrameDue() {
+ return activeTab() instanceof AbstractDiagramTab tab &&
tab.isFlowFrameDue();
+ }
+
MonitorTab activeTab() {
int selected = tabsState.selected();
return selected == TAB_MORE ? activeMoreTab : primaryTab(selected);
diff --git
a/dsl/camel-jbang/camel-jbang-plugin-tui/src/main/java/org/apache/camel/dsl/jbang/core/commands/tui/diagram/FlowAnimation.java
b/dsl/camel-jbang/camel-jbang-plugin-tui/src/main/java/org/apache/camel/dsl/jbang/core/commands/tui/diagram/FlowAnimation.java
new file mode 100644
index 000000000000..d50771a59831
--- /dev/null
+++
b/dsl/camel-jbang/camel-jbang-plugin-tui/src/main/java/org/apache/camel/dsl/jbang/core/commands/tui/diagram/FlowAnimation.java
@@ -0,0 +1,241 @@
+/*
+ * 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.dsl.jbang.core.commands.tui.diagram;
+
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.function.LongSupplier;
+
+import org.apache.camel.diagram.RouteDiagramLayoutEngine.StatInfo;
+
+/**
+ * The messages moving through a route diagram while it is on screen: how many
a second reach each step, and the steps
+ * where exchanges wait without any finishing.
+ * <p>
+ * The numbers come from the counts of the steps (or the routes of a
topology), which the diagram loads again about once
+ * a second: a reload brings new objects to read them from, and the change of
the counts since the last one is the rate.
+ * The frames in between (every {@link #FRAME_MS} ms) move the dots on the
arrows, so the diagram shows where the
+ * messages go without any more calls to the integration.
+ */
+public final class FlowAnimation {
+
+ /** How often a frame is drawn while something moves: about 12 a second. */
+ public static final long FRAME_MS = 80;
+ /** With no new numbers for this long (the diagram is hidden, or the
integration stopped) nothing moves. */
+ static final long STALE_MS = 3000;
+ /** Exchanges that wait at a step this long without one finishing make it
a stuck step. */
+ static final long STUCK_MS = 2000;
+ /**
+ * A new object with the same counts this soon after the last reading is
the same reading laid out again (a zoom).
+ */
+ private static final long RELAID_MS = 500;
+ /** A track not seen for this long (another route, a step gone after a
reload) is forgotten. */
+ private static final long FORGET_MS = 60_000;
+ /** How much of the rate is from the readings before the last one. */
+ private static final double SMOOTHING = 0.6;
+
+ /**
+ * The counts of a step or a route as the diagram has them now, from the
object they were read from: the same object
+ * again is no new reading.
+ */
+ public record Reading(Object source, long total, long failed, long
inflight) {
+
+ public static Reading of(StatInfo stat) {
+ return new Reading(stat, stat.exchangesTotal,
stat.exchangesFailed, stat.exchangesInflight);
+ }
+ }
+
+ /** What the diagram knows of one step, or of the arrow into it. */
+ public static final class Track {
+ private Object last;
+ private long total;
+ private long failed;
+ private long sampleAt;
+ private long progressAt;
+ private long seenAt;
+ private double rate;
+ private double failRate;
+ private long inflight;
+ private long stuckSince = -1;
+ private double phase;
+
+ /** Exchanges a second that reached the step, from the last two
reloads. */
+ public double rate() {
+ return rate;
+ }
+
+ /** Exchanges a second that failed at the step. */
+ public double failRate() {
+ return failRate;
+ }
+
+ /** The exchanges at the step now. */
+ public long inflight() {
+ return inflight;
+ }
+
+ /** The distance the dots on the arrow have moved, in cells. */
+ public double phase() {
+ return phase;
+ }
+ }
+
+ private final Map<String, Track> tracks = new HashMap<>();
+ private final LongSupplier clock;
+ private boolean enabled = true;
+ private long lastUpdate = -1;
+
+ public FlowAnimation() {
+ this(() -> System.nanoTime() / 1_000_000);
+ }
+
+ FlowAnimation(LongSupplier clock) {
+ this.clock = clock;
+ }
+
+ public boolean isEnabled() {
+ return enabled;
+ }
+
+ public void setEnabled(boolean enabled) {
+ this.enabled = enabled;
+ if (!enabled) {
+ tracks.clear();
+ lastUpdate = -1;
+ }
+ }
+
+ /**
+ * Brings the tracks up to date with the counts of the steps on screen, by
their key: counts from an object not seen
+ * before are a new reading, from the same one again the frame between two
reloads. Then the dots move on by the
+ * time since the last frame.
+ */
+ public void update(Map<String, Reading> stats) {
+ long now = clock.getAsLong();
+ double dt = lastUpdate < 0 ? 0 : Math.min(0.25, (now - lastUpdate) /
1000.0);
+ lastUpdate = now;
+ for (Map.Entry<String, Reading> e : stats.entrySet()) {
+ Track t = tracks.computeIfAbsent(e.getKey(), k -> new Track());
+ t.seenAt = now;
+ read(t, e.getValue(), now);
+ }
+ for (Iterator<Track> it = tracks.values().iterator(); it.hasNext();) {
+ Track t = it.next();
+ if (now - t.seenAt > FORGET_MS) {
+ it.remove();
+ continue;
+ }
+ t.phase += speed(t.rate) * dt;
+ }
+ }
+
+ private static void read(Track t, Reading stat, long now) {
+ if (stat.source() != t.last && t.last != null && now - t.sampleAt <
RELAID_MS
+ && stat.total() == t.total && stat.failed() == t.failed) {
+ t.last = stat.source();
+ }
+ if (stat.source() == t.last) {
+ if (now - t.sampleAt > STALE_MS) {
+ // no new numbers: nothing is known to move
+ t.rate = 0;
+ t.failRate = 0;
+ }
+ return;
+ }
+ if (t.last != null && now > t.sampleAt) {
+ double seconds = (now - t.sampleAt) / 1000.0;
+ t.rate = smooth(t.rate, Math.max(0, stat.total() - t.total) /
seconds);
+ t.failRate = smooth(t.failRate, Math.max(0, stat.failed() -
t.failed) / seconds);
+ }
+ boolean progressed = t.last == null || stat.total() > t.total;
+ if (progressed) {
+ t.progressAt = now;
+ }
+ t.inflight = stat.inflight();
+ if (t.inflight > 0 && !progressed) {
+ if (t.stuckSince < 0) {
+ t.stuckSince = t.progressAt;
+ }
+ } else {
+ t.stuckSince = -1;
+ }
+ t.last = stat.source();
+ t.total = stat.total();
+ t.failed = stat.failed();
+ t.sampleAt = now;
+ }
+
+ /**
+ * The rate with the readings before it: a few messages a second come in
fits and starts, and the dots would jump
+ * between fast and slow. No messages stops it at once, so the dots stop
when the messages do.
+ */
+ private static double smooth(double rate, double reading) {
+ return reading == 0 || rate == 0 ? reading : rate * SMOOTHING +
reading * (1 - SMOOTHING);
+ }
+
+ /** The cells a second the dots move: faster the more messages there are.
*/
+ static double speed(double rate) {
+ return rate <= 0 ? 0 : 3 + 2.2 * log2(1 + rate);
+ }
+
+ /** The cells between two dots on an arrow: closer the more messages there
are. */
+ public static int spacing(double rate) {
+ return (int) Math.max(4, Math.min(14, Math.round(14 - 2 * log2(1 +
rate))));
+ }
+
+ private static double log2(double v) {
+ return Math.log(v) / Math.log(2);
+ }
+
+ /** The track of a step or arrow, or null when it is not known. */
+ public Track get(String key) {
+ return tracks.get(key);
+ }
+
+ /** How long exchanges have waited at the step without one finishing, or
-1 when it is not stuck. */
+ public long stuckMillis(Track t) {
+ if (t == null || t.stuckSince < 0 || t.inflight <= 0) {
+ return -1;
+ }
+ long waited = clock.getAsLong() - t.stuckSince;
+ return waited >= STUCK_MS ? waited : -1;
+ }
+
+ /** The time on the clock of the animation, for the frames of a spinner. */
+ public long now() {
+ return clock.getAsLong();
+ }
+
+ /** Something on screen moves: dots on an arrow, or the spinner of a stuck
step. */
+ public boolean isAnimating() {
+ if (!enabled || lastUpdate < 0 || clock.getAsLong() - lastUpdate >
STALE_MS) {
+ return false;
+ }
+ for (Track t : tracks.values()) {
+ if (t.rate > 0 || stuckMillis(t) >= 0) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ /** The next frame of the animation is due: it is time to draw the diagram
again. */
+ public boolean frameDue() {
+ return isAnimating() && clock.getAsLong() - lastUpdate >= FRAME_MS;
+ }
+}
diff --git
a/dsl/camel-jbang/camel-jbang-plugin-tui/src/main/java/org/apache/camel/dsl/jbang/core/commands/tui/diagram/FlowDots.java
b/dsl/camel-jbang/camel-jbang-plugin-tui/src/main/java/org/apache/camel/dsl/jbang/core/commands/tui/diagram/FlowDots.java
new file mode 100644
index 000000000000..c1505d1b8a3d
--- /dev/null
+++
b/dsl/camel-jbang/camel-jbang-plugin-tui/src/main/java/org/apache/camel/dsl/jbang/core/commands/tui/diagram/FlowDots.java
@@ -0,0 +1,183 @@
+/*
+ * 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.dsl.jbang.core.commands.tui.diagram;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import dev.tamboui.buffer.Buffer;
+import dev.tamboui.layout.Rect;
+import dev.tamboui.style.Color;
+import dev.tamboui.style.Style;
+import org.apache.camel.dsl.jbang.core.commands.tui.Theme;
+
+import static
org.apache.camel.dsl.jbang.core.commands.tui.diagram.DiagramColors.failColor;
+
+/**
+ * The dots of the messages on the arrows of a diagram (a route or the
topology), drawn over the lines the arrows are
+ * drawn with, at the pace of a {@link FlowAnimation.Track}.
+ */
+final class FlowDots {
+
+ /** The cell of a line lit up as it is: no dot on it. */
+ static final char LIT = 0;
+
+ /**
+ * The cells of an arrow in the order a message goes along them, and its
head (a char of 0 when the line goes on to
+ * the mark of a step, with no head).
+ */
+ record Path(String key, int fromRow, List<int[]> cells, int[] head, char
headChar) {
+ }
+
+ private FlowDots() {
+ }
+
+ /**
+ * The path of an arrow as the diagrams draw one: down from the source,
along a row half way when the target is in
+ * another column, and down to the target; with a head in the row above
the target, or none.
+ */
+ static Path path(String key, int fromCx, int fromRow, int toCx, int toRow,
char headChar) {
+ int end = headChar != 0 ? toRow - 1 : toRow;
+ List<int[]> cells = new ArrayList<>();
+ if (fromCx == toCx) {
+ for (int r = fromRow; r < end; r++) {
+ cells.add(new int[] { r, fromCx });
+ }
+ } else {
+ int midRow = fromRow + (toRow - fromRow) / 2;
+ for (int r = fromRow; r < midRow; r++) {
+ cells.add(new int[] { r, fromCx });
+ }
+ int step = toCx > fromCx ? 1 : -1;
+ for (int c = fromCx; c != toCx + step; c += step) {
+ cells.add(new int[] { midRow, c });
+ }
+ for (int r = midRow + 1; r < end; r++) {
+ cells.add(new int[] { r, toCx });
+ }
+ }
+ return new Path(key, fromRow, cells, headChar != 0 ? new int[] { toRow
- 1, toCx } : null, headChar);
+ }
+
+ /**
+ * The dots on an arrow that messages go along, red when most of them
fail; or with {@code dots} off its line lit
+ * up, where a dot would look like the mark of a step. A letter, a digit
or a char of {@code keep} on the way stays.
+ */
+ static void draw(
+ Buffer buffer, Rect area, int scrollX, int scrollY, Path path,
FlowAnimation.Track t, boolean dots,
+ String keep) {
+ if (t == null || t.rate() <= 0) {
+ return;
+ }
+ int spacing = FlowAnimation.spacing(t.rate());
+ long moved = (long) Math.floor(t.phase());
+ // the foreground of the theme: the dots are lights on the lines,
whatever the colours of the steps are
+ Color head = light(t);
+ Color tail = mix(head, Theme.muted().fg().orElse(Color.GRAY), 0.5);
+ Style dotStyle = dots ? Style.EMPTY.fg(head) :
Style.EMPTY.fg(head).bold();
+ List<int[]> cells = path.cells();
+ // the head last: an arrow of a compact diagram is only its head,
which then lights up as the dots come by
+ int last = path.head() != null ? cells.size() : cells.size() - 1;
+ for (int i = 0; i <= last; i++) {
+ // counted from the top of the diagram: below a box the dots go on
at the same pace
+ if (Math.floorMod(path.fromRow() + i - moved, spacing) == 0) {
+ if (i == cells.size()) {
+ dot(buffer, area, scrollX, scrollY, path.head(),
path.headChar(), Style.EMPTY.fg(head).bold(),
+ path.headChar(), keep);
+ } else {
+ dot(buffer, area, scrollX, scrollY, cells.get(i), dots ?
'●' : LIT, dotStyle, (char) 0, keep);
+ }
+ if (i > 0) {
+ dot(buffer, area, scrollX, scrollY, cells.get(i - 1), dots
? '•' : LIT, Style.EMPTY.fg(tail),
+ (char) 0, keep);
+ }
+ }
+ }
+ }
+
+ /** A dot on a line of an arrow, or its head lit up (only where the head
is). */
+ private static void dot(
+ Buffer buffer, Rect area, int scrollX, int scrollY, int[] cell,
char ch, Style style, char onHead,
+ String keep) {
+ int x = area.x() + cell[1] - scrollX;
+ int y = area.y() + cell[0] - scrollY;
+ if (x < area.left() || x >= area.right() || y < area.top() || y >=
area.bottom()) {
+ return;
+ }
+ String existing = buffer.get(x, y).symbol();
+ if (onHead != 0) {
+ // a head on the line of a branch is the head of that arrow, not a
cell of its line
+ if (!existing.equals(String.valueOf(onHead))) {
+ return;
+ }
+ } else if (!existing.isEmpty() &&
(Character.isLetterOrDigit(existing.codePointAt(0))
+ || keep.indexOf(existing.charAt(0)) >= 0)) {
+ return;
+ }
+ if (ch == LIT && existing.isBlank()) {
+ return;
+ }
+ buffer.setString(x, y, ch == LIT ? existing : String.valueOf(ch),
style);
+ }
+
+ /** The colour of the dots of a track: the foreground of the theme, or red
when most of the messages fail. */
+ static Color light(FlowAnimation.Track t) {
+ return t.failRate() * 2 > t.rate() ? failColor() : Theme.baseFg();
+ }
+
+ /**
+ * The colour of a mark in a row as the light of the messages passes over
it, at the pace of the dots on the lines:
+ * the marks of a busy path light up one after another.
+ */
+ static Color lit(Color base, FlowAnimation.Track t, int row) {
+ if (t == null || t.rate() <= 0) {
+ return base;
+ }
+ int spacing = FlowAnimation.spacing(t.rate());
+ int at = Math.floorMod(row - (long) Math.floor(t.phase()), spacing);
+ if (at == 0) {
+ return mix(base, light(t), 0.7);
+ }
+ return at == spacing - 1 ? mix(base, light(t), 0.35) : base;
+ }
+
+ /** The colour between two colours, {@code t} of the way from the first. */
+ static Color mix(Color from, Color to, double t) {
+ if (t <= 0) {
+ return from;
+ }
+ if (terminalDefault(from) || terminalDefault(to)) {
+ // the default of the terminal has no RGB of its own (toRgb gives
white), so it is not mixed
+ return t < 0.5 ? from : to;
+ }
+ Color.Rgb a = from.toRgb();
+ Color.Rgb b = to.toRgb();
+ return Color.rgb(
+ a.r() + (int) Math.round((b.r() - a.r()) * t),
+ a.g() + (int) Math.round((b.g() - a.g()) * t),
+ a.b() + (int) Math.round((b.b() - a.b()) * t));
+ }
+
+ /** Whether the colour is the default of the terminal, also when a theme
names it. */
+ static boolean terminalDefault(Color color) {
+ Color c = color;
+ while (c instanceof Color.Named named) {
+ c = named.defaultValue();
+ }
+ return c instanceof Color.Reset;
+ }
+}
diff --git
a/dsl/camel-jbang/camel-jbang-plugin-tui/src/main/java/org/apache/camel/dsl/jbang/core/commands/tui/diagram/FlowFeed.java
b/dsl/camel-jbang/camel-jbang-plugin-tui/src/main/java/org/apache/camel/dsl/jbang/core/commands/tui/diagram/FlowFeed.java
new file mode 100644
index 000000000000..4de433ce48ac
--- /dev/null
+++
b/dsl/camel-jbang/camel-jbang-plugin-tui/src/main/java/org/apache/camel/dsl/jbang/core/commands/tui/diagram/FlowFeed.java
@@ -0,0 +1,41 @@
+/*
+ * 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.dsl.jbang.core.commands.tui.diagram;
+
+import java.util.List;
+import java.util.Map;
+
+/**
+ * The counts a topology whose boxes are not the running routes (the
architecture) moves its dots at: the readings by
+ * their key, and for each edge (by the ids of its boxes, {@code from>to}) the
reading it moves at.
+ *
+ * @param readings the counts by their key
+ * @param edges the reading of each edge, by {@link #edgeId}
+ */
+public record FlowFeed(Map<String, FlowAnimation.Reading> readings,
Map<String, Edge> edges) {
+
+ /**
+ * The reading an edge moves at, and the readings of the routes that send
along it: none of them moving, the edge
+ * does not either (none means it always may).
+ */
+ public record Edge(String key, List<String> senders) {
+ }
+
+ public static String edgeId(String from, String to) {
+ return from + ">" + to;
+ }
+}
diff --git
a/dsl/camel-jbang/camel-jbang-plugin-tui/src/main/java/org/apache/camel/dsl/jbang/core/commands/tui/diagram/RouteDiagramWidget.java
b/dsl/camel-jbang/camel-jbang-plugin-tui/src/main/java/org/apache/camel/dsl/jbang/core/commands/tui/diagram/RouteDiagramWidget.java
index b6f20ac2733d..e699546579e5 100644
---
a/dsl/camel-jbang/camel-jbang-plugin-tui/src/main/java/org/apache/camel/dsl/jbang/core/commands/tui/diagram/RouteDiagramWidget.java
+++
b/dsl/camel-jbang/camel-jbang-plugin-tui/src/main/java/org/apache/camel/dsl/jbang/core/commands/tui/diagram/RouteDiagramWidget.java
@@ -18,6 +18,7 @@ package org.apache.camel.dsl.jbang.core.commands.tui.diagram;
import java.util.ArrayList;
import java.util.Collections;
+import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
@@ -162,6 +163,10 @@ public class RouteDiagramWidget implements Widget {
foldHits.clear();
arrowCells.clear();
arrowEnds.clear();
+ flowArrows.clear();
+ if (flow != null) {
+ updateFlow();
+ }
if (errorFrame != null) {
drawErrorFrame(buffer, area);
@@ -186,6 +191,10 @@ public class RouteDiagramWidget implements Widget {
}
}
}
+ // the dots over the lines, before the boxes
+ for (FlowDots.Path arrow : flowArrows) {
+ FlowDots.draw(buffer, area, scrollX, scrollY, arrow,
flow.get(arrow.key()), density.boxed(), FLOW_KEEP);
+ }
// Nodes (on top, skip the structural "route" node)
markers.clear();
@@ -298,6 +307,20 @@ public class RouteDiagramWidget implements Widget {
return this;
}
+ private FlowAnimation flow;
+ /** The arrows the dots of the flow move on, in the order the messages go
along their cells. */
+ private final List<FlowDots.Path> flowArrows = new ArrayList<>();
+
+ /**
+ * The messages moving through the route (with the metrics on): dots on
the arrows that move faster and closer
+ * together the more messages there are (at the overview, a light over the
steps), and the steps where exchanges
+ * wait with none finishing marked as stuck.
+ */
+ public RouteDiagramWidget withFlow(FlowAnimation flow) {
+ this.flow = flow != null && flow.isEnabled() && showMetrics ? flow :
null;
+ return this;
+ }
+
private boolean bodyTypes;
private boolean bodyKindMarks;
/** The cells of the arrows and their counts, which the body types beside
an arrow stop at. */
@@ -492,7 +515,8 @@ public class RouteDiagramWidget implements Widget {
// a remote endpoint is an edge of the integration: its own color,
as in the topology
eipColor = external ? externalColor() : getEipColor(node.type);
}
- Style borderStyle = Style.EMPTY.fg(eipColor);
+ String stuck = highlighted ? null : stuckText(node);
+ Style borderStyle = stuck != null ? Theme.warning().bold() :
Style.EMPTY.fg(eipColor);
if (selected) {
borderStyle = borderStyle.patch(selectionStyle());
}
@@ -547,6 +571,10 @@ public class RouteDiagramWidget implements Widget {
// bodies of more than one kind reach the step: it needs attention
writeText(buffer, area, row, col + boxWidth - 3, BodyTypes.MARK,
Theme.warning());
}
+ if (stuck != null) {
+ // exchanges wait here with none finishing: how many, and for how
long, in the top border
+ writeText(buffer, area, row, col + 1, stuck, borderStyle);
+ }
// Link indicator for nodes that connect to other routes
String linkedRouteId = findLinkedRouteId(node);
@@ -591,6 +619,7 @@ public class RouteDiagramWidget implements Widget {
&& to.id != null && highlightNodeIds.contains(to.id);
drawArrowPath(buffer, area, fromCx, fromBottom, toCx, toTop, dashed,
external, bothHighlighted);
+ addFlowArrow(to, fromCx, fromBottom, toCx, toTop);
if (density != RouteDensity.OVERVIEW) {
// the steps of the overview are next to each other: no room for a
count
addArrowEnd(to, fromCx, fromBottom, toCx, toTop,
drawCounters(buffer, area, toCx, toTop, stat));
@@ -611,6 +640,7 @@ public class RouteDiagramWidget implements Widget {
&& to.id != null && highlightNodeIds.contains(to.id);
drawArrowPath(buffer, area, fromCx, fromRow, toCx, toTop, dashed,
false, highlighted);
+ addFlowArrow(to, fromCx, fromRow, toCx, toTop);
if (density != RouteDensity.OVERVIEW) {
addArrowEnd(to, fromCx, fromRow, toCx, toTop, drawCounters(buffer,
area, toCx, toTop, stat));
}
@@ -1090,7 +1120,8 @@ public class RouteDiagramWidget implements Widget {
} else if (stat != null && stat.exchangesFailed > 0) {
color = highlightFailColor();
} else {
- color = isExternalEndpoint(node) ? externalColor() :
getEipColor(node.type);
+ // no lines between the steps: the light of the messages passes
over the steps themselves
+ color = lit(isExternalEndpoint(node) ? externalColor() :
getEipColor(node.type), node, row);
}
String cell;
if ("from".equals(node.type)) {
@@ -1150,6 +1181,94 @@ public class RouteDiagramWidget implements Widget {
return DiagramText.wrap(text, maxWidth, MAX_WRAP_LINES);
}
+ // ---- the flow of the messages ----
+
+ private static final String SPINNER = "⠋⠙⠹⠸⠼⠴⠦⠧⠇⠏";
+ /** What a dot does not cover: the frame of a block, and the head of
another arrow. */
+ private static final String FLOW_KEEP = "" + SCOPE_H + SCOPE_V + ARROW;
+
+ private String flowKey(LayoutNode node) {
+ return layoutRoute.routeId + "/" + node.id;
+ }
+
+ /**
+ * The counts of the steps to the flow: of each step for when it is stuck,
and of the arrow into it for its dots.
+ */
+ private void updateFlow() {
+ Map<String, FlowAnimation.Reading> stats = new HashMap<>();
+ for (LayoutNode ln : layoutRoute.nodes) {
+ if (ln.id == null || ln.treeNode == null ||
"route".equals(ln.type)) {
+ continue;
+ }
+ if (ln.treeNode.info.stat != null) {
+ stats.put(flowKey(ln),
FlowAnimation.Reading.of(ln.treeNode.info.stat));
+ }
+ StatInfo in = resolveStatInfo(ln);
+ if (in != null) {
+ stats.put(flowKey(ln) + ">", FlowAnimation.Reading.of(in));
+ }
+ }
+ flow.update(stats);
+ }
+
+ /** The cells of an arrow as drawn by {@link #drawArrowPath}, in the order
a message goes along them. */
+ private void addFlowArrow(LayoutNode to, int fromCx, int fromRow, int
toCx, int toRow) {
+ if (flow != null && to.id != null && fromRow < toRow) {
+ // a boxed step has the head of the arrow above it; without boxes
the line goes on to the mark of the step
+ flowArrows.add(FlowDots.path(flowKey(to) + ">", fromCx, fromRow,
toCx, toRow, density.boxed() ? ARROW : 0));
+ }
+ }
+
+ /**
+ * The colour of a step of the overview as the light of the messages into
it passes over it, at the pace of the dots
+ * on the lines of the other zoom levels: the steps of a busy path light
up one after another.
+ */
+ private Color lit(Color base, LayoutNode node, int row) {
+ return FlowDots.lit(base, flow != null && node.id != null ?
flow.get(flowKey(node) + ">") : null, row);
+ }
+
+ /**
+ * The text in the top border of a step where exchanges wait with none
finishing: a spinner, how many, and how long;
+ * or null. A step with steps inside it (a choice, a split) waits for
them, so only the step itself has it.
+ */
+ private String stuckText(LayoutNode node) {
+ if (flow == null || node.id == null || node.treeNode == null ||
"from".equals(node.type)
+ || !node.treeNode.children.isEmpty()) {
+ return null;
+ }
+ FlowAnimation.Track t = flow.get(flowKey(node));
+ long waited = flow.stuckMillis(t);
+ if (waited < 0) {
+ return null;
+ }
+ char spin = SPINNER.charAt((int) (flow.now() / 100 %
SPINNER.length()));
+ // since the step last finished an exchange, as the integration says;
the time the diagram has watched it else
+ StatInfo stat = node.treeNode.info.stat;
+ String age;
+ if (stat != null && stat.lastCompletedExchangeTimestamp > 0) {
+ age = duration(Math.max(waited, System.currentTimeMillis() -
stat.lastCompletedExchangeTimestamp));
+ } else if (stat != null && stat.exchangesTotal == 0) {
+ age = "none done";
+ } else {
+ age = duration(waited);
+ }
+ String head = " " + spin + " ";
+ for (String text : List.of(head + t.inflight() + " inflight · " + age
+ " ",
+ head + t.inflight() + " · " + age + " ", head + age + " ")) {
+ if (CharWidth.of(text) <= boxWidth - 5) {
+ return text;
+ }
+ }
+ return null;
+ }
+
+ private static String duration(long millis) {
+ if (millis < 60_000) {
+ return millis / 1000 + "s";
+ }
+ return millis < 3_600_000 ? millis / 60_000 + "m" : millis / 3_600_000
+ "h";
+ }
+
private void setChar(Buffer buffer, Rect area, int gridRow, int gridCol,
char ch, Style style) {
int x = area.x() + gridCol - scrollX;
int y = area.y() + gridRow - scrollY;
diff --git
a/dsl/camel-jbang/camel-jbang-plugin-tui/src/main/java/org/apache/camel/dsl/jbang/core/commands/tui/diagram/TopologyDiagramWidget.java
b/dsl/camel-jbang/camel-jbang-plugin-tui/src/main/java/org/apache/camel/dsl/jbang/core/commands/tui/diagram/TopologyDiagramWidget.java
index cbf10d9559a6..68cf77f45342 100644
---
a/dsl/camel-jbang/camel-jbang-plugin-tui/src/main/java/org/apache/camel/dsl/jbang/core/commands/tui/diagram/TopologyDiagramWidget.java
+++
b/dsl/camel-jbang/camel-jbang-plugin-tui/src/main/java/org/apache/camel/dsl/jbang/core/commands/tui/diagram/TopologyDiagramWidget.java
@@ -18,6 +18,7 @@ package org.apache.camel.dsl.jbang.core.commands.tui.diagram;
import java.util.ArrayList;
import java.util.Collections;
+import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
@@ -70,6 +71,9 @@ public class TopologyDiagramWidget implements Widget {
private Set<String> errorMarks = Set.of();
private Map<TopologyLayoutNode, List<String>> errorLabels;
private RouteDensity density = RouteDensity.DETAILED;
+ private FlowAnimation flow;
+ private FlowFeed flowFeed;
+ private final List<FlowDots.Path> flowArrows = new ArrayList<>();
public record NodeBox(String routeId, int startRow, int endRow, int
startCol, int endCol, int layer) {
}
@@ -269,6 +273,24 @@ public class TopologyDiagramWidget implements Widget {
return this;
}
+ /**
+ * The messages moving between the routes (with the metrics on): dots on
the edges into the routes that get
+ * messages, faster and closer together the more messages a second the
route gets.
+ */
+ public TopologyDiagramWidget withFlow(FlowAnimation flow) {
+ return withFlow(flow, null);
+ }
+
+ /**
+ * The messages moving along the edges, at the counts of the boxes (the
routes, with the metrics on), or of the feed
+ * when the boxes are not the running routes (the architecture).
+ */
+ public TopologyDiagramWidget withFlow(FlowAnimation flow, FlowFeed feed) {
+ this.flowFeed = feed;
+ this.flow = flow != null && flow.isEnabled() && (showMetrics || feed
!= null) ? flow : null;
+ return this;
+ }
+
public List<NodeBox> getNodeBoxes() {
return nodeBoxes;
}
@@ -276,6 +298,10 @@ public class TopologyDiagramWidget implements Widget {
@Override
public void render(Rect area, Buffer buffer) {
nodeBoxes.clear();
+ flowArrows.clear();
+ if (flow != null) {
+ updateFlow();
+ }
if (errorLayer != null) {
drawErrorFrame(buffer, area);
@@ -292,6 +318,10 @@ public class TopologyDiagramWidget implements Widget {
drawSelfLoop(buffer, area, edge);
}
}
+ // the dots over the lines, before the boxes
+ for (FlowDots.Path arrow : flowArrows) {
+ FlowDots.draw(buffer, area, scrollX, scrollY, arrow,
flow.get(arrow.key()), density.boxed(), FLOW_KEEP);
+ }
for (TopologyLayoutNode node : layout.nodes) {
drawNode(buffer, area, node);
@@ -641,6 +671,74 @@ public class TopologyDiagramWidget implements Widget {
}
setChar(buffer, area, toTop - 1, toCx, head, edgeStyle);
}
+ String key = flowKey(edge);
+ if (key != null) {
+ flowArrows.add(FlowDots.path(key, fromCx, fromBottom, toCx, toTop,
head));
+ }
+ }
+
+ // ---- the flow of the messages ----
+
+ /** What a dot does not cover: the head of another edge. */
+ private static final String FLOW_KEEP = "" + ARROW + REPLY_ARROW;
+
+ /** The key of the counts of a route (or an external system) of the
topology. */
+ private static String flowKey(TopologyLayoutNode node) {
+ String id = node.routeId != null ? node.routeId : node.from;
+ return id != null ? "topology/" + id : null;
+ }
+
+ /** The counts of the routes to the flow, and of the external systems that
have counts. */
+ private void updateFlow() {
+ if (flowFeed != null) {
+ flow.update(flowFeed.readings());
+ return;
+ }
+ Map<String, FlowAnimation.Reading> readings = new HashMap<>();
+ for (TopologyLayoutNode node : layout.nodes) {
+ String key = flowKey(node);
+ if (key != null && counted(node)) {
+ // a reload lays the topology out anew: new nodes are a new
reading
+ readings.put(key, new FlowAnimation.Reading(node,
node.exchangesTotal, node.exchangesFailed, 0));
+ }
+ }
+ flow.update(readings);
+ }
+
+ /** A route has counts; an external system only when the integration
counts its messages. */
+ private static boolean counted(TopologyLayoutNode node) {
+ return !isExternal(node) || node.exchangesTotal > 0;
+ }
+
+ /**
+ * The counts an edge moves at: those of the route it goes into, which
gets the messages; or of the route it comes
+ * from when it goes to a system that is not counted. None from a route
that gets no messages: the route it goes
+ * into may get them from another one.
+ */
+ private String flowKey(TopologyLayoutEdge edge) {
+ if (flow == null || edge.to == null || edge.from == null) {
+ return null;
+ }
+ if (flowFeed != null) {
+ FlowFeed.Edge e =
flowFeed.edges().get(FlowFeed.edgeId(edge.from.routeId, edge.to.routeId));
+ if (e == null || !e.senders().isEmpty() &&
e.senders().stream().map(flow::get)
+ .noneMatch(t -> t != null && t.rate() > 0)) {
+ return null;
+ }
+ return e.key();
+ }
+ String from = flowKey(edge.from);
+ String to = flowKey(edge.to);
+ if (from == null || to == null) {
+ return null;
+ }
+ if (counted(edge.from)) {
+ FlowAnimation.Track source = flow.get(from);
+ if (source == null || source.rate() <= 0) {
+ return null;
+ }
+ }
+ return counted(edge.to) ? to : counted(edge.from) ? from : null;
}
private void drawSelfLoop(Buffer buffer, Rect area, TopologyLayoutEdge
edge) {
diff --git
a/dsl/camel-jbang/camel-jbang-plugin-tui/src/main/resources/tui/help/diagram.md
b/dsl/camel-jbang/camel-jbang-plugin-tui/src/main/resources/tui/help/diagram.md
index 74e696d1fdb4..7a4c01bc16ec 100644
---
a/dsl/camel-jbang/camel-jbang-plugin-tui/src/main/resources/tui/help/diagram.md
+++
b/dsl/camel-jbang/camel-jbang-plugin-tui/src/main/resources/tui/help/diagram.md
@@ -98,7 +98,8 @@ state: `a` ai (off shows only what the sources and the runtime
say: no AI labels, notes or capabilities; it does not change the AI
overview setting; with no summary yet it has the AI write one, as
`/overview` does), `b` view (business: labels and what capabilities achieve;
-technical: route ids and endpoints), `m` metrics, `e` external, `y` types
+technical: route ids and endpoints), `m` metrics, `e` external, `w` flow
+(the messages moving through a route), `y` types
(the body types on the arrows of a route), `+/-` zoom (how much room a step of
a route takes;
fit when `z` chose it for the screen), `d` detail, `g` group, `u` utility (one
setting for the architecture
and the topology, so both show the same groups), `x` errors (the
@@ -196,6 +197,42 @@ lists them all with their kind, and in the topology the
Info panel of a
route says how many of its steps were reached with more than one type
(`⚠ 1 mixed · 2 varied`).
+## Live Flow
+
+With the metrics on, a route diagram and the topology show where the
+messages go while the integration runs, so the busy part stands out at a
+glance; the architecture shows it between its groups. `w` turns it off
+and on (kept for the next start).
+
+- **Dots on the arrows** move along an arrow while messages reach the
+ step below it: the more messages a second, the faster and closer
+ together they are. They are red when most of the messages fail there.
+ In compact the head of an arrow lights up as a dot comes in. In bare
+ and overview the lines light up instead, as a dot would look like the
+ mark of a step there. The overview has hardly any lines between its
+ steps, so there the light passes over the steps themselves.
+- **In the topology** the dots go along the edges into the routes that
+ get messages, at the pace of the route they go into. An edge from a
+ route that gets no messages has none, even when the route it goes
+ into gets them from another one.
+- **In the architecture** the dots go along a link at the pace of the
+ messages into the routes of the group it goes to, from the routes of
+ the group it comes from; with `x` on, red dots go into the Error
+ handling box at the pace the routes of a group fail; with `e` on, the
+ dots come in from an external system at the pace of the route that
+ consumes from it, and go out to one at the pace of the messages sent
+ to it. It needs the integration running: a source route counts when
+ it is matched to a running route.
+- **Stuck** (a route diagram): a step where exchanges wait and none has
finished for a
+ few seconds has a spinner in its top border, with how many wait and
+ how long ago the step last finished one (`⠹ 3 inflight · 12s`), or
+ `none done` when it never did, such as a call to a system that does
+ not answer.
+
+The rates come from the counts the diagram reloads about once a second;
+the dots move in between, about 12 frames a second, only
+while something moves.
+
## Route Structure Preview
A compact tree structure preview appears in the bottom-right corner
@@ -259,6 +296,8 @@ you an at-a-glance view of where you are in the route.
- `x` — show or hide the route's error handling, in a frame below it
- `y` — show the body types each step has been reached with, beside the
arrows into the steps
+- `w` — live flow on or off: dots on the arrows, the stuck steps marked
+ (with the metrics on)
- `g` — go to node (fuzzy search popup)
- `+` / `-` — zoom in or out: detailed (boxes with up to three lines),
compact (the default: boxes with one line, the steps closer together) and
bare (a
@@ -290,6 +329,7 @@ you an at-a-glance view of where you are in the route.
**Common:**
- `m` — toggle metrics on/off (default: on)
+- `w` — live flow on or off: dots on the arrows (with the metrics on)
- `e` — toggle external systems on/off (topology only)
- `b` — business or technical view (`n` works too)
- `PgUp/PgDn` — page scroll
diff --git
a/dsl/camel-jbang/camel-jbang-plugin-tui/src/main/resources/tui/help/routes.md
b/dsl/camel-jbang/camel-jbang-plugin-tui/src/main/resources/tui/help/routes.md
index 4bbdefa53e28..32ce02c312eb 100644
---
a/dsl/camel-jbang/camel-jbang-plugin-tui/src/main/resources/tui/help/routes.md
+++
b/dsl/camel-jbang/camel-jbang-plugin-tui/src/main/resources/tui/help/routes.md
@@ -162,6 +162,7 @@ in the diagram.
topology (top right of a route) and the tree of the route (bottom right)
- `Esc` — close diagram (back to route table)
- `m` — toggle metrics on/off
+- `w` — toggle the live flow: dots on the edges into the routes that get
messages
- `e` — toggle external systems on/off
- `n` — toggle description labels
@@ -190,6 +191,7 @@ in the diagram.
- `Esc` — go back (previous route or topology)
- `t` — jump back to topology view
- `m` — toggle metrics
+- `w` — toggle the live flow: dots on the arrows, the stuck steps marked
- `y` — toggle the body types each step has been reached with, beside the
arrows
- `n` — toggle description labels
- `PgUp/PgDn` — scroll detail panel (when detail is on)
diff --git
a/dsl/camel-jbang/camel-jbang-plugin-tui/src/test/java/org/apache/camel/dsl/jbang/core/commands/tui/ArchitectureFlowTest.java
b/dsl/camel-jbang/camel-jbang-plugin-tui/src/test/java/org/apache/camel/dsl/jbang/core/commands/tui/ArchitectureFlowTest.java
new file mode 100644
index 000000000000..e4830a2e5e16
--- /dev/null
+++
b/dsl/camel-jbang/camel-jbang-plugin-tui/src/test/java/org/apache/camel/dsl/jbang/core/commands/tui/ArchitectureFlowTest.java
@@ -0,0 +1,186 @@
+/*
+ * 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.dsl.jbang.core.commands.tui;
+
+import java.nio.charset.StandardCharsets;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.util.List;
+import java.util.function.UnaryOperator;
+
+import org.apache.camel.catalog.DefaultCamelCatalog;
+import org.apache.camel.dsl.jbang.core.commands.ai.ProjectCapabilities;
+import
org.apache.camel.dsl.jbang.core.commands.ai.ProjectCapabilities.Capabilities;
+import org.apache.camel.dsl.jbang.core.commands.ai.ProjectOverview;
+import
org.apache.camel.dsl.jbang.core.commands.tui.diagram.FlowAnimation.Reading;
+import org.apache.camel.dsl.jbang.core.commands.tui.diagram.FlowFeed;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.io.TempDir;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+/**
+ * The messages moving between the groups of the architecture: along a link,
the messages into the routes of the group
+ * it goes to, from the routes that send them; into the error handling, the
failures of a group.
+ */
+class ArchitectureFlowTest {
+
+ private static final String ROUTES = """
+ - route:
+ id: order
+ group: shop
+ from:
+ uri: platform-http:/orders
+ steps:
+ - doTry:
+ steps:
+ - to: direct:invoice
+ doCatch:
+ - exception:
+ - java.lang.Exception
+ steps:
+ - to: direct:dlq
+ - route:
+ id: invoice
+ group: billing
+ from:
+ uri: direct:invoice
+ steps:
+ - to: kafka:invoices
+ - route:
+ id: dlq
+ from:
+ uri: direct:dlq
+ steps:
+ - to: kafka:dlq
+ """;
+
+ @TempDir
+ Path project;
+
+ private ProjectOverview.Overview overview;
+ private Capabilities caps;
+
+ @BeforeEach
+ void setUp() throws Exception {
+ Files.writeString(project.resolve("shop.camel.yaml"), ROUTES,
StandardCharsets.UTF_8);
+ overview = ProjectOverview.analyze(project, new DefaultCamelCatalog());
+ caps = ProjectCapabilities.withErrorHandling(overview,
ProjectCapabilities.build(overview, null));
+ }
+
+ @Test
+ void aLinkMovesAtTheMessagesIntoTheGroupItGoesTo() {
+ FlowFeed feed = ArchitectureFlow.feed(overview, caps,
+ List.of(route("order", 100, 0, 0), route("invoice", 90, 4, 0),
route("dlq", 10, 0, 0)),
+ List.of(), UnaryOperator.identity());
+
+ String link = FlowFeed.edgeId(caps.groupOf().get("order"),
caps.groupOf().get("invoice"));
+ assertThat(feed.edges()).containsKey(link);
+ FlowFeed.Edge edge = feed.edges().get(link);
+ assertThat(edge.senders()).as("the routes that send along
it").containsExactly("route/order");
+ Reading reading = feed.readings().get(edge.key());
+ assertThat(reading.total()).as("the messages into
invoice").isEqualTo(90);
+ assertThat(reading.failed()).isEqualTo(4);
+ }
+
+ @Test
+ void theFailuresOfAGroupGoToTheErrorHandlingInRed() {
+ FlowFeed feed = ArchitectureFlow.feed(overview, caps,
+ List.of(route("order", 100, 3, 7), route("invoice", 90, 0, 0),
route("dlq", 10, 0, 0)),
+ List.of(), UnaryOperator.identity());
+
+ String shop = caps.groupOf().get("order");
+ FlowFeed.Edge edge = feed.edges().get(FlowFeed.edgeId(shop,
ProjectCapabilities.ERRORS));
+ assertThat(edge).as("the shop group sends its failures to the error
handling").isNotNull();
+ Reading reading = feed.readings().get(edge.key());
+ assertThat(reading.total()).as("failed and handled").isEqualTo(10);
+ assertThat(reading.failed()).as("all of them failures:
red").isEqualTo(reading.total());
+ }
+
+ @Test
+ void aSourceRouteIsKnownByTheIdItRunsWith() {
+ // a route without an id in the source runs with the id Camel made up
+ FlowFeed feed = ArchitectureFlow.feed(overview, caps,
+ List.of(route("order", 100, 0, 0), route("route2", 90, 0, 0)),
+ List.of(), key -> "invoice".equals(key) ? "route2" : key);
+
+ assertThat(feed.readings()).containsKey("route/invoice");
+ assertThat(feed.readings().get("route/invoice").total()).isEqualTo(90);
+ }
+
+ @Test
+ void noRunningRoutesNoFlow() {
+ assertThat(ArchitectureFlow.feed(overview, caps, List.of(), List.of(),
UnaryOperator.identity())).isNull();
+ assertThat(ArchitectureFlow.feed(overview, caps,
List.of(route("other", 5, 0, 0)), List.of(),
+ UnaryOperator.identity()))
+ .as("another project's routes").isNull();
+ }
+
+ @Test
+ void aSystemMovesAtTheMessagesOfTheRouteItFeedsOrOfTheEndpointSentTo() {
+ // as the running integration writes its endpoints
+ FlowFeed feed = ArchitectureFlow.feed(overview, caps,
+ List.of(route("order", 100, 0, 0), route("invoice", 90, 0, 0),
route("dlq", 10, 0, 0)),
+ // a polling consumer counts no hits: the route has the
messages it got
+ List.of(endpoint("platform-http:///orders", "in", "order", 0),
+ endpoint("kafka://invoices?brokers=x", "out",
"invoice", 42)),
+ UnaryOperator.identity());
+
+ String in = FlowFeed.edgeId(ArchitectureView.systemId("Platform HTTP",
true), caps.groupOf().get("order"));
+ String out = FlowFeed.edgeId(caps.groupOf().get("invoice"),
ArchitectureView.systemId("Kafka", false));
+ assertThat(feed.edges()).containsKeys(in, out);
+
assertThat(feed.readings().get(feed.edges().get(in).key()).total()).as("the
messages of order").isEqualTo(100);
+
assertThat(feed.readings().get(feed.edges().get(out).key()).total()).as("the
hits of kafka:invoices")
+ .isEqualTo(42);
+ }
+
+ @Test
+ void withoutTheCountsOfItsEndpointASystemMovesAtItsRoute() {
+ FlowFeed feed = ArchitectureFlow.feed(overview, caps,
+ List.of(route("order", 100, 0, 0), route("invoice", 90, 0, 0),
route("dlq", 10, 0, 0)),
+ List.of(), UnaryOperator.identity());
+
+ String out = FlowFeed.edgeId(caps.groupOf().get("invoice"),
ArchitectureView.systemId("Kafka", false));
+
assertThat(feed.readings().get(feed.edges().get(out).key()).total()).isEqualTo(90);
+ }
+
+ @Test
+ void anEndpointUriIsKnownWithOrWithoutItsSlashesAndOptions() {
+
assertThat(ArchitectureFlow.endpointKey("file:inbox?delete=true&delay=200"))
+
.isEqualTo(ArchitectureFlow.endpointKey("file://inbox?delay=200&delete=true"));
+
assertThat(ArchitectureFlow.endpointKey("Kafka:orders")).isEqualTo("kafka:orders");
+ }
+
+ private static EndpointInfo endpoint(String uri, String direction, String
routeId, long hits) {
+ EndpointInfo e = new EndpointInfo();
+ e.uri = uri;
+ e.direction = direction;
+ e.routeId = routeId;
+ e.hits = hits;
+ return e;
+ }
+
+ private static RouteInfo route(String id, long total, long failed, long
handled) {
+ RouteInfo r = new RouteInfo();
+ r.routeId = id;
+ r.total = total;
+ r.failed = failed;
+ r.failuresHandled = handled;
+ return r;
+ }
+}
diff --git
a/dsl/camel-jbang/camel-jbang-plugin-tui/src/test/java/org/apache/camel/dsl/jbang/core/commands/tui/diagram/FlowAnimationTest.java
b/dsl/camel-jbang/camel-jbang-plugin-tui/src/test/java/org/apache/camel/dsl/jbang/core/commands/tui/diagram/FlowAnimationTest.java
new file mode 100644
index 000000000000..8ff4a67c8f74
--- /dev/null
+++
b/dsl/camel-jbang/camel-jbang-plugin-tui/src/test/java/org/apache/camel/dsl/jbang/core/commands/tui/diagram/FlowAnimationTest.java
@@ -0,0 +1,178 @@
+/*
+ * 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.dsl.jbang.core.commands.tui.diagram;
+
+import java.util.Map;
+import java.util.concurrent.atomic.AtomicLong;
+
+import org.junit.jupiter.api.Test;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.within;
+
+/**
+ * The messages moving through a route diagram: the rates from the counts the
diagram reloads, the heat of the steps,
+ * the stuck steps, and the frames drawn only while something moves.
+ */
+class FlowAnimationTest {
+
+ private final AtomicLong clock = new AtomicLong(10_000);
+ private final FlowAnimation flow = new FlowAnimation(clock::get);
+
+ @Test
+ void theRateIsTheChangeOfTheCountsBetweenTwoReloads() {
+ flow.update(Map.of("a", stat(100, 0, 0)));
+ assertThat(flow.get("a").rate()).isZero();
+
+ clock.addAndGet(1000);
+ flow.update(Map.of("a", stat(150, 5, 0)));
+
+ assertThat(flow.get("a").rate()).isCloseTo(50, within(0.01));
+ assertThat(flow.get("a").failRate()).isCloseTo(5, within(0.01));
+ }
+
+ @Test
+ void aRateInFitsAndStartsIsSmoothedButStopsAtOnce() {
+ flow.update(Map.of("a", stat(0, 0, 0)));
+ clock.addAndGet(1000);
+ flow.update(Map.of("a", stat(10, 0, 0)));
+ clock.addAndGet(1000);
+ flow.update(Map.of("a", stat(10 + 2, 0, 0)));
+ assertThat(flow.get("a").rate()).as("between the two
readings").isBetween(2.0, 10.0);
+
+ clock.addAndGet(1000);
+ flow.update(Map.of("a", stat(12, 0, 0)));
+ assertThat(flow.get("a").rate()).as("no messages").isZero();
+ }
+
+ @Test
+ void theFramesBetweenTwoReloadsKeepTheRate() {
+ FlowAnimation.Reading first = stat(0, 0, 0);
+ flow.update(Map.of("a", first));
+ clock.addAndGet(1000);
+ FlowAnimation.Reading second = stat(20, 0, 0);
+ flow.update(Map.of("a", second));
+ double phase = flow.get("a").phase();
+
+ clock.addAndGet(FlowAnimation.FRAME_MS);
+ flow.update(Map.of("a", second));
+
+ assertThat(flow.get("a").rate()).isCloseTo(20, within(0.01));
+ assertThat(flow.get("a").phase()).as("the dots moved
on").isGreaterThan(phase);
+ }
+
+ @Test
+ void theSameCountsLaidOutAgainSoonAfterAreNoNewReading() {
+ flow.update(Map.of("a", stat(0, 0, 0)));
+ clock.addAndGet(1000);
+ flow.update(Map.of("a", stat(20, 0, 0)));
+
+ // a zoom lays the diagram out again: new objects, the same counts
+ clock.addAndGet(FlowAnimation.FRAME_MS);
+ flow.update(Map.of("a", stat(20, 0, 0)));
+
+ assertThat(flow.get("a").rate()).as("still moving").isCloseTo(20,
within(0.01));
+ }
+
+ @Test
+ void withNoNewCountsNothingMoves() {
+ FlowAnimation.Reading stat = stat(0, 0, 0);
+ flow.update(Map.of("a", stat));
+ clock.addAndGet(1000);
+ FlowAnimation.Reading busy = stat(30, 0, 0);
+ flow.update(Map.of("a", busy));
+
+ clock.addAndGet(FlowAnimation.STALE_MS + 1);
+ flow.update(Map.of("a", busy));
+
+ assertThat(flow.get("a").rate()).isZero();
+ }
+
+ @Test
+ void nothingMovesWhenTheMessagesStop() {
+ flow.update(Map.of("a", stat(0, 0, 0)));
+ for (int i = 1; i <= 5; i++) {
+ clock.addAndGet(1000);
+ flow.update(Map.of("a", stat(50L * i, 0, 0)));
+ }
+ assertThat(flow.isAnimating()).isTrue();
+
+ // the counts stay the same: no messages
+ clock.addAndGet(1000);
+ flow.update(Map.of("a", stat(250, 0, 0)));
+
+ assertThat(flow.get("a").rate()).isZero();
+ assertThat(flow.isAnimating()).isFalse();
+ }
+
+ @Test
+ void aStepWhereExchangesWaitWithNoneFinishingIsStuck() {
+ flow.update(Map.of("a", stat(10, 0, 0)));
+ clock.addAndGet(1000);
+ flow.update(Map.of("a", stat(10, 0, 3)));
+ FlowAnimation.Track t = flow.get("a");
+ assertThat(flow.stuckMillis(t)).as("not yet: waiting a second can be a
slow call").isEqualTo(-1);
+
+ clock.addAndGet(1000);
+ flow.update(Map.of("a", stat(10, 0, 4)));
+ clock.addAndGet(1000);
+ flow.update(Map.of("a", stat(10, 0, 4)));
+
+
assertThat(flow.stuckMillis(t)).isGreaterThanOrEqualTo(FlowAnimation.STUCK_MS);
+ assertThat(t.inflight()).isEqualTo(4);
+ assertThat(flow.isAnimating()).as("the spinner turns").isTrue();
+
+ // one finishes: no longer stuck
+ clock.addAndGet(1000);
+ flow.update(Map.of("a", stat(11, 0, 3)));
+ assertThat(flow.stuckMillis(t)).isEqualTo(-1);
+ }
+
+ @Test
+ void aFrameIsDueOnlyWhileSomethingMoves() {
+ FlowAnimation.Reading quiet = stat(5, 0, 0);
+ flow.update(Map.of("a", quiet));
+ clock.addAndGet(1000);
+ flow.update(Map.of("a", stat(5, 0, 0)));
+ clock.addAndGet(FlowAnimation.FRAME_MS);
+ assertThat(flow.frameDue()).as("no messages: nothing moves").isFalse();
+
+ clock.addAndGet(1000);
+ flow.update(Map.of("a", stat(25, 0, 0)));
+ assertThat(flow.frameDue()).as("just drawn").isFalse();
+ clock.addAndGet(FlowAnimation.FRAME_MS);
+ assertThat(flow.frameDue()).isTrue();
+
+ flow.setEnabled(false);
+ assertThat(flow.frameDue()).as("turned off").isFalse();
+ assertThat(flow.get("a")).isNull();
+ }
+
+ @Test
+ void theDotsAreCloserTogetherTheMoreMessagesThereAre() {
+
assertThat(FlowAnimation.spacing(1)).isGreaterThan(FlowAnimation.spacing(100));
+ assertThat(FlowAnimation.spacing(0.1)).isLessThanOrEqualTo(14);
+ assertThat(FlowAnimation.spacing(1_000_000)).isEqualTo(4);
+
assertThat(FlowAnimation.speed(100)).isGreaterThan(FlowAnimation.speed(1));
+ assertThat(FlowAnimation.speed(0)).isZero();
+ }
+
+ /** The counts of a reload: a new object each time, as a reload brings. */
+ private static FlowAnimation.Reading stat(long total, long failed, long
inflight) {
+ return new FlowAnimation.Reading(new Object(), total, failed,
inflight);
+ }
+}
diff --git
a/dsl/camel-jbang/camel-jbang-plugin-tui/src/test/java/org/apache/camel/dsl/jbang/core/commands/tui/diagram/FlowDotsTest.java
b/dsl/camel-jbang/camel-jbang-plugin-tui/src/test/java/org/apache/camel/dsl/jbang/core/commands/tui/diagram/FlowDotsTest.java
new file mode 100644
index 000000000000..80611dffa81c
--- /dev/null
+++
b/dsl/camel-jbang/camel-jbang-plugin-tui/src/test/java/org/apache/camel/dsl/jbang/core/commands/tui/diagram/FlowDotsTest.java
@@ -0,0 +1,322 @@
+/*
+ * 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.dsl.jbang.core.commands.tui.diagram;
+
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+import java.util.concurrent.atomic.AtomicLong;
+
+import dev.tamboui.buffer.Buffer;
+import dev.tamboui.buffer.Cell;
+import dev.tamboui.layout.Rect;
+import dev.tamboui.style.Color;
+import org.apache.camel.diagram.RouteDiagramLayoutEngine;
+import org.apache.camel.diagram.RouteDiagramLayoutEngine.LayoutRoute;
+import org.apache.camel.diagram.RouteDiagramLayoutEngine.NodeInfo;
+import org.apache.camel.diagram.RouteDiagramLayoutEngine.RouteInfo;
+import org.apache.camel.diagram.RouteDiagramLayoutEngine.StatInfo;
+import org.apache.camel.dsl.jbang.core.commands.tui.Theme;
+import org.junit.jupiter.api.Test;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+/**
+ * The live flow in the route diagram: dots on the arrows the messages go
along, the stuck step marked in its border,
+ * and none of it with the flow off or the metrics off.
+ */
+class FlowDotsTest {
+
+ private final AtomicLong clock = new AtomicLong(50_000);
+ private final FlowAnimation flow = new FlowAnimation(clock::get);
+ private final RouteDiagramLayoutEngine engine = new
RouteDiagramLayoutEngine();
+
+ @Test
+ void dotsMoveOnTheArrowsTheMessagesGoAlong() {
+ int dots = 0;
+ boolean moved = false;
+ String before = null;
+ for (int reload = 0; reload < 3; reload++) {
+ LayoutRoute layout = layout(reload * 40L, 0, 0);
+ for (int frame = 0; frame < 12; frame++) {
+ Buffer buffer = render(layout, true);
+ String screen = screen(buffer);
+ dots += count(screen, '●');
+ if (before != null && reload > 0 && !screen.equals(before)) {
+ moved = true;
+ }
+ before = screen;
+ clock.addAndGet(FlowAnimation.FRAME_MS);
+ }
+ clock.addAndGet(1000 - 12 * FlowAnimation.FRAME_MS);
+ }
+ assertThat(dots).isPositive();
+ assertThat(moved).as("the dots move from frame to frame").isTrue();
+ assertThat(flow.isAnimating()).isTrue();
+ }
+
+ @Test
+ void theBusyBoxesKeepTheirFrameAndColour() {
+ Buffer idle = render(layout(0, 0, 0), false);
+ Color colour = borderColor(idle);
+
+ Buffer busy = null;
+ for (int reload = 0; reload < 4; reload++) {
+ LayoutRoute layout = layout(reload * 100L, 0, 0);
+ for (int frame = 0; frame < 12; frame++) {
+ busy = render(layout, true);
+ clock.addAndGet(FlowAnimation.FRAME_MS);
+ }
+ clock.addAndGet(1000 - 12 * FlowAnimation.FRAME_MS);
+ }
+
+ assertThat(corner(busy)).isEqualTo(corner(idle)).isEqualTo("┌");
+ assertThat(borderColor(busy)).as("the colour of its
kind").isEqualTo(colour);
+ }
+
+ @Test
+ void bareLightsUpTheLinesBetweenTheSteps() {
+ int lit = 0;
+ for (int reload = 0; reload < 3; reload++) {
+ LayoutRoute layout = layout(reload * 40L, 0, 0);
+ RouteDensity.BARE.apply(layout);
+ for (int frame = 0; frame < 12; frame++) {
+ Buffer buffer = render(layout, true, RouteDensity.BARE);
+ assertThat(screen(buffer)).as("no dot: it would look like the
mark of a step").doesNotContain("•");
+ lit += litLines(buffer);
+ clock.addAndGet(FlowAnimation.FRAME_MS);
+ }
+ clock.addAndGet(1000 - 12 * FlowAnimation.FRAME_MS);
+ }
+ assertThat(lit).isPositive();
+ }
+
+ /** The cells of the lines in the colour of the foreground, not the muted
colour of a line. */
+ private static int litLines(Buffer buffer) {
+ int lit = 0;
+ for (int y = 0; y < buffer.height(); y++) {
+ for (int x = 0; x < buffer.width(); x++) {
+ Cell cell = buffer.get(x, y);
+ if ("│".equals(cell.symbol()) &&
cell.style().fg().filter(Theme.baseFg()::equals).isPresent()) {
+ lit++;
+ }
+ }
+ }
+ return lit;
+ }
+
+ @Test
+ void theOverviewHasALightPassingOverTheSteps() {
+ LayoutRoute quiet = layout(0, 0, 0);
+ RouteDensity.OVERVIEW.apply(quiet);
+ Color colour = markColor(render(quiet, false, RouteDensity.OVERVIEW));
+
+ Set<Color> colours = new HashSet<>();
+ for (int reload = 0; reload < 3; reload++) {
+ LayoutRoute layout = layout(reload * 40L, 0, 0);
+ RouteDensity.OVERVIEW.apply(layout);
+ for (int frame = 0; frame < 12; frame++) {
+ colours.add(markColor(render(layout, true,
RouteDensity.OVERVIEW)));
+ clock.addAndGet(FlowAnimation.FRAME_MS);
+ }
+ clock.addAndGet(1000 - 12 * FlowAnimation.FRAME_MS);
+ }
+ assertThat(colours).as("lit up as the light passes, and
back").contains(colour).hasSizeGreaterThan(1);
+ }
+
+ /** The colour of the mark of the last step in the overview. */
+ private static Color markColor(Buffer buffer) {
+ for (int y = buffer.height() - 1; y >= 0; y--) {
+ int x = row(buffer, y).indexOf('■');
+ if (x >= 0) {
+ return buffer.get(x, y).style().fg().orElse(Color.RESET);
+ }
+ }
+ throw new AssertionError("no step");
+ }
+
+ @Test
+ void aStuckStepHasASpinnerInItsBorder() {
+ render(layout(10, 0, 0), true);
+ for (int reload = 1; reload <= 3; reload++) {
+ clock.addAndGet(1000);
+ render(layout(10, 0, 2), true);
+ }
+ String screen = screen(render(layout(10, 0, 2), true));
+
+ assertThat(screen).contains("2 inflight · 3s");
+ }
+
+ @Test
+ void aStuckStepSaysWhenItLastFinishedAnExchange() {
+ render(layout(10, 0, 0), true);
+ for (int reload = 1; reload <= 3; reload++) {
+ clock.addAndGet(1000);
+ LayoutRoute layout = layout(10, 0, 2);
+ lastStep(layout).lastCompletedExchangeTimestamp =
System.currentTimeMillis() - 5 * 60_000;
+ render(layout, true);
+ }
+ LayoutRoute layout = layout(10, 0, 2);
+ lastStep(layout).lastCompletedExchangeTimestamp =
System.currentTimeMillis() - 5 * 60_000;
+
+ assertThat(screen(render(layout, true))).contains("2 inflight · 5m");
+ }
+
+ @Test
+ void aStuckStepThatNeverFinishedOneSaysSo() {
+ render(layout(0, 0, 0), true);
+ for (int reload = 1; reload <= 3; reload++) {
+ clock.addAndGet(1000);
+ render(layout(0, 0, 4), true);
+ }
+
+ assertThat(screen(render(layout(0, 0, 4), true))).contains("4 · none
done");
+ }
+
+ private static StatInfo lastStep(LayoutRoute layout) {
+ return layout.nodes.stream().filter(n ->
"to1".equals(n.id)).findFirst().orElseThrow().treeNode.info.stat;
+ }
+
+ @Test
+ void offThereAreNoDots() {
+ flow.setEnabled(false);
+ for (int reload = 0; reload < 3; reload++) {
+ LayoutRoute layout = layout(reload * 40L, 0, 0);
+ for (int frame = 0; frame < 12; frame++) {
+ assertThat(screen(render(layout, true))).doesNotContain("●");
+ clock.addAndGet(FlowAnimation.FRAME_MS);
+ }
+ clock.addAndGet(1000 - 12 * FlowAnimation.FRAME_MS);
+ }
+ assertThat(flow.isAnimating()).isFalse();
+ }
+
+ @Test
+ void withoutTheMetricsThereIsNoFlow() {
+ for (int reload = 0; reload < 3; reload++) {
+ LayoutRoute layout = layout(reload * 40L, 0, 0);
+ RouteDiagramWidget widget = new RouteDiagramWidget(layout,
engine.getNodeWidth(), -1, 0, 0, false, Map.of())
+ .withFlow(flow);
+ Rect area = new Rect(0, 0, 120, 60);
+ Buffer buffer = Buffer.empty(area);
+ widget.render(area, buffer);
+ assertThat(screen(buffer)).doesNotContain("●");
+ clock.addAndGet(1000);
+ }
+ assertThat(flow.isAnimating()).isFalse();
+ }
+
+ private Buffer render(LayoutRoute layout, boolean withFlow) {
+ return render(layout, withFlow, RouteDensity.DETAILED);
+ }
+
+ private Buffer render(LayoutRoute layout, boolean withFlow, RouteDensity
density) {
+ RouteDiagramWidget widget = new RouteDiagramWidget(layout,
engine.getNodeWidth(), -1, 0, 0, true, Map.of())
+ .withDensity(density).withFlow(withFlow ? flow : null);
+ Rect area = new Rect(0, 0, 120, 60);
+ Buffer buffer = Buffer.empty(area);
+ widget.render(area, buffer);
+ return buffer;
+ }
+
+ /** A route of a few steps in a row, each reached by the same messages;
the last step has the inflight. */
+ private LayoutRoute layout(long total, long failed, long inflight) {
+ RouteInfo route = new RouteInfo();
+ route.routeId = "orders";
+ NodeInfo r = node("route", "orders", 0, 0, 0, 0);
+ r.code = "route[orders]";
+ route.nodes.add(r);
+ route.nodes.add(node("from", "from1", 0, total, 0, 0));
+ route.nodes.add(node("unmarshal", "unmarshal1", 1, total, 0, 0));
+ route.nodes.add(node("bean", "bean1", 1, total, 0, 0));
+ route.nodes.add(node("to", "to1", 1, total, failed, inflight));
+ return engine.layoutRoute(route, 0);
+ }
+
+ private static NodeInfo node(String type, String id, int level, long
total, long failed, long inflight) {
+ NodeInfo n = new NodeInfo();
+ n.type = type;
+ n.id = id;
+ n.code = type;
+ n.level = level;
+ n.stat = new StatInfo();
+ n.stat.exchangesTotal = total;
+ n.stat.exchangesFailed = failed;
+ n.stat.exchangesInflight = inflight;
+ return n;
+ }
+
+ /** The colour of the top left corner of the box of the unmarshal step. */
+ private static Color borderColor(Buffer buffer) {
+ int[] at = cornerOf(buffer);
+ return buffer.get(at[0], at[1]).style().fg().orElse(Color.RESET);
+ }
+
+ /** The top left corner of the box of the unmarshal step. */
+ private static String corner(Buffer buffer) {
+ int[] at = cornerOf(buffer);
+ return buffer.get(at[0], at[1]).symbol();
+ }
+
+ private static int[] cornerOf(Buffer buffer) {
+ for (int y = 0; y < buffer.height(); y++) {
+ String row = row(buffer, y);
+ int x = row.indexOf("unmarshal");
+ if (x >= 0) {
+ int left = Math.max(row.lastIndexOf('│', x),
row.lastIndexOf('┃', x));
+ return new int[] { left, y - 1 };
+ }
+ }
+ throw new AssertionError("no unmarshal box");
+ }
+
+ private static String screen(Buffer buffer) {
+ StringBuilder sb = new StringBuilder();
+ for (int y = 0; y < buffer.height(); y++) {
+ sb.append(row(buffer, y)).append('\n');
+ }
+ return sb.toString();
+ }
+
+ private static String row(Buffer buffer, int y) {
+ StringBuilder sb = new StringBuilder();
+ for (int x = 0; x < buffer.width(); x++) {
+ sb.append(buffer.get(x, y).symbol());
+ }
+ return sb.toString();
+ }
+
+ private static int count(String s, char c) {
+ return (int) s.chars().filter(ch -> ch == c).count();
+ }
+
+ @Test
+ void mixBlendsAnsiAndIndexedColoursThroughTheirRgb() {
+ // black (0,0,0) to white (255,255,255) half way; the ANSI and indexed
colours have an RGB too
+ Color mid = FlowDots.mix(Color.rgb(0, 0, 0), Color.rgb(255, 255, 255),
0.5);
+ assertThat(mid).isEqualTo(Color.rgb(128, 128, 128));
+ assertThat(FlowDots.mix(Color.RED, Color.indexed(16),
0.5)).isInstanceOf(Color.Rgb.class);
+ }
+
+ @Test
+ void mixDoesNotBlendTheDefaultOfTheTerminal() {
+ // Color.RESET gives white as its RGB: mixing with it would light up
every dot on a dark terminal
+ assertThat(FlowDots.mix(Color.RESET, Color.RED,
0.35)).isEqualTo(Color.RESET);
+ assertThat(FlowDots.mix(Color.RESET, Color.RED,
0.7)).isEqualTo(Color.RED);
+ assertThat(FlowDots.mix(Color.RED, new Color.Named("fg", Color.RESET),
0.35)).isEqualTo(Color.RED);
+ }
+}
diff --git
a/dsl/camel-jbang/camel-jbang-plugin-tui/src/test/java/org/apache/camel/dsl/jbang/core/commands/tui/diagram/TopologyFlowTest.java
b/dsl/camel-jbang/camel-jbang-plugin-tui/src/test/java/org/apache/camel/dsl/jbang/core/commands/tui/diagram/TopologyFlowTest.java
new file mode 100644
index 000000000000..5e2c41782514
--- /dev/null
+++
b/dsl/camel-jbang/camel-jbang-plugin-tui/src/test/java/org/apache/camel/dsl/jbang/core/commands/tui/diagram/TopologyFlowTest.java
@@ -0,0 +1,208 @@
+/*
+ * 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.dsl.jbang.core.commands.tui.diagram;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.atomic.AtomicLong;
+
+import dev.tamboui.buffer.Buffer;
+import dev.tamboui.buffer.Cell;
+import dev.tamboui.layout.Rect;
+import org.apache.camel.diagram.TopologyLayoutEngine;
+import org.apache.camel.diagram.TopologyLayoutEngine.TopologyEdgeInfo;
+import org.apache.camel.diagram.TopologyLayoutEngine.TopologyLayoutResult;
+import org.apache.camel.diagram.TopologyLayoutEngine.TopologyNodeInfo;
+import org.apache.camel.dsl.jbang.core.commands.tui.Theme;
+import org.junit.jupiter.api.Test;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+/**
+ * The live flow in the topology: dots on the edges into the routes that get
messages, from the routes that send them,
+ * and none from a route that sends none.
+ */
+class TopologyFlowTest {
+
+ private final AtomicLong clock = new AtomicLong(50_000);
+ private final FlowAnimation flow = new FlowAnimation(clock::get);
+ private final TopologyLayoutEngine engine = new TopologyLayoutEngine();
+
+ @Test
+ void theEdgeFromABusyRouteHasDots() {
+ int dots = 0;
+ for (int reload = 0; reload < 3; reload++) {
+ TopologyLayoutResult layout = layout(reload * 40L, 0, reload *
40L);
+ for (int frame = 0; frame < 12; frame++) {
+ dots += count(render(layout, RouteDensity.DETAILED), '●');
+ clock.addAndGet(FlowAnimation.FRAME_MS);
+ }
+ clock.addAndGet(1000 - 12 * FlowAnimation.FRAME_MS);
+ }
+ assertThat(dots).isPositive();
+ assertThat(flow.isAnimating()).isTrue();
+ }
+
+ @Test
+ void theEdgeFromARouteThatSendsNothingHasNone() {
+ // b gets its messages from somewhere else: the caller is idle
+ for (int reload = 0; reload < 3; reload++) {
+ TopologyLayoutResult layout = layout(0, 0, reload * 40L);
+ for (int frame = 0; frame < 12; frame++) {
+ assertThat(render(layout,
RouteDensity.DETAILED)).doesNotContain("●");
+ clock.addAndGet(FlowAnimation.FRAME_MS);
+ }
+ clock.addAndGet(1000 - 12 * FlowAnimation.FRAME_MS);
+ }
+ }
+
+ @Test
+ void bareLightsUpTheLines() {
+ int lit = 0;
+ for (int reload = 0; reload < 3; reload++) {
+ TopologyLayoutResult layout = layout(reload * 40L, 0, reload *
40L);
+ TopologyLayoutResult bare = TopologyZoom.apply(RouteDensity.BARE,
layout, null).layout();
+ for (int frame = 0; frame < 12; frame++) {
+ Buffer buffer = buffer(bare, RouteDensity.BARE);
+ assertThat(screen(buffer)).as("no dot: it would look like the
mark of a route").doesNotContain("•");
+ lit += litLines(buffer);
+ clock.addAndGet(FlowAnimation.FRAME_MS);
+ }
+ clock.addAndGet(1000 - 12 * FlowAnimation.FRAME_MS);
+ }
+ assertThat(lit).isPositive();
+ }
+
+ @Test
+ void withoutTheMetricsThereIsNoFlow() {
+ for (int reload = 0; reload < 3; reload++) {
+ TopologyLayoutResult layout = layout(reload * 40L, 0, reload *
40L);
+ TopologyDiagramWidget widget
+ = new TopologyDiagramWidget(layout, engine.getNodeWidth(),
-1, 0, 0, false, false).withFlow(flow);
+ Rect area = new Rect(0, 0, 120, 40);
+ Buffer buffer = Buffer.empty(area);
+ widget.render(area, buffer);
+ assertThat(screen(buffer)).doesNotContain("●");
+ clock.addAndGet(1000);
+ }
+ assertThat(flow.isAnimating()).isFalse();
+ }
+
+ @Test
+ void aFeedMovesTheEdgesOfBoxesThatAreNotRoutes() {
+ // the architecture: boxes of groups, no metrics of their own, the
counts from a feed
+ TopologyLayoutResult layout = layout(0, 0, 0);
+ FlowAnimation idleFlow = new FlowAnimation(clock::get);
+ int moving = 0;
+ int idle = 0;
+ for (int reload = 0; reload < 3; reload++) {
+ Object source = new Object();
+ for (int frame = 0; frame < 12; frame++) {
+ moving += count(screen(feedBuffer(flow, layout, feed(source,
reload * 40L, reload * 40L))), '●');
+ idle += count(screen(feedBuffer(idleFlow, layout, feed(source,
reload * 40L, 0))), '●');
+ clock.addAndGet(FlowAnimation.FRAME_MS);
+ }
+ clock.addAndGet(1000 - 12 * FlowAnimation.FRAME_MS);
+ }
+ assertThat(moving).isPositive();
+ assertThat(idle).as("its sender sends nothing").isZero();
+ }
+
+ /** The link a > b moves at the messages into b, sent by the route of a. */
+ private static FlowFeed feed(Object source, long intoB, long sentByA) {
+ return new FlowFeed(
+ Map.of("link/b", new FlowAnimation.Reading(source, intoB, 0,
0),
+ "route/a", new FlowAnimation.Reading(source, sentByA,
0, 0)),
+ Map.of(FlowFeed.edgeId("a", "b"), new FlowFeed.Edge("link/b",
List.of("route/a"))));
+ }
+
+ private Buffer feedBuffer(FlowAnimation flow, TopologyLayoutResult layout,
FlowFeed feed) {
+ TopologyDiagramWidget widget = new TopologyDiagramWidget(layout,
engine.getNodeWidth(), -1, 0, 0, false, false)
+ .withFlow(flow, feed);
+ Rect area = new Rect(0, 0, 120, 40);
+ Buffer buffer = Buffer.empty(area);
+ widget.render(area, buffer);
+ return buffer;
+ }
+
+ /** Route a calls b; a reload lays it out anew, with new nodes. */
+ private TopologyLayoutResult layout(long totalA, long failedA, long
totalB) {
+ List<TopologyNodeInfo> nodes = new ArrayList<>();
+ nodes.add(node("a", "timer:a", totalA, failedA));
+ nodes.add(node("b", "direct:b", totalB, 0));
+ TopologyEdgeInfo edge = new TopologyEdgeInfo();
+ edge.fromRouteId = "a";
+ edge.toRouteId = "b";
+ edge.endpoint = "direct:b";
+ edge.connectionType = "internal";
+ return engine.layout(nodes, List.of(edge));
+ }
+
+ private static TopologyNodeInfo node(String id, String from, long total,
long failed) {
+ TopologyNodeInfo n = new TopologyNodeInfo();
+ n.routeId = id;
+ n.from = from;
+ n.fromScheme = from.substring(0, from.indexOf(':'));
+ n.nodeType = "route";
+ n.exchangesTotal = total;
+ n.exchangesFailed = failed;
+ return n;
+ }
+
+ private String render(TopologyLayoutResult layout, RouteDensity density) {
+ return screen(buffer(layout, density));
+ }
+
+ private Buffer buffer(TopologyLayoutResult layout, RouteDensity density) {
+ TopologyDiagramWidget widget = new TopologyDiagramWidget(layout,
engine.getNodeWidth(), -1, 0, 0, true, false)
+ .withDensity(density).withFlow(flow);
+ Rect area = new Rect(0, 0, 120, 40);
+ Buffer buffer = Buffer.empty(area);
+ widget.render(area, buffer);
+ return buffer;
+ }
+
+ /** The cells of the lines in the colour of the foreground, not the colour
of a line. */
+ private static int litLines(Buffer buffer) {
+ int lit = 0;
+ for (int y = 0; y < buffer.height(); y++) {
+ for (int x = 0; x < buffer.width(); x++) {
+ Cell cell = buffer.get(x, y);
+ if ("│▼".contains(cell.symbol()) &&
cell.style().fg().filter(Theme.baseFg()::equals).isPresent()) {
+ lit++;
+ }
+ }
+ }
+ return lit;
+ }
+
+ private static String screen(Buffer buffer) {
+ StringBuilder sb = new StringBuilder();
+ for (int y = 0; y < buffer.height(); y++) {
+ for (int x = 0; x < buffer.width(); x++) {
+ sb.append(buffer.get(x, y).symbol());
+ }
+ sb.append('\n');
+ }
+ return sb.toString();
+ }
+
+ private static int count(String s, char c) {
+ return (int) s.chars().filter(ch -> ch == c).count();
+ }
+}