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 2010/07/26 15:32:43 UTC

svn commit: r979276 - in /camel/trunk/components/camel-netty/src/main/java/org/apache/camel/component/netty: ClientPipelineFactory.java NettyComponent.java NettyEndpoint.java

Author: davsclaus
Date: Mon Jul 26 13:32:42 2010
New Revision: 979276

URL: http://svn.apache.org/viewvc?rev=979276&view=rev
Log:
CAMEL-2978: Fixed camel-netty eating up memory due using a new timer instead of a global shared. Thanks to Sean for reporting.

Modified:
    camel/trunk/components/camel-netty/src/main/java/org/apache/camel/component/netty/ClientPipelineFactory.java
    camel/trunk/components/camel-netty/src/main/java/org/apache/camel/component/netty/NettyComponent.java
    camel/trunk/components/camel-netty/src/main/java/org/apache/camel/component/netty/NettyEndpoint.java

Modified: camel/trunk/components/camel-netty/src/main/java/org/apache/camel/component/netty/ClientPipelineFactory.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-netty/src/main/java/org/apache/camel/component/netty/ClientPipelineFactory.java?rev=979276&r1=979275&r2=979276&view=diff
==============================================================================
--- camel/trunk/components/camel-netty/src/main/java/org/apache/camel/component/netty/ClientPipelineFactory.java (original)
+++ camel/trunk/components/camel-netty/src/main/java/org/apache/camel/component/netty/ClientPipelineFactory.java Mon Jul 26 13:32:42 2010
@@ -33,8 +33,6 @@ import org.jboss.netty.channel.ChannelUp
 import org.jboss.netty.channel.Channels;
 import org.jboss.netty.handler.ssl.SslHandler;
 import org.jboss.netty.handler.timeout.ReadTimeoutHandler;
-import org.jboss.netty.util.HashedWheelTimer;
-import org.jboss.netty.util.Timer;
 
 public class ClientPipelineFactory implements ChannelPipelineFactory {
     private static final transient Log LOG = LogFactory.getLog(ClientPipelineFactory.class);
@@ -48,7 +46,7 @@ public class ClientPipelineFactory imple
         this.callback = callback;
     }
 
-    public ChannelPipeline getPipeline() throws Exception {
+    public synchronized ChannelPipeline getPipeline() throws Exception {
         // create a new pipeline
         ChannelPipeline channelPipeline = Channels.pipeline();
 
@@ -62,8 +60,7 @@ public class ClientPipelineFactory imple
 
         // use read timeout handler to handle timeout while waiting for a remote reply (while reading from the remote host)
         if (producer.getConfiguration().getTimeout() > 0) {
-            Timer timer = new HashedWheelTimer();
-            channelPipeline.addLast("timeout", new ReadTimeoutHandler(timer, producer.getConfiguration().getTimeout(), TimeUnit.MILLISECONDS));
+            channelPipeline.addLast("timeout", new ReadTimeoutHandler(producer.getEndpoint().getTimer(), producer.getConfiguration().getTimeout(), TimeUnit.MILLISECONDS));
         }
 
         List<ChannelUpstreamHandler> decoders = producer.getConfiguration().getDecoders();

Modified: camel/trunk/components/camel-netty/src/main/java/org/apache/camel/component/netty/NettyComponent.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-netty/src/main/java/org/apache/camel/component/netty/NettyComponent.java?rev=979276&r1=979275&r2=979276&view=diff
==============================================================================
--- camel/trunk/components/camel-netty/src/main/java/org/apache/camel/component/netty/NettyComponent.java (original)
+++ camel/trunk/components/camel-netty/src/main/java/org/apache/camel/component/netty/NettyComponent.java Mon Jul 26 13:32:42 2010
@@ -22,8 +22,12 @@ import java.util.Map;
 import org.apache.camel.CamelContext;
 import org.apache.camel.Endpoint;
 import org.apache.camel.impl.DefaultComponent;
+import org.jboss.netty.util.HashedWheelTimer;
+import org.jboss.netty.util.Timer;
 
 public class NettyComponent extends DefaultComponent {
+    // use a shared timer for Netty (see javadoc for HashedWheelTimer)
+    private static volatile Timer timer;
     private NettyConfiguration configuration;
 
     public NettyComponent() {
@@ -43,8 +47,9 @@ public class NettyComponent extends Defa
         }
 
         config.parseURI(new URI(remaining), parameters, this);
-        
+
         NettyEndpoint nettyEndpoint = new NettyEndpoint(remaining, this, config);
+        nettyEndpoint.setTimer(getTimer());
         setProperties(nettyEndpoint.getConfiguration(), parameters);
         return nettyEndpoint;
     }
@@ -56,4 +61,24 @@ public class NettyComponent extends Defa
     public void setConfiguration(NettyConfiguration configuration) {
         this.configuration = configuration;
     }
+
+    public static Timer getTimer() {
+        return timer;
+    }
+
+    @Override
+    protected void doStart() throws Exception {
+        if (timer == null) {
+            timer = new HashedWheelTimer();
+        }
+        super.doStart();
+    }
+
+    @Override
+    protected void doStop() throws Exception {
+        timer.stop();
+        timer = null;
+        super.doStop();
+    }
+
 }
\ No newline at end of file

Modified: camel/trunk/components/camel-netty/src/main/java/org/apache/camel/component/netty/NettyEndpoint.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-netty/src/main/java/org/apache/camel/component/netty/NettyEndpoint.java?rev=979276&r1=979275&r2=979276&view=diff
==============================================================================
--- camel/trunk/components/camel-netty/src/main/java/org/apache/camel/component/netty/NettyEndpoint.java (original)
+++ camel/trunk/components/camel-netty/src/main/java/org/apache/camel/component/netty/NettyEndpoint.java Mon Jul 26 13:32:42 2010
@@ -22,13 +22,17 @@ import org.apache.camel.Exchange;
 import org.apache.camel.Processor;
 import org.apache.camel.Producer;
 import org.apache.camel.impl.DefaultEndpoint;
+import org.apache.camel.util.ObjectHelper;
 import org.jboss.netty.channel.ChannelHandlerContext;
 import org.jboss.netty.channel.MessageEvent;
+import org.jboss.netty.util.HashedWheelTimer;
+import org.jboss.netty.util.Timer;
 
 public class NettyEndpoint extends DefaultEndpoint {
     private NettyConfiguration configuration;
+    private Timer timer;
 
-    public NettyEndpoint(String endpointUri, Component component, NettyConfiguration configuration) {
+    public NettyEndpoint(String endpointUri, NettyComponent component, NettyConfiguration configuration) {
         super(endpointUri, component);
         this.configuration = configuration;
     }
@@ -62,5 +66,18 @@ public class NettyEndpoint extends Defau
         this.configuration = configuration;
     }
 
-    
+    public void setTimer(Timer timer) {
+        this.timer = timer;
+    }
+
+    public Timer getTimer() {
+        return timer;
+    }
+
+    @Override
+    public void start() throws Exception {
+        super.start();
+        ObjectHelper.notNull(timer, "timer");
+    }
+
 }
\ No newline at end of file