You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by da...@apache.org on 2022/08/21 17:05:05 UTC
[camel] branch main updated: CAMEL-18408: camel-console for inflight.
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 c7d5b228a77 CAMEL-18408: camel-console for inflight.
c7d5b228a77 is described below
commit c7d5b228a77a3e8801e5a5943b7c25b953fbd5eb
Author: Claus Ibsen <cl...@gmail.com>
AuthorDate: Sun Aug 21 19:04:49 2022 +0200
CAMEL-18408: camel-console for inflight.
---
.../services/org/apache/camel/dev-console/inflight | 2 +
.../apache/camel/impl/console/InflightConsole.java | 75 ++++++++++++++++++++++
2 files changed, 77 insertions(+)
diff --git a/core/camel-console/src/generated/resources/META-INF/services/org/apache/camel/dev-console/inflight b/core/camel-console/src/generated/resources/META-INF/services/org/apache/camel/dev-console/inflight
new file mode 100644
index 00000000000..570b274b369
--- /dev/null
+++ b/core/camel-console/src/generated/resources/META-INF/services/org/apache/camel/dev-console/inflight
@@ -0,0 +1,2 @@
+# Generated by camel build tools - do NOT edit this file!
+class=org.apache.camel.impl.console.InflightConsole
diff --git a/core/camel-console/src/main/java/org/apache/camel/impl/console/InflightConsole.java b/core/camel-console/src/main/java/org/apache/camel/impl/console/InflightConsole.java
new file mode 100644
index 00000000000..b0c14696f77
--- /dev/null
+++ b/core/camel-console/src/main/java/org/apache/camel/impl/console/InflightConsole.java
@@ -0,0 +1,75 @@
+/*
+ * 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.impl.console;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.camel.spi.InflightRepository;
+import org.apache.camel.spi.annotations.DevConsole;
+import org.apache.camel.util.TimeUtils;
+import org.apache.camel.util.json.JsonObject;
+
+@DevConsole("inflight")
+public class InflightConsole extends AbstractDevConsole {
+
+ public InflightConsole() {
+ super("camel", "inflight", "Inflight Exchanges", "Display inflight exchanges");
+ }
+
+ @Override
+ protected String doCallText(Map<String, Object> options) {
+ StringBuilder sb = new StringBuilder();
+
+ InflightRepository repo = getCamelContext().getInflightRepository();
+ sb.append(String.format("\n Inflight: %s", repo.size()));
+ if (repo.isInflightBrowseEnabled()) {
+ for (InflightRepository.InflightExchange ie : repo.browse()) {
+ String age = TimeUtils.printDuration(ie.getDuration(), true);
+ sb.append(String.format("\n %s (from: %s at: %s/%s age: %s)",
+ ie.getExchange().getExchangeId(), ie.getFromRouteId(), ie.getAtRouteId(), ie.getNodeId(), age));
+ }
+ }
+
+ return sb.toString();
+ }
+
+ @Override
+ protected JsonObject doCallJson(Map<String, Object> options) {
+ JsonObject root = new JsonObject();
+
+ InflightRepository repo = getCamelContext().getInflightRepository();
+ root.put("inflight", repo.size());
+ if (repo.isInflightBrowseEnabled()) {
+ final List<JsonObject> list = new ArrayList<>();
+ for (InflightRepository.InflightExchange ie : repo.browse()) {
+ JsonObject props = new JsonObject();
+ props.put("exchangeId", ie.getExchange().getExchangeId());
+ props.put("fromRouteId", ie.getFromRouteId());
+ props.put("atRouteId", ie.getAtRouteId());
+ props.put("nodeId", ie.getNodeId());
+ props.put("elapsed", ie.getElapsed());
+ props.put("duration", ie.getDuration());
+ list.add(props);
+ }
+ root.put("exchanges", list);
+ }
+
+ return root;
+ }
+}