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:45 UTC
[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 <da...@apache.org>
Authored: Fri Jan 10 10:26:29 2014 +0100
Committer: Claus Ibsen <da...@apache.org>
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);
[3/3] git commit: CAMEL-7117: Jetty http client should use daemon
threads in its pool.
Posted by da...@apache.org.
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/136d7c3e
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/136d7c3e
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/136d7c3e
Branch: refs/heads/camel-2.12.x
Commit: 136d7c3e445e238843080ec301a81e8810b0a76d
Parents: d491f7f
Author: Claus Ibsen <da...@apache.org>
Authored: Fri Jan 10 10:27:33 2014 +0100
Committer: Claus Ibsen <da...@apache.org>
Committed: Fri Jan 10 10:28:30 2014 +0100
----------------------------------------------------------------------
.../main/java/org/apache/camel/component/jetty/CamelHttpClient.java | 1 -
1 file changed, 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/136d7c3e/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 eed3347..386ed03 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,6 @@ 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;
[2/3] git commit: CAMEL-7116: jetty http producer should stop client
thread pool when stopping.
Posted by da...@apache.org.
CAMEL-7116: jetty http producer should stop client thread pool when stopping.
Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/38119b9d
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/38119b9d
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/38119b9d
Branch: refs/heads/camel-2.12.x
Commit: 38119b9d63df163a6f3757662503e396634d29b8
Parents: 483b445
Author: Claus Ibsen <da...@apache.org>
Authored: Fri Jan 10 10:08:17 2014 +0100
Committer: Claus Ibsen <da...@apache.org>
Committed: Fri Jan 10 10:28:29 2014 +0100
----------------------------------------------------------------------
.../component/jetty/JettyHttpProducer.java | 11 +++
.../HttpJettyProducerRecipientListTest.java | 70 ++++++++++++++++++++
2 files changed, 81 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/38119b9d/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 3e28b75..fa4a69f 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
@@ -43,6 +43,7 @@ import org.apache.camel.util.ObjectHelper;
import org.apache.camel.util.URISupport;
import org.eclipse.jetty.client.HttpClient;
import org.eclipse.jetty.io.ByteArrayBuffer;
+import org.eclipse.jetty.util.component.LifeCycle;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -266,6 +267,11 @@ public class JettyHttpProducer extends DefaultProducer implements AsyncProcessor
// only start non-shared client
if (!sharedClient && client != null) {
client.start();
+ // start the thread pool
+ LOG.debug("Starting client thread pool {}", client.getThreadPool());
+ if (client.getThreadPool() instanceof LifeCycle) {
+ ((LifeCycle) client.getThreadPool()).start();
+ }
}
super.doStart();
}
@@ -276,6 +282,11 @@ public class JettyHttpProducer extends DefaultProducer implements AsyncProcessor
// only stop non-shared client
if (!sharedClient && client != null) {
client.stop();
+ // stop thread pool
+ LOG.debug("Stopping client thread pool {}", client.getThreadPool());
+ if (client.getThreadPool() instanceof LifeCycle) {
+ ((LifeCycle) client.getThreadPool()).stop();
+ }
}
}
}
http://git-wip-us.apache.org/repos/asf/camel/blob/38119b9d/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
new file mode 100644
index 0000000..ab06e43
--- /dev/null
+++ b/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/jettyproducer/HttpJettyProducerRecipientListTest.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 HttpJettyProducerRecipientListTest 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