You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by lb...@apache.org on 2020/03/20 09:07:22 UTC

[camel] 02/02: CAMEL-14738: Create a camel-platform-http-vertx component (share vertx instance)

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

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

commit 1ff09b238bed5753b48a7be854233eadab80483c
Author: lburgazzoli <lb...@gmail.com>
AuthorDate: Thu Mar 19 18:00:31 2020 +0100

    CAMEL-14738: Create a camel-platform-http-vertx component (share vertx instance)
---
 ...atformHttpRouter.java => VertxPlatformHttp.java} | 21 ++++++++++++++-------
 .../http/vertx/VertxPlatformHttpEngine.java         |  8 ++++----
 .../http/vertx/VertxPlatformHttpServer.java         |  4 ++--
 .../http/vertx/VertxPlatformHttpEngineTest.java     |  2 +-
 4 files changed, 21 insertions(+), 14 deletions(-)

diff --git a/components/camel-platform-http-vertx/src/main/java/org/apache/camel/component/platform/http/vertx/VertxPlatformHttpRouter.java b/components/camel-platform-http-vertx/src/main/java/org/apache/camel/component/platform/http/vertx/VertxPlatformHttp.java
similarity index 78%
rename from components/camel-platform-http-vertx/src/main/java/org/apache/camel/component/platform/http/vertx/VertxPlatformHttpRouter.java
rename to components/camel-platform-http-vertx/src/main/java/org/apache/camel/component/platform/http/vertx/VertxPlatformHttp.java
index 939bcd1..bdc63c0 100644
--- a/components/camel-platform-http-vertx/src/main/java/org/apache/camel/component/platform/http/vertx/VertxPlatformHttpRouter.java
+++ b/components/camel-platform-http-vertx/src/main/java/org/apache/camel/component/platform/http/vertx/VertxPlatformHttp.java
@@ -20,6 +20,7 @@ import java.util.Collections;
 import java.util.List;
 
 import io.vertx.core.Handler;
+import io.vertx.core.Vertx;
 import io.vertx.ext.web.Router;
 import io.vertx.ext.web.RoutingContext;
 import org.apache.camel.CamelContext;
@@ -30,21 +31,27 @@ import org.apache.camel.support.CamelContextHelper;
  * This class holds an instance of a {@link Router} and an optional list of [{@link Handler<RoutingContext>} that are
  * used by the {@link VertxPlatformHttpConsumer} to create and register Vert.x {@link io.vertx.ext.web.Route}].
  */
