Return-Path: X-Original-To: apmail-camel-commits-archive@www.apache.org Delivered-To: apmail-camel-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id DBB5C10739 for ; Fri, 10 Jan 2014 09:26:40 +0000 (UTC) Received: (qmail 84812 invoked by uid 500); 10 Jan 2014 09:25:00 -0000 Delivered-To: apmail-camel-commits-archive@camel.apache.org Received: (qmail 84672 invoked by uid 500); 10 Jan 2014 09:24:48 -0000 Mailing-List: contact commits-help@camel.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@camel.apache.org Delivered-To: mailing list commits@camel.apache.org Received: (qmail 84655 invoked by uid 99); 10 Jan 2014 09:24:45 -0000 Received: from tyr.zones.apache.org (HELO tyr.zones.apache.org) (140.211.11.114) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 10 Jan 2014 09:24:45 +0000 Received: by tyr.zones.apache.org (Postfix, from userid 65534) id 0CC228B547D; Fri, 10 Jan 2014 09:24:45 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: davsclaus@apache.org To: commits@camel.apache.org Date: Fri, 10 Jan 2014 09:24:45 -0000 Message-Id: X-Mailer: ASF-Git Admin Mailer Subject: [1/3] git commit: CAMEL-7117: Jetty http client should use daemon threads in its pool. Updated Branches: refs/heads/camel-2.12.x 483b445dc -> 136d7c3e4 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/d491f7f9 Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/d491f7f9 Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/d491f7f9 Branch: refs/heads/camel-2.12.x Commit: d491f7f9847fad90fcafebab7b7e979fdad9c12a Parents: 38119b9 Author: Claus Ibsen Authored: Fri Jan 10 10:26:29 2014 +0100 Committer: Claus Ibsen Committed: Fri Jan 10 10:28:29 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/d491f7f9/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/d491f7f9/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/d491f7f9/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/d491f7f9/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/d491f7f9/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);