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 2014/01/10 10:24:10 UTC
[2/3] git commit: CAMEL-7117: Jetty http client should use daemon
threads in its pool.
CAMEL-7117: Jetty http client should use daemon threads in its pool.
Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/fe158aee
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/fe158aee
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/fe158aee
Branch: refs/heads/master
Commit: fe158aeec716083312268167095dfbe8b3e06c92
Parents: 5f356bc
Author: Claus Ibsen <da...@apache.org>
Authored: Fri Jan 10 10:26:29 2014 +0100
Committer: Claus Ibsen <da...@apache.org>
Committed: Fri Jan 10 10:28:05 2014 +0100
----------------------------------------------------------------------
.../camel/component/jetty/CamelHttpClient.java | 19 ++++++
.../component/jetty/JettyHttpComponent.java | 7 +-
.../component/jetty/JettyHttpProducer.java | 4 +-
...oducerRecipientListCustomThreadPoolTest.java | 70 ++++++++++++++++++++
.../HttpJettyProducerRecipientListTest.java | 2 +-
5 files changed, 94 insertions(+), 8 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/fe158aee/components/camel-jetty/src/main/java/org/apache/camel/component/jetty/CamelHttpClient.java
----------------------------------------------------------------------
diff --git a/components/camel-jetty/src/main/java/org/apache/camel/component/jetty/CamelHttpClient.java b/components/camel-jetty/src/main/java/org/apache/camel/component/jetty/CamelHttpClient.java
index 945a404..eed3347 100644
--- a/components/camel-jetty/src/main/java/org/apache/camel/component/jetty/CamelHttpClient.java
+++ b/components/camel-jetty/src/main/java/org/apache/camel/component/jetty/CamelHttpClient.java
@@ -18,7 +18,10 @@ package org.apache.camel.component.jetty;
import javax.net.ssl.SSLContext;
+import org.apache.camel.RuntimeCamelException;
+import org.apache.camel.util.ObjectHelper;
import org.eclipse.jetty.client.HttpClient;
+import org.eclipse.jetty.util.thread.QueuedThreadPool;
public class CamelHttpClient extends HttpClient {
@@ -36,4 +39,20 @@ public class CamelHttpClient extends HttpClient {
public void setSSLContext(SSLContext context) {
this.context = context;
}
+
+ @Override
+ protected void doStart() throws Exception {
+ if (getThreadPool() == null) {
+ // if there is no thread pool then create a default thread pool using daemon threads
+ QueuedThreadPool qtp = new QueuedThreadPool();
+ // 16 max threads is the default in the http client
+ qtp.setMaxThreads(16);
+ qtp.setDaemon(true);
+ // let the thread names indicate they are from the client
+ qtp.setName("CamelJettyClient(" + ObjectHelper.getIdentityHashCode(this) + ")");
+ setThreadPool(qtp);
+ }
+
+ super.doStart();
+ }
}
http://git-wip-us.apache.org/repos/asf/camel/blob/fe158aee/components/camel-jetty/src/main/java/org/apache/camel/component/jetty/JettyHttpComponent.java
----------------------------------------------------------------------
diff --git a/components/camel-jetty/src/main/java/org/apache/camel/component/jetty/JettyHttpComponent.java b/components/camel-jetty/src/main/java/org/apache/camel/component/jetty/JettyHttpComponent.java
index e23e342..808f554 100644
--- a/components/camel-jetty/src/main/java/org/apache/camel/component/jetty/JettyHttpComponent.java
+++ b/components/camel-jetty/src/main/java/org/apache/camel/component/jetty/JettyHttpComponent.java
@@ -708,13 +708,10 @@ public class JettyHttpComponent extends HttpComponent {
QueuedThreadPool qtp = new QueuedThreadPool();
qtp.setMinThreads(minThreads.intValue());
qtp.setMaxThreads(maxThreads.intValue());
+ // and we want to use daemon threads
+ qtp.setDaemon(true);
// let the thread names indicate they are from the client
qtp.setName("CamelJettyClient(" + ObjectHelper.getIdentityHashCode(httpClient) + ")");
- try {
- qtp.start();
- } catch (Exception e) {
- throw new RuntimeCamelException("Error starting JettyHttpClient thread pool: " + qtp, e);
- }
httpClient.setThreadPool(qtp);
}
http://git-wip-us.apache.org/repos/asf/camel/blob/fe158aee/components/camel-jetty/src/main/java/org/apache/camel/component/jetty/JettyHttpProducer.java
----------------------------------------------------------------------
diff --git a/components/camel-jetty/src/main/java/org/apache/camel/component/jetty/JettyHttpProducer.java b/components/camel-jetty/src/main/java/org/apache/camel/component/jetty/JettyHttpProducer.java
index fa4a69f..45fcc53 100644
--- a/components/camel-jetty/src/main/java/org/apache/camel/component/jetty/JettyHttpProducer.java
+++ b/components/camel-jetty/src/main/java/org/apache/camel/component/jetty/JettyHttpProducer.java
@@ -268,8 +268,8 @@ public class JettyHttpProducer extends DefaultProducer implements AsyncProcessor
if (!sharedClient && client != null) {
client.start();
// start the thread pool
- LOG.debug("Starting client thread pool {}", client.getThreadPool());
if (client.getThreadPool() instanceof LifeCycle) {
+ LOG.debug("Starting client thread pool {}", client.getThreadPool());
((LifeCycle) client.getThreadPool()).start();
}
}
@@ -283,8 +283,8 @@ public class JettyHttpProducer extends DefaultProducer implements AsyncProcessor
if (!sharedClient && client != null) {
client.stop();
// stop thread pool
- LOG.debug("Stopping client thread pool {}", client.getThreadPool());
if (client.getThreadPool() instanceof LifeCycle) {
+ LOG.debug("Stopping client thread pool {}", client.getThreadPool());
((LifeCycle) client.getThreadPool()).stop();
}
}
http://git-wip-us.apache.org/repos/asf/camel/blob/fe158aee/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/jettyproducer/HttpJettyProducerRecipientListCustomThreadPoolTest.java
----------------------------------------------------------------------
diff --git a/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/jettyproducer/HttpJettyProducerRecipientListCustomThreadPoolTest.java b/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/jettyproducer/HttpJettyProducerRecipientListCustomThreadPoolTest.java
new file mode 100644
index 0000000..1036a35
--- /dev/null
+++ b/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/jettyproducer/HttpJettyProducerRecipientListCustomThreadPoolTest.java
@@ -0,0 +1,70 @@
+/**
+ * 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.jetty.jettyproducer;
+
+import org.apache.camel.Exchange;
+import org.apache.camel.Processor;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.jetty.BaseJettyTest;
+import org.junit.Test;
+
+/**
+ * @version
+ */
+public class HttpJettyProducerRecipientListCustomThreadPoolTest extends BaseJettyTest {
+
+ @Test
+ public void testRecipientList() throws Exception {
+ // these tests does not run well on Windows
+ if (isPlatform("windows")) {
+ return;
+ }
+
+ // give Jetty time to startup properly
+ Thread.sleep(1000);
+
+ Exchange a = template.request("direct:a", new Processor() {
+ public void process(Exchange exchange) throws Exception {
+ exchange.getIn().setHeader("slip", "jetty://http://localhost:" + getPort() + "/myapp?foo=123&bar=cheese&httpClientMinThreads=4&httpClientMaxThreads=8");
+ }
+ });
+ assertNotNull(a);
+
+ assertEquals("Bye cheese", a.getOut().getBody(String.class));
+ assertEquals(246, a.getOut().getHeader("foo", Integer.class).intValue());
+ }
+
+ @Override
+ protected RouteBuilder createRouteBuilder() throws Exception {
+ return new RouteBuilder() {
+ @Override
+ public void configure() throws Exception {
+ from("direct:a").recipientList(header("slip"));
+
+ from("jetty://http://localhost:{{port}}/myapp").process(new Processor() {
+ public void process(Exchange exchange) throws Exception {
+ int foo = exchange.getIn().getHeader("foo", Integer.class);
+ String bar = exchange.getIn().getHeader("bar", String.class);
+
+ exchange.getOut().setHeader("foo", foo * 2);
+ exchange.getOut().setBody("Bye " + bar);
+ }
+ });
+ }
+ };
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/camel/blob/fe158aee/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/jettyproducer/HttpJettyProducerRecipientListTest.java
----------------------------------------------------------------------
diff --git a/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/jettyproducer/HttpJettyProducerRecipientListTest.java b/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/jettyproducer/HttpJettyProducerRecipientListTest.java
index ab06e43..89d817e 100644
--- a/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/jettyproducer/HttpJettyProducerRecipientListTest.java
+++ b/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/jettyproducer/HttpJettyProducerRecipientListTest.java
@@ -39,7 +39,7 @@ public class HttpJettyProducerRecipientListTest extends BaseJettyTest {
Exchange a = template.request("direct:a", new Processor() {
public void process(Exchange exchange) throws Exception {
- exchange.getIn().setHeader("slip", "jetty://http://localhost:" + getPort() + "/myapp?foo=123&bar=cheese&httpClientMinThreads=4&httpClientMaxThreads=8");
+ exchange.getIn().setHeader("slip", "jetty://http://localhost:" + getPort() + "/myapp?foo=123&bar=cheese");
}
});
assertNotNull(a);