* Added receiveBufferSizePredictor property to DatagramChannelConfig

* The default predictor for DatagramChannel is FixedReceiveSizePredictor(768) which should work for most cases
This commit is contained in:
Trustin Lee 2009-03-12 13:17:30 +00:00
parent d33e38e626
commit 5754d9d87f
2 changed files with 20 additions and 0 deletions

View File

@ -27,6 +27,7 @@ import java.net.InetAddress;
import java.net.NetworkInterface;
import org.jboss.netty.channel.ChannelConfig;
import org.jboss.netty.channel.ReceiveBufferSizePredictor;
/**
* A {@link ChannelConfig} for a {@link DatagramChannel}.
@ -52,6 +53,8 @@ import org.jboss.netty.channel.ChannelConfig;
* </tr><tr>
* <td>{@code "receiveBufferSize"}</td><td>{@link #setReceiveBufferSize(int)}</td>
* </tr><tr>
* <td>{@code "receiveBufferSizePredictor"}</td><td>{@link #setReceiveBufferSizePredictor(ReceiveBufferSizePredictor)}</td>
* </tr><tr>
* <td>{@code "sendBufferSize"}</td><td>{@link #setSendBufferSize(int)}</td>
* </tr><tr>
* <td>{@code "timeToLive"}</td><td>{@link #setTimeToLive(int)}</td>
@ -127,4 +130,6 @@ public interface DatagramChannelConfig extends ChannelConfig {
NetworkInterface getNetworkInterface();
void setNetworkInterface(NetworkInterface networkInterface);
ReceiveBufferSizePredictor getReceiveBufferSizePredictor();
void setReceiveBufferSizePredictor(ReceiveBufferSizePredictor predictor);
}

View File

@ -31,6 +31,8 @@ import java.net.SocketException;
import org.jboss.netty.channel.ChannelException;
import org.jboss.netty.channel.DefaultChannelConfig;
import org.jboss.netty.channel.FixedReceiveBufferSizePredictor;
import org.jboss.netty.channel.ReceiveBufferSizePredictor;
import org.jboss.netty.util.ConversionUtil;
/**
@ -46,6 +48,8 @@ public class DefaultDatagramChannelConfig extends DefaultChannelConfig
implements DatagramChannelConfig {
private final DatagramSocket socket;
private volatile ReceiveBufferSizePredictor predictor =
new FixedReceiveBufferSizePredictor(768);
/**
* Creates a new instance.
@ -254,4 +258,15 @@ public class DefaultDatagramChannelConfig extends DefaultChannelConfig
throw new ChannelException(e);
}
}
public ReceiveBufferSizePredictor getReceiveBufferSizePredictor() {
return predictor;
}
public void setReceiveBufferSizePredictor(ReceiveBufferSizePredictor predictor) {
if (predictor == null) {
throw new NullPointerException("predictor");
}
this.predictor = predictor;
}
}