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:39 UTC

[camel] 23/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 052ed23c4bf8e81adc7eb421058541ac6df50007
Author: Claus Ibsen <cl...@gmail.com>
AuthorDate: Wed Dec 29 19:25:52 2021 +0100

    CAMEL-17384: Developer Console SPI
---
 .../impl/console/JvmDevConsoleConfigurer.java      | 55 ++++++++++++++++
 .../org.apache.camel.impl.console.JvmDevConsole    |  2 +
 .../services/org/apache/camel/dev-console/jvm      |  2 +
 .../apache/camel/impl/console/JvmDevConsole.java   | 76 ++++++++++++++++++++++
 4 files changed, 135 insertions(+)

diff --git a/core/camel-console/src/generated/java/org/apache/camel/impl/console/JvmDevConsoleConfigurer.java b/core/camel-console/src/generated/java/org/apache/camel/impl/console/JvmDevConsoleConfigurer.java
new file mode 100644
index 0000000..f93de65
--- /dev/null
+++ b/core/camel-console/src/generated/java/org/apache/camel/impl/console/JvmDevConsoleConfigurer.java
@@ -0,0 +1,55 @@
+/* Generated by camel build tools - do NOT edit this file! */
+package org.apache.camel.impl.console;
+
+import java.util.Map;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.spi.ExtendedPropertyConfigurerGetter;
+import org.apache.camel.spi.PropertyConfigurerGetter;
+import org.apache.camel.spi.ConfigurerStrategy;
+import org.apache.camel.spi.GeneratedPropertyConfigurer;
+import org.apache.camel.util.CaseInsensitiveMap;
+import org.apache.camel.impl.console.JvmDevConsole;
+
+/**
+ * Generated by camel build tools - do NOT edit this file!
+ */
+@SuppressWarnings("unchecked")
+public class JvmDevConsoleConfigurer extends org.apache.camel.support.component.PropertyConfigurerSupport implements GeneratedPropertyConfigurer, PropertyConfigurerGetter {
+
+    @Override
+    public boolean configure(CamelContext camelContext, Object obj, String name, Object value, boolean ignoreCase) {
+        org.apache.camel.impl.console.JvmDevConsole target = (org.apache.camel.impl.console.JvmDevConsole) obj;
+        switch (ignoreCase ? name.toLowerCase() : name) {
+        case "camelcontext":
+        case "CamelContext": target.setCamelContext(property(camelContext, org.apache.camel.CamelContext.class, value)); return true;
+        case "showclasspath":
+        case "ShowClasspath": target.setShowClasspath(property(camelContext, boolean.class, value)); return true;
+        default: return false;
+        }
+    }
+
+    @Override
+    public Class<?> getOptionType(String name, boolean ignoreCase) {
+        switch (ignoreCase ? name.toLowerCase() : name) {
+        case "camelcontext":
+        case "CamelContext": return org.apache.camel.CamelContext.class;
+        case "showclasspath":
+        case "ShowClasspath": return boolean.class;
+        default: return null;
+        }
+    }
+
+    @Override
+    public Object getOptionValue(Object obj, String name, boolean ignoreCase) {
+        org.apache.camel.impl.console.JvmDevConsole target = (org.apache.camel.impl.console.JvmDevConsole) obj;
+        switch (ignoreCase ? name.toLowerCase() : name) {
+        case "camelcontext":
+        case "CamelContext": return target.getCamelContext();
+        case "showclasspath":
+        case "ShowClasspath": return target.isShowClasspath();
+        default: return null;
+        }
+    }
+}
+
diff --git a/core/camel-console/src/generated/resources/META-INF/services/org/apache/camel/configurer/org.apache.camel.impl.console.JvmDevConsole b/core/camel-console/src/generated/resources/META-INF/services/org/apache/camel/configurer/org.apache.camel.impl.console.JvmDevConsole
new file mode 100644
index 0000000..402dacd
--- /dev/null
+++ b/core/camel-console/src/generated/resources/META-INF/services/org/apache/camel/configurer/org.apache.camel.impl.console.JvmDevConsole
@@ -0,0 +1,2 @@
+# Generated by camel build tools - do NOT edit this file!
+class=org.apache.camel.impl.console.JvmDevConsoleConfigurer
diff --git a/core/camel-console/src/generated/resources/META-INF/services/org/apache/camel/dev-console/jvm b/core/camel-console/src/generated/resources/META-INF/services/org/apache/camel/dev-console/jvm
new file mode 100644
index 0000000..2e662ee
--- /dev/null
+++ b/core/camel-console/src/generated/resources/META-INF/services/org/apache/camel/dev-console/jvm
@@ -0,0 +1,2 @@
+# Generated by camel build tools - do NOT edit this file!
+class=org.apache.camel.impl.console.JvmDevConsole
diff --git a/core/camel-console/src/main/java/org/apache/camel/impl/console/JvmDevConsole.java b/core/camel-console/src/main/java/org/apache/camel/impl/console/JvmDevConsole.java
new file mode 100644
index 0000000..481dfdc
--- /dev/null
+++ b/core/camel-console/src/main/java/org/apache/camel/impl/console/JvmDevConsole.java
@@ -0,0 +1,76 @@
+/*
+ * 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.lang.management.ManagementFactory;
+import java.lang.management.RuntimeMXBean;
+import java.util.Map;
+
+import org.apache.camel.spi.Configurer;
+import org.apache.camel.spi.Metadata;
+import org.apache.camel.spi.annotations.DevConsole;
+import org.apache.camel.util.TimeUtils;
+
+@DevConsole("jvm")
+@Configurer(bootstrap = true)
+public class JvmDevConsole extends AbstractDevConsole {
+
+    @Metadata(defaultValue = "true", description = "Show classpath information")
+    private boolean showClasspath = true;
+
+    public JvmDevConsole() {
+        super("camel", "jvm", "JVM", "Displays JVM information");
+    }
+
+    public boolean isShowClasspath() {
+        return showClasspath;
+    }
+
+    public void setShowClasspath(boolean showClasspath) {
+        this.showClasspath = showClasspath;
+    }
+
+    @Override
+    protected Object doCall(MediaType mediaType, Map<String, Object> options) {
+        // only text is supported
+        StringBuilder sb = new StringBuilder();
+
+        RuntimeMXBean mb = ManagementFactory.getRuntimeMXBean();
+        if (mb != null) {
+            sb.append(String.format("Java Name: %s\n", mb.getVmName()));
+            sb.append(String.format("Java Version: %s\n", mb.getVmVersion()));
+            sb.append(String.format("Java Vendor: %s\n", mb.getVmVendor()));
+            sb.append(String.format("Uptime: %s\n", TimeUtils.printDuration(mb.getUptime())));
+            sb.append(String.format("PID: %s\n", mb.getPid()));
+            if (!mb.getInputArguments().isEmpty()) {
+                sb.append("Input Arguments:");
+                String cp = String.join("\n    ", mb.getInputArguments());
+                sb.append("\n    ").append(cp).append("\n");
+            }
+            if (mb.isBootClassPathSupported()) {
+                sb.append("Boot Classpath:");
+                String cp = String.join("\n    ", mb.getBootClassPath().split("[:|;]"));
+                sb.append("\n    ").append(cp).append("\n");
+            }
+            sb.append("Classpath:");
+            String cp = String.join("\n    ", mb.getClassPath().split("[:|;]"));
+            sb.append("\n    ").append(cp).append("\n");
+        }
+
+        return sb.toString();
+    }
+}