Repository: camel Updated Branches: refs/heads/camel-2.13.x 9df6d8f45 -> 2883bbfef refs/heads/camel-2.14.x 2e92c811b -> 7e51e5b4e
CAMEL-8094 Do not stop the timer in NettyClientBossPoolBuilder Project: http://git-wip-us.apache.org/repos/asf/camel/repo Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/7e51e5b4 Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/7e51e5b4 Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/7e51e5b4 Branch: refs/heads/camel-2.14.x Commit: 7e51e5b4e090009871ddec7002b95ce5315c1897 Parents: 2e92c81 Author: Willem Jiang <willem.ji...@gmail.com> Authored: Mon Dec 1 12:56:27 2014 +0800 Committer: Willem Jiang <willem.ji...@gmail.com> Committed: Mon Dec 1 12:58:24 2014 +0800 ---------------------------------------------------------------------- .../netty/NettyClientBossPoolBuilder.java | 44 ++++++++++++++++++-- .../netty/NettyServerBossPoolBuilder.java | 3 +- .../component/netty/NettyWorkerPoolBuilder.java | 2 - 3 files changed, 41 insertions(+), 8 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/camel/blob/7e51e5b4/components/camel-netty/src/main/java/org/apache/camel/component/netty/NettyClientBossPoolBuilder.java ---------------------------------------------------------------------- diff --git a/components/camel-netty/src/main/java/org/apache/camel/component/netty/NettyClientBossPoolBuilder.java b/components/camel-netty/src/main/java/org/apache/camel/component/netty/NettyClientBossPoolBuilder.java index 62caf1e..6697491 100644 --- a/components/camel-netty/src/main/java/org/apache/camel/component/netty/NettyClientBossPoolBuilder.java +++ b/components/camel-netty/src/main/java/org/apache/camel/component/netty/NettyClientBossPoolBuilder.java @@ -16,13 +16,16 @@ */ package org.apache.camel.component.netty; -import java.util.concurrent.Executor; +import java.util.Collections; +import java.util.Set; import java.util.concurrent.Executors; +import java.util.concurrent.TimeUnit; import org.jboss.netty.channel.socket.nio.BossPool; import org.jboss.netty.channel.socket.nio.NioClientBossPool; -import org.jboss.netty.util.ThreadNameDeterminer; +import org.jboss.netty.util.Timeout; import org.jboss.netty.util.Timer; +import org.jboss.netty.util.TimerTask; /** * A builder to create Netty {@link org.jboss.netty.channel.socket.nio.BossPool} which can be used for sharing boss pools @@ -34,6 +37,7 @@ public final class NettyClientBossPoolBuilder { private String pattern; private int bossCount = 1; private Timer timer; + private boolean stopTimer; public void setName(String name) { this.name = name; @@ -70,11 +74,43 @@ public final class NettyClientBossPoolBuilder { setTimer(timer); return this; } - + + public NettyClientBossPoolBuilder stopTimer() { + stopTimer = true; + return this; + } + /** * Creates a new boss pool. */ BossPool build() { - return new NioClientBossPool(Executors.newCachedThreadPool(), bossCount, timer, new CamelNettyThreadNameDeterminer(pattern, name)); + Timer internalTimer = timer; + if (!stopTimer) { + internalTimer = new UnstoppableTimer(timer); + } + return new NioClientBossPool(Executors.newCachedThreadPool(), bossCount, internalTimer, new CamelNettyThreadNameDeterminer(pattern, name)); + } + + // Here we don't close the timer, as the timer is passed from out side + class UnstoppableTimer implements Timer { + Timer delegateTimer; + UnstoppableTimer(Timer timer) { + delegateTimer = timer; + } + + public Timeout newTimeout(TimerTask task, long delay, TimeUnit unit) { + return delegateTimer.newTimeout(task, delay, unit); + } + + + @SuppressWarnings("unchecked") + public Set<Timeout> stop() { + // do nothing here; + return Collections.EMPTY_SET; + } + + + } + } http://git-wip-us.apache.org/repos/asf/camel/blob/7e51e5b4/components/camel-netty/src/main/java/org/apache/camel/component/netty/NettyServerBossPoolBuilder.java ---------------------------------------------------------------------- diff --git a/components/camel-netty/src/main/java/org/apache/camel/component/netty/NettyServerBossPoolBuilder.java b/components/camel-netty/src/main/java/org/apache/camel/component/netty/NettyServerBossPoolBuilder.java index 6404ae1..517bca0 100644 --- a/components/camel-netty/src/main/java/org/apache/camel/component/netty/NettyServerBossPoolBuilder.java +++ b/components/camel-netty/src/main/java/org/apache/camel/component/netty/NettyServerBossPoolBuilder.java @@ -16,12 +16,11 @@ */ package org.apache.camel.component.netty; -import java.util.concurrent.Executor; import java.util.concurrent.Executors; import org.jboss.netty.channel.socket.nio.BossPool; import org.jboss.netty.channel.socket.nio.NioServerBossPool; -import org.jboss.netty.util.ThreadNameDeterminer; + /** * A builder to create Netty {@link org.jboss.netty.channel.socket.nio.BossPool} which can be used for sharing boss pools http://git-wip-us.apache.org/repos/asf/camel/blob/7e51e5b4/components/camel-netty/src/main/java/org/apache/camel/component/netty/NettyWorkerPoolBuilder.java ---------------------------------------------------------------------- diff --git a/components/camel-netty/src/main/java/org/apache/camel/component/netty/NettyWorkerPoolBuilder.java b/components/camel-netty/src/main/java/org/apache/camel/component/netty/NettyWorkerPoolBuilder.java index c60cc25..c63c4a7 100644 --- a/components/camel-netty/src/main/java/org/apache/camel/component/netty/NettyWorkerPoolBuilder.java +++ b/components/camel-netty/src/main/java/org/apache/camel/component/netty/NettyWorkerPoolBuilder.java @@ -16,12 +16,10 @@ */ package org.apache.camel.component.netty; -import java.util.concurrent.Executor; import java.util.concurrent.Executors; import org.jboss.netty.channel.socket.nio.NioWorkerPool; import org.jboss.netty.channel.socket.nio.WorkerPool; -import org.jboss.netty.util.ThreadNameDeterminer; /** * A builder to create Netty {@link WorkerPool} which can be used for sharing worker pools