camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From davscl...@apache.org
Subject [1/2] git commit: CAMEL-7740: Allow pool prefill configuration for SjmsProducer
Date Mon, 25 Aug 2014 06:27:16 GMT
Repository: camel
Updated Branches:
  refs/heads/master 593f5b15b -> 4f8bf48e7


CAMEL-7740: Allow pool prefill configuration for SjmsProducer

Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/f2132d3c
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/f2132d3c
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/f2132d3c

Branch: refs/heads/master
Commit: f2132d3c83f27694be5d650c227a49a0a82ecaa7
Parents: 86a191f
Author: Cristiano Nicolai <cnicolai@redhat.com>
Authored: Mon Aug 25 12:57:47 2014 +1000
Committer: Cristiano Nicolai <cnicolai@redhat.com>
Committed: Mon Aug 25 13:05:58 2014 +1000

----------------------------------------------------------------------
 .../camel/component/sjms/SjmsEndpoint.java      | 10 ++++
 .../camel/component/sjms/SjmsProducer.java      | 34 ++++++------
 .../sjms/producer/PrefillPoolTest.java          | 56 ++++++++++++++++++++
 3 files changed, 84 insertions(+), 16 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/f2132d3c/components/camel-sjms/src/main/java/org/apache/camel/component/sjms/SjmsEndpoint.java
----------------------------------------------------------------------
diff --git a/components/camel-sjms/src/main/java/org/apache/camel/component/sjms/SjmsEndpoint.java
b/components/camel-sjms/src/main/java/org/apache/camel/component/sjms/SjmsEndpoint.java
index d8cd26f..61d4bea 100644
--- a/components/camel-sjms/src/main/java/org/apache/camel/component/sjms/SjmsEndpoint.java
+++ b/components/camel-sjms/src/main/java/org/apache/camel/component/sjms/SjmsEndpoint.java
@@ -74,6 +74,8 @@ public class SjmsEndpoint extends DefaultEndpoint implements MultipleConsumersSu
     private boolean asyncStartListener;
     @UriParam
     private boolean asyncStopListener;
+    @UriParam
+    private boolean prefillPool = true;
     private TransactionCommitStrategy transactionCommitStrategy;
 
     public SjmsEndpoint() {
@@ -469,4 +471,12 @@ public class SjmsEndpoint extends DefaultEndpoint implements MultipleConsumersSu
         return asyncStopListener;
     }
 
+    public boolean isPrefillPool() {
+        return prefillPool;
+    }
+
+    public void setPrefillPool(boolean prefillPool) {
+        this.prefillPool = prefillPool;
+    }
+
 }

http://git-wip-us.apache.org/repos/asf/camel/blob/f2132d3c/components/camel-sjms/src/main/java/org/apache/camel/component/sjms/SjmsProducer.java
----------------------------------------------------------------------
diff --git a/components/camel-sjms/src/main/java/org/apache/camel/component/sjms/SjmsProducer.java
b/components/camel-sjms/src/main/java/org/apache/camel/component/sjms/SjmsProducer.java
index 533b2f1..27a0ab5 100644
--- a/components/camel-sjms/src/main/java/org/apache/camel/component/sjms/SjmsProducer.java
+++ b/components/camel-sjms/src/main/java/org/apache/camel/component/sjms/SjmsProducer.java
@@ -83,24 +83,26 @@ public abstract class SjmsProducer extends DefaultAsyncProducer {
             setProducers(new GenericObjectPool<MessageProducerResources>(new MessageProducerResourcesFactory()));
             getProducers().setMaxActive(getProducerCount());
             getProducers().setMaxIdle(getProducerCount());
-            if (getEndpoint().isAsyncStartListener()) {
-                asyncStart = getEndpoint().getComponent().getAsyncStartStopExecutorService().submit(new
Runnable() {
-                    @Override
-                    public void run() {
-                        try {
-                            fillProducersPool();
-                        } catch (Throwable e) {
-                            log.warn("Error starting listener container on destination: "
+ getDestinationName() + ". This exception will be ignored.", e);
+            if (getEndpoint().isPrefillPool()) {
+                if (getEndpoint().isAsyncStartListener()) {
+                    asyncStart = getEndpoint().getComponent().getAsyncStartStopExecutorService().submit(new
Runnable() {
+                        @Override
+                        public void run() {
+                            try {
+                                fillProducersPool();
+                            } catch (Throwable e) {
+                                log.warn("Error starting listener container on destination:
" + getDestinationName() + ". This exception will be ignored.", e);
+                            }
                         }
-                    }
 
-                    @Override
-                    public String toString() {
-                        return "AsyncStartListenerTask[" + getDestinationName() + "]";
-                    }
-                });
-            } else {
-                fillProducersPool();
+                        @Override
+                        public String toString() {
+                            return "AsyncStartListenerTask[" + getDestinationName() + "]";
+                        }
+                    });
+                } else {
+                    fillProducersPool();
+                }
             }
         }
     }

http://git-wip-us.apache.org/repos/asf/camel/blob/f2132d3c/components/camel-sjms/src/test/java/org/apache/camel/component/sjms/producer/PrefillPoolTest.java
----------------------------------------------------------------------
diff --git a/components/camel-sjms/src/test/java/org/apache/camel/component/sjms/producer/PrefillPoolTest.java
b/components/camel-sjms/src/test/java/org/apache/camel/component/sjms/producer/PrefillPoolTest.java
new file mode 100644
index 0000000..2785354
--- /dev/null
+++ b/components/camel-sjms/src/test/java/org/apache/camel/component/sjms/producer/PrefillPoolTest.java
@@ -0,0 +1,56 @@
+/**
+ * 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.component.sjms.producer;
+
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.camel.component.sjms.support.JmsTestSupport;
+import org.junit.Test;
+
+/**
+ * Test Producer prefillPool parameter 
+ */
+public class PrefillPoolTest extends JmsTestSupport {
+
+    @Test
+    public void testProducerWithPrefill() throws Exception {
+        sendBodyAndAssert("sjms:queue:producer");
+    }
+
+    @Test
+    public void testProducerWithoutPrefill() throws Exception {
+        sendBodyAndAssert("sjms:queue:producer?prefillPool=false");
+    }
+
+    private void sendBodyAndAssert(final String uri) throws InterruptedException {
+        String body1 = "Hello World";
+        String body2 = "G'day World";
+        MockEndpoint result = getMockEndpoint("mock:result");
+        result.expectedBodiesReceived(body1, body2);
+        template.sendBody(uri, body1);
+        template.sendBody(uri, body2);
+        result.assertIsSatisfied();
+    }
+
+    protected RouteBuilder createRouteBuilder() throws Exception {
+        return new RouteBuilder() {
+            public void configure() throws Exception {
+                from("sjms:queue:producer").to("mock:result");
+            }
+        };
+    }
+}
\ No newline at end of file


Mime
View raw message