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:18 UTC
[camel] 02/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 06ba52fa5f7bb35c9853f126d969f41a86a9e50b
Author: Claus Ibsen <cl...@gmail.com>
AuthorDate: Mon Dec 27 11:15:16 2021 +0100
CAMEL-17384: Developer Console SPI
---
.../java/org/apache/camel/console/DevConsole.java | 6 ++
core/camel-console/pom.xml | 55 ++++++++++++
.../camel/impl/console/AbstractDevConsole.java | 99 ++++++++++++++++++++++
core/pom.xml | 1 +
4 files changed, 161 insertions(+)
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 d131a07..87f6f49 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
@@ -25,6 +25,7 @@ import java.util.Map;
public interface DevConsole {
String CONSOLE_ID = "console.id";
+ String CONSOLE_GROUP = "console.group";
enum MediaType {
TEXT,
@@ -37,6 +38,11 @@ public interface DevConsole {
String getId();
/**
+ * The group of this console.
+ */
+ String getGroup();
+
+ /**
* Whether this console supports the given media type.
*
* @param mediaType the media type
diff --git a/core/camel-console/pom.xml b/core/camel-console/pom.xml
new file mode 100644
index 0000000..17d7611
--- /dev/null
+++ b/core/camel-console/pom.xml
@@ -0,0 +1,55 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ 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.
+
+-->
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>org.apache.camel</groupId>
+ <artifactId>core</artifactId>
+ <version>3.15.0-SNAPSHOT</version>
+ </parent>
+
+ <artifactId>camel-console</artifactId>
+ <packaging>jar</packaging>
+
+ <name>Camel :: Console</name>
+ <description>Camel Developer Console</description>
+
+ <properties>
+ <firstVersion>3.15.0</firstVersion>
+ <label>core</label>
+ <camel-prepare-component>false</camel-prepare-component>
+ </properties>
+
+ <dependencies>
+
+ <dependency>
+ <groupId>org.apache.camel</groupId>
+ <artifactId>camel-core-engine</artifactId>
+ </dependency>
+
+ <dependency>
+ <groupId>org.slf4j</groupId>
+ <artifactId>slf4j-api</artifactId>
+ </dependency>
+
+ </dependencies>
+
+</project>
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
new file mode 100644
index 0000000..cfbde35
--- /dev/null
+++ b/core/camel-console/src/main/java/org/apache/camel/impl/console/AbstractDevConsole.java
@@ -0,0 +1,99 @@
+/*
+ * 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.Map;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.CamelContextAware;
+import org.apache.camel.console.DevConsole;
+
+/**
+ * Base implementation for {@link DevConsole}.
+ */
+public abstract class AbstractDevConsole implements DevConsole, CamelContextAware {
+
+ private CamelContext camelContext;
+ private final Object lock;
+ private final String id;
+ private final String group;
+
+ public AbstractDevConsole(String id, String group) {
+ this.lock = new Object();
+ this.id = id;
+ this.group = group;
+ }
+
+ @Override
+ public CamelContext getCamelContext() {
+ return camelContext;
+ }
+
+ @Override
+ public void setCamelContext(CamelContext camelContext) {
+ this.camelContext = camelContext;
+ }
+
+ @Override
+ public boolean supportMediaType(MediaType mediaType) {
+ return mediaType == MediaType.TEXT;
+ }
+
+ @Override
+ public String getId() {
+ return id;
+ }
+
+ @Override
+ public String getGroup() {
+ return group;
+ }
+
+ @Override
+ public boolean equals(Object o) {
+ if (this == o) {
+ return true;
+ }
+ if (!(o instanceof AbstractDevConsole)) {
+ return false;
+ }
+
+ AbstractDevConsole that = (AbstractDevConsole) o;
+
+ return id.equals(that.id);
+ }
+
+ @Override
+ public int hashCode() {
+ return id != null ? id.hashCode() : 0;
+ }
+
+ @Override
+ public Object call(MediaType mediaType, Map<String, Object> options) {
+ synchronized (lock) {
+ return doCall(mediaType, options);
+ }
+ }
+
+ /**
+ * Invokes and gets the output from this console.
+ *
+ * @see DevConsole#call(MediaType, Map)
+ */
+ protected abstract Object doCall(MediaType mediaType, Map<String, Object> options);
+
+}
diff --git a/core/pom.xml b/core/pom.xml
index e56d05f..97b9c87 100644
--- a/core/pom.xml
+++ b/core/pom.xml
@@ -56,6 +56,7 @@
<module>camel-core-xml</module>
<module>camel-cloud</module>
<module>camel-health</module>
+ <module>camel-console</module>
<module>camel-main</module>
</modules>