-public class VertxPlatformHttpRouter {
+public class VertxPlatformHttp {
     public static final String PLATFORM_HTTP_ROUTER_NAME = PlatformHttpConstants.PLATFORM_HTTP_COMPONENT_NAME + "-router";
 
+    private final Vertx vertx;
     private final Router router;
     private final List<Handler<RoutingContext>> handlers;
 
-    public VertxPlatformHttpRouter(Router router) {
-        this(router, Collections.emptyList());
+    public VertxPlatformHttp(Vertx vertx, Router router) {
+        this(vertx, router, Collections.emptyList());
     }
 
-    public VertxPlatformHttpRouter(Router router, List<Handler<RoutingContext>> handlers) {
+    public VertxPlatformHttp(Vertx vertx, Router router, List<Handler<RoutingContext>> handlers) {
+        this.vertx = vertx;
         this.router = router;
         this.handlers = handlers;
     }
 
+    public Vertx vertx() {
+        return this.vertx;
+    }
+
     public Router router() {
         return router;
     }
@@ -59,11 +66,11 @@ public class VertxPlatformHttpRouter {
     //
     // **********************
 
-    public static VertxPlatformHttpRouter lookup(CamelContext camelContext) {
+    public static VertxPlatformHttp lookup(CamelContext camelContext) {
         return CamelContextHelper.mandatoryLookup(
             camelContext,
-            VertxPlatformHttpRouter.PLATFORM_HTTP_ROUTER_NAME,
-            VertxPlatformHttpRouter.class
+            VertxPlatformHttp.PLATFORM_HTTP_ROUTER_NAME,
+            VertxPlatformHttp.class
         );
     }
 }
diff --git a/components/camel-platform-http-vertx/src/main/java/org/apache/camel/component/platform/http/vertx/VertxPlatformHttpEngine.java b/components/camel-platform-http-vertx/src/main/java/org/apache/camel/component/platform/http/vertx/VertxPlatformHttpEngine.java
index cca7be7..d0769d6 100644
--- a/components/camel-platform-http-vertx/src/main/java/org/apache/camel/component/platform/http/vertx/VertxPlatformHttpEngine.java
+++ b/components/camel-platform-http-vertx/src/main/java/org/apache/camel/component/platform/http/vertx/VertxPlatformHttpEngine.java
@@ -43,7 +43,7 @@ import org.apache.camel.util.ObjectHelper;
 @JdkService(PlatformHttpConstants.PLATFORM_HTTP_ENGINE_FACTORY)
 public class VertxPlatformHttpEngine extends ServiceSupport implements PlatformHttpEngine, CamelContextAware {
     private CamelContext camelContext;
-    private VertxPlatformHttpRouter router;
+    private VertxPlatformHttp router;
     private List<Handler<RoutingContext>> handlers;
     private UploadAttacher uploadAttacher;
 
@@ -51,11 +51,11 @@ public class VertxPlatformHttpEngine extends ServiceSupport implements PlatformH
         this.handlers = Collections.emptyList();
     }
 
-    public VertxPlatformHttpRouter getRouter() {
+    public VertxPlatformHttp getRouter() {
         return router;
     }
 
-    public void setRouter(VertxPlatformHttpRouter router) {
+    public void setRouter(VertxPlatformHttp router) {
         this.router = router;
     }
 
@@ -92,7 +92,7 @@ public class VertxPlatformHttpEngine extends ServiceSupport implements PlatformH
         if (router == null) {
             ObjectHelper.notNull(getCamelContext(), "Camel Context");
 
-            router = VertxPlatformHttpRouter.lookup(getCamelContext());
+            router = VertxPlatformHttp.lookup(getCamelContext());
         }
     }
 
diff --git a/components/camel-platform-http-vertx/src/main/java/org/apache/camel/component/platform/http/vertx/VertxPlatformHttpServer.java b/components/camel-platform-http-vertx/src/main/java/org/apache/camel/component/platform/http/vertx/VertxPlatformHttpServer.java
index 300a4da..95102e6 100644
--- a/components/camel-platform-http-vertx/src/main/java/org/apache/camel/component/platform/http/vertx/VertxPlatformHttpServer.java
+++ b/components/camel-platform-http-vertx/src/main/java/org/apache/camel/component/platform/http/vertx/VertxPlatformHttpServer.java
@@ -145,8 +145,8 @@ final class VertxPlatformHttpServer extends ServiceSupport {
         router.mountSubRouter(configuration.getPath(), subRouter);
 
         context.getRegistry().bind(
-            VertxPlatformHttpRouter.PLATFORM_HTTP_ROUTER_NAME,
-            new VertxPlatformHttpRouter(subRouter, Collections.singletonList(createBodyHandler()))
+            VertxPlatformHttp.PLATFORM_HTTP_ROUTER_NAME,
+            new VertxPlatformHttp(vertx, subRouter, Collections.singletonList(createBodyHandler()))
         );
 
         //HttpServerOptions options = new HttpServerOptions();
diff --git a/components/camel-platform-http-vertx/src/test/java/org/apache/camel/component/platform/http/vertx/VertxPlatformHttpEngineTest.java b/components/camel-platform-http-vertx/src/test/java/org/apache/camel/component/platform/http/vertx/VertxPlatformHttpEngineTest.java
index 4bcf876..84fa9a5 100644
--- a/components/camel-platform-http-vertx/src/test/java/org/apache/camel/component/platform/http/vertx/VertxPlatformHttpEngineTest.java
+++ b/components/camel-platform-http-vertx/src/test/java/org/apache/camel/component/platform/http/vertx/VertxPlatformHttpEngineTest.java
@@ -54,7 +54,7 @@ public class VertxPlatformHttpEngineTest {
 
             context.start();
 
-            assertThat(VertxPlatformHttpRouter.lookup(context)).isNotNull();
+            assertThat(VertxPlatformHttp.lookup(context)).isNotNull();
             assertThat(context.getComponent("platform-http")).isInstanceOfSatisfying(PlatformHttpComponent.class, component -> {
                 assertThat(component.getEngine()).isInstanceOfSatisfying(VertxPlatformHttpEngine.class, e -> {
                     assertThat(e.getRouter().router()).isNotNull();