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 2021/12/30 12:04:35 UTC

[camel] 19/30: CAMEL-17384: Developer Console SPI

This is an automated email from the ASF dual-hosted git repository.

davsclaus pushed a commit to branch console
in repository https://gitbox.apache.org/repos/asf/camel.git

commit 50208355abf4399f2a5f25378b4d200e664c46f7
Author: Claus Ibsen <cl...@gmail.com>
AuthorDate: Wed Dec 29 11:56:05 2021 +0100

    CAMEL-17384: Developer Console SPI
---
 .../main/java/org/apache/camel/console/DevConsole.java   | 10 ++++++++++
 .../apache/camel/impl/console/AbstractDevConsole.java    | 16 +++++++++++++++-
 .../org/apache/camel/impl/console/ContextDevConsole.java |  4 +++-
 .../java/org/apache/camel/impl/console/EventConsole.java |  7 +++----
 .../main/java/org/apache/camel/main/VertxHttpServer.java |  3 +++
 5 files changed, 34 insertions(+), 6 deletions(-)

diff --git a/core/camel-api/src/main/java/org/apache/camel/console/DevConsole.java b/core/camel-api/src/main/java/org/apache/camel/console/DevConsole.java
index f5dd0e9..518fbb2 100644
--- a/core/camel-api/src/main/java/org/apache/camel/console/DevConsole.java
+++ b/core/camel-api/src/main/java/org/apache/camel/console/DevConsole.java
@@ -43,6 +43,16 @@ public interface DevConsole {
     String getId();
 
     /**
+     * Display name of this console.
+     */
+    String getDisplayName();
+
+    /**
+     * Short description of this console.
+     */
+    String getDescription();
+
+    /**
      * Whether this console supports the given media type.
      *
      * @param  mediaType the media type
diff --git a/core/camel-console/src/main/java/org/apache/camel/impl/console/AbstractDevConsole.java b/core/camel-console/src/main/java/org/apache/camel/impl/console/AbstractDevConsole.java
index c1d5c06..5ead0ac 100644
--- a/core/camel-console/src/main/java/org/apache/camel/impl/console/AbstractDevConsole.java
+++ b/core/camel-console/src/main/java/org/apache/camel/impl/console/AbstractDevConsole.java
@@ -32,11 +32,15 @@ public abstract class AbstractDevConsole extends ServiceSupport implements DevCo
     private final Object lock;
     private final String group;
     private final String id;
+    private final String displayName;
+    private final String description;
 
-    public AbstractDevConsole(String group, String id) {
+    public AbstractDevConsole(String group, String id, String displayName, String description) {
         this.lock = new Object();
         this.group = group;
         this.id = id;
+        this.displayName = displayName;
+        this.description = description;
     }
 
     @Override
@@ -65,6 +69,16 @@ public abstract class AbstractDevConsole extends ServiceSupport implements DevCo
     }
 
     @Override
+    public String getDisplayName() {
+        return displayName;
+    }
+
+    @Override
+    public String getDescription() {
+        return description;
+    }
+
+    @Override
     public boolean equals(Object o) {
         if (this == o) {
             return true;
diff --git a/core/camel-console/src/main/java/org/apache/camel/impl/console/ContextDevConsole.java b/core/camel-console/src/main/java/org/apache/camel/impl/console/ContextDevConsole.java
index b8ec2a6..059d36c 100644
--- a/core/camel-console/src/main/java/org/apache/camel/impl/console/ContextDevConsole.java
+++ b/core/camel-console/src/main/java/org/apache/camel/impl/console/ContextDevConsole.java
@@ -26,7 +26,7 @@ import org.apache.camel.spi.annotations.DevConsole;
 public class ContextDevConsole extends AbstractDevConsole {
 
     public ContextDevConsole() {
-        super("camel", "context");
+        super("camel", "context", "CamelContext", "Overall information about the CamelContext");
     }
 
     @Override
@@ -37,6 +37,8 @@ public class ContextDevConsole extends AbstractDevConsole {
         sb.append(String.format("Apache Camel %s (%s) uptime %s", getCamelContext().getVersion(), getCamelContext().getName(),
                 getCamelContext().getUptime()));
         sb.append("\n");
+
+        // TODO: number of messages should maybe be in another console
         ManagedCamelContext mcc = getCamelContext().getExtension(ManagedCamelContext.class);
         if (mcc != null) {
             ManagedCamelContextMBean mb = mcc.getManagedCamelContext();
diff --git a/core/camel-console/src/main/java/org/apache/camel/impl/console/EventConsole.java b/core/camel-console/src/main/java/org/apache/camel/impl/console/EventConsole.java
index 68ab032..ed09bcc 100644
--- a/core/camel-console/src/main/java/org/apache/camel/impl/console/EventConsole.java
+++ b/core/camel-console/src/main/java/org/apache/camel/impl/console/EventConsole.java
@@ -22,6 +22,7 @@ import java.util.Queue;
 
 import org.apache.camel.spi.CamelEvent;
 import org.apache.camel.spi.Configurer;
+import org.apache.camel.spi.Metadata;
 import org.apache.camel.spi.annotations.DevConsole;
 import org.apache.camel.support.EventNotifierSupport;
 
@@ -29,6 +30,7 @@ import org.apache.camel.support.EventNotifierSupport;
 @Configurer(bootstrap = true)
 public class EventConsole extends AbstractDevConsole {
 
+    @Metadata(defaultValue = "25", description = "Maximum capacity of last number of events to capture")
     private int capacity = 25;
 
     private Queue<CamelEvent> events;
@@ -36,16 +38,13 @@ public class EventConsole extends AbstractDevConsole {
     private final ConsoleEventNotifier listener = new ConsoleEventNotifier();
 
     public EventConsole() {
-        super("camel", "event");
+        super("camel", "event", "Camel Events", "The most recent Camel events");
     }
 
     public int getCapacity() {
         return capacity;
     }
 
-    /**
-     * Shows last number of events.
-     */
     public void setCapacity(int capacity) {
         this.capacity = capacity;
     }
diff --git a/dsl/camel-kamelet-main/src/main/java/org/apache/camel/main/VertxHttpServer.java b/dsl/camel-kamelet-main/src/main/java/org/apache/camel/main/VertxHttpServer.java
index e2c9257..e53cda0 100644
--- a/dsl/camel-kamelet-main/src/main/java/org/apache/camel/main/VertxHttpServer.java
+++ b/dsl/camel-kamelet-main/src/main/java/org/apache/camel/main/VertxHttpServer.java
@@ -137,6 +137,7 @@ public final class VertxHttpServer {
         Route dev = router.route("/dev");
         dev.method(HttpMethod.GET);
         dev.handler(router.bodyHandler());
+        dev.produces("text/plain");
         dev.handler(new Handler<RoutingContext>() {
             @Override
             public void handle(RoutingContext ctx) {
@@ -147,6 +148,8 @@ public final class VertxHttpServer {
                         if (c.supportMediaType(DevConsole.MediaType.TEXT)) {
                             String text = (String) c.call(DevConsole.MediaType.TEXT);
                             if (text != null) {
+                                sb.append(c.getDisplayName()).append(":");
+                                sb.append("\n\n");
                                 sb.append(text);
                                 sb.append("\n\n");
                             }