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/20 19:55:35 UTC

[camel] branch main updated: CAMEL-18408: camel-console for endpoints.

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 fb40857b24b CAMEL-18408: camel-console for endpoints.
fb40857b24b is described below

commit fb40857b24bdf3f9a82140d82af3e119e29362ea
Author: Claus Ibsen <cl...@gmail.com>
AuthorDate: Sat Aug 20 21:55:23 2022 +0200

    CAMEL-18408: camel-console for endpoints.
---
 .../org/apache/camel/dev-console/endpoints         |  2 +
 .../camel/impl/console/EndpointsDevConsole.java    | 77 ++++++++++++++++++++++
 2 files changed, 79 insertions(+)

diff --git a/core/camel-console/src/generated/resources/META-INF/services/org/apache/camel/dev-console/endpoints b/core/camel-console/src/generated/resources/META-INF/services/org/apache/camel/dev-console/endpoints
new file mode 100644
index 00000000000..40c569b1839
--- /dev/null
+++ b/core/camel-console/src/generated/resources/META-INF/services/org/apache/camel/dev-console/endpoints
@@ -0,0 +1,2 @@
+# Generated by camel build tools - do NOT edit this file!
+class=org.apache.camel.impl.console.EndpointsDevConsole
diff --git a/core/camel-console/src/main/java/org/apache/camel/impl/console/EndpointsDevConsole.java b/core/camel-console/src/main/java/org/apache/camel/impl/console/EndpointsDevConsole.java
new file mode 100644
index 00000000000..95b306ae50f
--- /dev/null
+++ b/core/camel-console/src/main/java/org/apache/camel/impl/console/EndpointsDevConsole.java
@@ -0,0 +1,77 @@
+/*
+ * 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.Collection;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.camel.Endpoint;
+import org.apache.camel.spi.EndpointRegistry;
+import org.apache.camel.spi.annotations.DevConsole;
+import org.apache.camel.util.json.JsonObject;
+
+@DevConsole("endpoints")
+public class EndpointsDevConsole extends AbstractDevConsole {
+
+    public EndpointsDevConsole() {
+        super("camel", "endpoints", "Endpoints", "Endpoint Registry information");
+    }
+
+    @Override
+    protected String doCallText(Map<String, Object> options) {
+        StringBuilder sb = new StringBuilder();
+
+        EndpointRegistry reg = getCamelContext().getEndpointRegistry();
+        sb.append(
+                String.format("\n    Endpoints: %s (static: %s dynamic: %s", reg.size(), reg.staticSize(), reg.dynamicSize()));
+        sb.append(String.format("\n    Maximum Cache Size: %s", reg.getMaximumCacheSize()));
+        Collection<Endpoint> col = reg.getReadOnlyValues();
+        if (!col.isEmpty()) {
+            sb.append("\n");
+            for (Endpoint e : col) {
+                sb.append(String.format("\n    %s", e.toString()));
+            }
+        }
+        sb.append("\n");
+
+        return sb.toString();
+    }
+
+    @Override
+    protected JsonObject doCallJson(Map<String, Object> options) {
+        JsonObject root = new JsonObject();
+
+        EndpointRegistry reg = getCamelContext().getEndpointRegistry();
+        root.put("size", reg.size());
+        root.put("staticSize", reg.staticSize());
+        root.put("dynamicSize", reg.dynamicSize());
+        root.put("maximumCacheSize", reg.getMaximumCacheSize());
+
+        final List<JsonObject> list = new ArrayList<>();
+        root.put("endpoints", list);
+        Collection<Endpoint> col = reg.getReadOnlyValues();
+        for (Endpoint e : col) {
+            JsonObject uri = new JsonObject();
+            uri.put("uri", e.toString());
+            list.add(uri);
+        }
+
+        return root;
+    }
+}