You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by ni...@apache.org on 2014/12/01 05:59:27 UTC

[2/2] camel git commit: CAMEL-8094 Do not stop the timer in NettyClientBossPoolBuilder

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/2883bbfe
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/2883bbfe
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/2883bbfe

Branch: refs/heads/camel-2.13.x
Commit: 2883bbfef2514cf50bbd98569275c2d4e7fe873b
Parents: 9df6d8f
Author: Willem Jiang <wi...@gmail.com>
Authored: Mon Dec 1 12:56:27 2014 +0800
Committer: Willem Jiang <wi...@gmail.com>
Committed: Mon Dec 1 12:59:05 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/2883bbfe/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 6025840..e4164e1 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 boos 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/2883bbfe/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 6f45dc2..486391e 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 boos pools

http://git-wip-us.apache.org/repos/asf/camel/blob/2883bbfe/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 229040d..21abd07 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