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 2011/12/04 14:56:39 UTC
svn commit: r1210113 - in /camel/trunk/components/camel-netty/src:
main/java/org/apache/camel/component/netty/
test/java/org/apache/camel/component/netty/
Author: ningjiang
Date: Sun Dec 4 13:56:39 2011
New Revision: 1210113
URL: http://svn.apache.org/viewvc?rev=1210113&view=rev
Log:
CAMEL-4737 Added ReceiveBufferSizePredictor option on the camel-netty uri
Added:
camel/trunk/components/camel-netty/src/test/java/org/apache/camel/component/netty/NettyUDPLargeMessageInOnlyTest.java (with props)
Modified:
camel/trunk/components/camel-netty/src/main/java/org/apache/camel/component/netty/NettyConfiguration.java
camel/trunk/components/camel-netty/src/main/java/org/apache/camel/component/netty/NettyConsumer.java
camel/trunk/components/camel-netty/src/test/java/org/apache/camel/component/netty/NettyComponentWithConfigurationTest.java
Modified: camel/trunk/components/camel-netty/src/main/java/org/apache/camel/component/netty/NettyConfiguration.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-netty/src/main/java/org/apache/camel/component/netty/NettyConfiguration.java?rev=1210113&r1=1210112&r2=1210113&view=diff
==============================================================================
--- camel/trunk/components/camel-netty/src/main/java/org/apache/camel/component/netty/NettyConfiguration.java (original)
+++ camel/trunk/components/camel-netty/src/main/java/org/apache/camel/component/netty/NettyConfiguration.java Sun Dec 4 13:56:39 2011
@@ -67,6 +67,7 @@ public class NettyConfiguration implemen
private boolean ssl;
private long sendBufferSize = 65536;
private long receiveBufferSize = 65536;
+ private int receiveBufferSizePredictor;
private int corePoolSize = 10;
private int maxPoolSize = 100;
private int workerCount;
@@ -351,6 +352,14 @@ public class NettyConfiguration implemen
public void setReceiveBufferSize(long receiveBufferSize) {
this.receiveBufferSize = receiveBufferSize;
}
+
+ public int getReceiveBufferSizePredictor() {
+ return receiveBufferSizePredictor;
+ }
+
+ public void setReceiveBufferSizePredictor(int receiveBufferSizePredictor) {
+ this.receiveBufferSizePredictor = receiveBufferSizePredictor;
+ }
public String getPassphrase() {
return passphrase;
Modified: camel/trunk/components/camel-netty/src/main/java/org/apache/camel/component/netty/NettyConsumer.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-netty/src/main/java/org/apache/camel/component/netty/NettyConsumer.java?rev=1210113&r1=1210112&r2=1210113&view=diff
==============================================================================
--- camel/trunk/components/camel-netty/src/main/java/org/apache/camel/component/netty/NettyConsumer.java (original)
+++ camel/trunk/components/camel-netty/src/main/java/org/apache/camel/component/netty/NettyConsumer.java Sun Dec 4 13:56:39 2011
@@ -26,6 +26,7 @@ import org.jboss.netty.bootstrap.Connect
import org.jboss.netty.bootstrap.ServerBootstrap;
import org.jboss.netty.channel.Channel;
import org.jboss.netty.channel.ChannelFactory;
+import org.jboss.netty.channel.FixedReceiveBufferSizePredictorFactory;
import org.jboss.netty.channel.group.ChannelGroup;
import org.jboss.netty.channel.group.ChannelGroupFuture;
import org.jboss.netty.channel.group.DefaultChannelGroup;
@@ -190,6 +191,11 @@ public class NettyConsumer extends Defau
connectionlessServerBootstrap.setOption("child.broadcast", configuration.isBroadcast());
connectionlessServerBootstrap.setOption("sendBufferSize", configuration.getSendBufferSize());
connectionlessServerBootstrap.setOption("receiveBufferSize", configuration.getReceiveBufferSize());
+ // only set this if user has specified
+ if (configuration.getReceiveBufferSizePredictor() > 0) {
+ connectionlessServerBootstrap.setOption("receiveBufferSizePredictorFactory",
+ new FixedReceiveBufferSizePredictorFactory(configuration.getReceiveBufferSizePredictor()));
+ }
channel = connectionlessServerBootstrap.bind(new InetSocketAddress(configuration.getHost(), configuration.getPort()));
// to keep track of all channels in use
Modified: camel/trunk/components/camel-netty/src/test/java/org/apache/camel/component/netty/NettyComponentWithConfigurationTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-netty/src/test/java/org/apache/camel/component/netty/NettyComponentWithConfigurationTest.java?rev=1210113&r1=1210112&r2=1210113&view=diff
==============================================================================
--- camel/trunk/components/camel-netty/src/test/java/org/apache/camel/component/netty/NettyComponentWithConfigurationTest.java (original)
+++ camel/trunk/components/camel-netty/src/test/java/org/apache/camel/component/netty/NettyComponentWithConfigurationTest.java Sun Dec 4 13:56:39 2011
@@ -39,6 +39,10 @@ public class NettyComponentWithConfigura
// should not be same
assertNotSame(e1, e2);
assertNotSame(e1.getConfiguration(), e2.getConfiguration());
+
+ assertEquals(0, e2.getConfiguration().getReceiveBufferSizePredictor());
+ e2.getConfiguration().setReceiveBufferSizePredictor(1024);
+ assertEquals(1024, e2.getConfiguration().getReceiveBufferSizePredictor());
e2.getConfiguration().setPort(5566);
Added: camel/trunk/components/camel-netty/src/test/java/org/apache/camel/component/netty/NettyUDPLargeMessageInOnlyTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-netty/src/test/java/org/apache/camel/component/netty/NettyUDPLargeMessageInOnlyTest.java?rev=1210113&view=auto
==============================================================================
--- camel/trunk/components/camel-netty/src/test/java/org/apache/camel/component/netty/NettyUDPLargeMessageInOnlyTest.java (added)
+++ camel/trunk/components/camel-netty/src/test/java/org/apache/camel/component/netty/NettyUDPLargeMessageInOnlyTest.java Sun Dec 4 13:56:39 2011
@@ -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.netty;
+
+import org.apache.camel.Exchange;
+import org.apache.camel.Processor;
+import org.apache.camel.builder.RouteBuilder;
+import org.junit.Test;
+
+public class NettyUDPLargeMessageInOnlyTest extends BaseNettyTest {
+
+ private byte[] getMessageBytes(int messageSize) {
+ byte[] msgBytes = new byte[messageSize];
+ for (int i = 0; i < messageSize; i++) {
+ msgBytes[i] = 'A';
+ }
+ return msgBytes;
+ }
+
+ private void sendMessage(int messageSize) throws Exception {
+ byte[] msgBytes = getMessageBytes(messageSize);
+
+ assertEquals(msgBytes.length, messageSize);
+ String message = new String(msgBytes);
+
+ getMockEndpoint("mock:result").expectedBodiesReceived(message);
+ template.sendBody("netty:udp://localhost:{{port}}?sync=false", message);
+ assertMockEndpointsSatisfied();
+ }
+
+ @Test
+ public void testSend512Message() throws Exception {
+ sendMessage(512);
+ }
+
+ @Test
+ public void testSend768Message() throws Exception {
+ sendMessage(768);
+ }
+
+ @Test
+ public void testSend1024Message() throws Exception {
+ sendMessage(1024);
+ }
+
+ @Override
+ protected RouteBuilder createRouteBuilder() throws Exception {
+ return new RouteBuilder() {
+ @Override
+ public void configure() throws Exception {
+ from("netty:udp://localhost:{{port}}?receiveBufferSizePredictor=2048&sync=false")
+ .to("mock:result");
+ }
+ };
+ }
+}
Propchange: camel/trunk/components/camel-netty/src/test/java/org/apache/camel/component/netty/NettyUDPLargeMessageInOnlyTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: camel/trunk/components/camel-netty/src/test/java/org/apache/camel/component/netty/NettyUDPLargeMessageInOnlyTest.java
------------------------------------------------------------------------------
svn:keywords = Rev Date