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 2020/10/13 09:41:02 UTC

[camel] branch master updated: CAMEL-15176: Optimize component to do as much in init phase vs start phase.

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

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


The following commit(s) were added to refs/heads/master by this push:
     new 543507c  CAMEL-15176: Optimize component to do as much in init phase vs start phase.
543507c is described below

commit 543507cbea09b79764ed25a5a51d3534712e479b
Author: Claus Ibsen <cl...@gmail.com>
AuthorDate: Tue Oct 13 11:40:33 2020 +0200

    CAMEL-15176: Optimize component to do as much in init phase vs start phase.
---
 .../http/vertx/VertxPlatformHttpConsumer.java        | 20 +++++++++++++-------
 .../platform/http/vertx/VertxPlatformHttpServer.java | 11 +++++++++--
 components/components-init-work-in-progress.md       |  2 +-
 3 files changed, 23 insertions(+), 10 deletions(-)

diff --git a/components/camel-platform-http-vertx/src/main/java/org/apache/camel/component/platform/http/vertx/VertxPlatformHttpConsumer.java b/components/camel-platform-http-vertx/src/main/java/org/apache/camel/component/platform/http/vertx/VertxPlatformHttpConsumer.java
index 16dd352..8937de5 100644
--- a/components/camel-platform-http-vertx/src/main/java/org/apache/camel/component/platform/http/vertx/VertxPlatformHttpConsumer.java
+++ b/components/camel-platform-http-vertx/src/main/java/org/apache/camel/component/platform/http/vertx/VertxPlatformHttpConsumer.java
@@ -62,6 +62,8 @@ public class VertxPlatformHttpConsumer extends DefaultConsumer {
 
     private final List<Handler<RoutingContext>> handlers;
     private final String fileNameExtWhitelist;
+    private Set<Method> methods;
+    private String path;
 
     private Route route;
 
@@ -82,24 +84,28 @@ public class VertxPlatformHttpConsumer extends DefaultConsumer {
     }
 
     @Override
+    protected void doInit() throws Exception {
+        super.doInit();
+        methods = Method.parseList(getEndpoint().getHttpMethodRestrict());
+        path = configureEndpointPath(getEndpoint());
+    }
+
+    @Override
     protected void doStart() throws Exception {
         super.doStart();
 
         final VertxPlatformHttpRouter router = VertxPlatformHttpRouter.lookup(getEndpoint().getCamelContext());
-        final PlatformHttpEndpoint endpoint = getEndpoint();
-        final String path = configureEndpointPath(endpoint);
         final Route newRoute = router.route(path);
 
-        final Set<Method> methods = Method.parseList(endpoint.getHttpMethodRestrict());
         if (!methods.equals(Method.getAll())) {
             methods.forEach(m -> newRoute.method(HttpMethod.valueOf(m.name())));
         }
 
-        if (endpoint.getConsumes() != null) {
-            newRoute.consumes(endpoint.getConsumes());
+        if (getEndpoint().getConsumes() != null) {
+            newRoute.consumes(getEndpoint().getConsumes());
         }
-        if (endpoint.getProduces() != null) {
-            newRoute.produces(endpoint.getProduces());
+        if (getEndpoint().getProduces() != null) {
+            newRoute.produces(getEndpoint().getProduces());
         }
 
         newRoute.handler(router.bodyHandler());
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 69f8092..99eec9d 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
@@ -86,6 +86,15 @@ public class VertxPlatformHttpServer extends ServiceSupport implements CamelCont
     }
 
     @Override
+    protected void doInit() throws Exception {
+        // we can only optimize to lookup existing vertx instance at init phase
+        vertx = lookupVertx();
+        if (vertx != null) {
+            LOGGER.info("Found Vert.x instance in registry: {}", vertx);
+        }
+    }
+
+    @Override
     protected void doStart() throws Exception {
         initializeServer();
         startServer();
@@ -128,8 +137,6 @@ public class VertxPlatformHttpServer extends ServiceSupport implements CamelCont
                 LOGGER.info("Creating new Vert.x instance");
                 vertx = createVertxInstance();
                 localVertx = true;
-            } else {
-                LOGGER.info("Found Vert.x instance in registry: {}", vertx);
             }
         }
 
diff --git a/components/components-init-work-in-progress.md b/components/components-init-work-in-progress.md
index e37165d..f125850 100644
--- a/components/components-init-work-in-progress.md
+++ b/components/components-init-work-in-progress.md
@@ -274,7 +274,7 @@
 |camel-pgevent| | |
 |camel-pg-replication-slot| | |
 |camel-platform-http|DONE| |
-|camel-platform-http-vertx| | |
+|camel-platform-http-vertx|DONE | |
 |camel-printer| | |
 |camel-properties| | |
 |camel-protobuf| | |