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 b0a0823  CAMEL-16106: camel-seda - Endpoints with custom queueSize to 
create queue lazy
b0a0823 is described below

commit b0a0823616d570754519fae65c273152d85d7a92
Author: Claus Ibsen <claus.ib...@gmail.com>
AuthorDate: Fri Jan 29 17:47:39 2021 +0100

    CAMEL-16106: camel-seda - Endpoints with custom queueSize to create queue 
lazy
---
 .../apache/camel/component/seda/SedaComponent.java   | 20 +++++++++++++++++++-
 .../apache/camel/component/seda/SedaEndpoint.java    | 15 ++++++++++-----
 .../apache/camel/component/seda/SedaSizeTest.java    |  2 +-
 3 files changed, 30 insertions(+), 7 deletions(-)

diff --git 
a/components/camel-seda/src/main/java/org/apache/camel/component/seda/SedaComponent.java
 
b/components/camel-seda/src/main/java/org/apache/camel/component/seda/SedaComponent.java
index 2b88bc5..78b7679 100644
--- 
a/components/camel-seda/src/main/java/org/apache/camel/component/seda/SedaComponent.java
+++ 
b/components/camel-seda/src/main/java/org/apache/camel/component/seda/SedaComponent.java
@@ -51,6 +51,7 @@ public class SedaComponent extends DefaultComponent {
     private long defaultOfferTimeout;
 
     private final Map<String, QueueReference> queues = new HashMap<>();
+    private final Map<String, Integer> customSize = new HashMap<>();
 
     public SedaComponent() {
     }
@@ -130,11 +131,16 @@ public class SedaComponent extends DefaultComponent {
 
     public synchronized QueueReference getOrCreateQueue(
             SedaEndpoint endpoint, Integer size, Boolean multipleConsumers, 
BlockingQueueFactory<Exchange> customQueueFactory) {
+
         String key = getQueueKey(endpoint.getEndpointUri());
 
+        if (size == null) {
+            // there may be a custom size during startup
+            size = customSize.get(key);
+        }
+
         QueueReference ref = getQueues().get(key);
         if (ref != null) {
-
             // if the given size is not provided, we just use the existing 
queue as is
             if (size != null && !size.equals(ref.getSize())) {
                 // there is already a queue, so make sure the size matches
@@ -229,6 +235,17 @@ public class SedaComponent extends DefaultComponent {
         // if offerTimeout is set on endpoint, defaultOfferTimeout is ignored.
         long offerTimeout = getAndRemoveParameter(parameters, "offerTimeout", 
long.class, defaultOfferTimeout);
 
+        // using custom size?
+        Integer size = getAndRemoveParameter(parameters, "size", 
Integer.class);
+        if (size != null) {
+            answer.setSize(size);
+            // this queue has a custom size remember this while setting up 
routes
+            if (!getCamelContext().isStarted()) {
+                String key = getQueueKey(uri);
+                customSize.put(key, size);
+            }
+        }
+
         answer.setOfferTimeout(offerTimeout);
         answer.setBlockWhenFull(blockWhenFull);
         answer.setDiscardWhenFull(discardWhenFull);
@@ -259,6 +276,7 @@ public class SedaComponent extends DefaultComponent {
     @Override
     protected void doStop() throws Exception {
         getQueues().clear();
+        customSize.clear();
         super.doStop();
     }
 
diff --git 
a/components/camel-seda/src/main/java/org/apache/camel/component/seda/SedaEndpoint.java
 
b/components/camel-seda/src/main/java/org/apache/camel/component/seda/SedaEndpoint.java
index 6af015b..da90364 100644
--- 
a/components/camel-seda/src/main/java/org/apache/camel/component/seda/SedaEndpoint.java
+++ 
b/components/camel-seda/src/main/java/org/apache/camel/component/seda/SedaEndpoint.java
@@ -526,11 +526,6 @@ public class SedaEndpoint extends DefaultEndpoint 
implements AsyncEndpoint, Brow
                                                + " You can only either discard 
or block when full.");
         }
 
-        // force creating queue when starting
-        if (queue == null) {
-            queue = getQueue();
-        }
-
         // special for unit testing where we can set a system property to make 
seda poll faster
         // and therefore also react faster upon shutdown, which makes overall 
testing faster of the Camel project
         String override = System.getProperty("CamelSedaPollTimeout", "" + 
getPollTimeout());
@@ -538,6 +533,16 @@ public class SedaEndpoint extends DefaultEndpoint 
implements AsyncEndpoint, Brow
     }
 
     @Override
+    protected void doStart() throws Exception {
+        super.doStart();
+
+        // force creating queue when starting
+        if (queue == null) {
+            queue = getQueue();
+        }
+    }
+
+    @Override
     public void stop() {
         if (getConsumers().isEmpty()) {
             super.stop();
diff --git 
a/core/camel-core/src/test/java/org/apache/camel/component/seda/SedaSizeTest.java
 
b/core/camel-core/src/test/java/org/apache/camel/component/seda/SedaSizeTest.java
index 0694d65..d1c3a43 100644
--- 
a/core/camel-core/src/test/java/org/apache/camel/component/seda/SedaSizeTest.java
+++ 
b/core/camel-core/src/test/java/org/apache/camel/component/seda/SedaSizeTest.java
@@ -36,7 +36,7 @@ public class SedaSizeTest extends ContextTestSupport {
         return new RouteBuilder() {
             @Override
             public void configure() throws Exception {
-                from("direct:start").to("seda:bar?size=5");
+                from("direct:start").to("seda:bar");
 
                 from("seda:bar?size=5").to("mock:bar");
             }

Reply via email to