Renamed DefaultReceiveBufferSizePredictor to AdaptiveReceiveBufferSizePredictor
Added FixedReceiveBufferSizePredictor
This commit is contained in:
parent
521f220aaa
commit
368c34ace9
@ -26,13 +26,14 @@ import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* The default {@link ReceiveBufferSizePredictor} implementation.
|
||||
* The {@link ReceiveBufferSizePredictor} that automatically increases and
|
||||
* decreases the predicted buffer size on feed back.
|
||||
* <p>
|
||||
* It gradually increases the expected number of readable bytes if the
|
||||
* previous read filled the allocated buffer. It gradually decreases the
|
||||
* expected number of readable bytes if the read operation was not able to
|
||||
* fill a certain amount of the allocated buffer two times consecutively.
|
||||
* Otherwise, it keeps returning the previous prediction.
|
||||
* It gradually increases the expected number of readable bytes if the previous
|
||||
* read filled the allocated buffer. It gradually decreases the expected number
|
||||
* of readable bytes if the read operation was not able to fill a certain amount
|
||||
* of the allocated buffer two times consecutively. Otherwise, it keeps
|
||||
* returning the previous prediction.
|
||||
*
|
||||
* @author The Netty Project (netty-dev@lists.jboss.org)
|
||||
* @author Trustin Lee (tlee@redhat.com)
|
||||
@ -40,7 +41,7 @@ import java.util.List;
|
||||
* @version $Rev$, $Date$
|
||||
*
|
||||
*/
|
||||
public class DefaultReceiveBufferSizePredictor implements
|
||||
public class AdaptiveReceiveBufferSizePredictor implements
|
||||
ReceiveBufferSizePredictor {
|
||||
|
||||
private static final int INDEX_INCREMENT = 4;
|
||||
@ -115,7 +116,7 @@ public class DefaultReceiveBufferSizePredictor implements
|
||||
* parameters, the expected buffer size starts from {@code 1024}, does not
|
||||
* go down below {@code 64}, and does not go up above {@code 65536}.
|
||||
*/
|
||||
public DefaultReceiveBufferSizePredictor() {
|
||||
public AdaptiveReceiveBufferSizePredictor() {
|
||||
this(DEFAULT_MINIMUM, DEFAULT_INITIAL, DEFAULT_MAXIMUM);
|
||||
}
|
||||
|
||||
@ -126,7 +127,7 @@ public class DefaultReceiveBufferSizePredictor implements
|
||||
* @param initial the initial buffer size when no feed back was received
|
||||
* @param maximum the inclusive upper bound of the expected buffer size
|
||||
*/
|
||||
public DefaultReceiveBufferSizePredictor(int minimum, int initial, int maximum) {
|
||||
public AdaptiveReceiveBufferSizePredictor(int minimum, int initial, int maximum) {
|
||||
if (minimum <= 0) {
|
||||
throw new IllegalArgumentException("minimum: " + minimum);
|
||||
}
|
@ -0,0 +1,59 @@
|
||||
/*
|
||||
* JBoss, Home of Professional Open Source
|
||||
*
|
||||
* Copyright 2008, Red Hat Middleware LLC, and individual contributors
|
||||
* by the @author tags. See the COPYRIGHT.txt in the distribution for a
|
||||
* full listing of individual contributors.
|
||||
*
|
||||
* This is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU Lesser General Public License as
|
||||
* published by the Free Software Foundation; either version 2.1 of
|
||||
* the License, or (at your option) any later version.
|
||||
*
|
||||
* This software is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this software; if not, write to the Free
|
||||
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
|
||||
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
|
||||
*/
|
||||
package org.jboss.netty.channel;
|
||||
|
||||
|
||||
/**
|
||||
* The {@link ReceiveBufferSizePredictor} that always yields the same buffer
|
||||
* size prediction.
|
||||
*
|
||||
* @author The Netty Project (netty-dev@lists.jboss.org)
|
||||
* @author Trustin Lee (tlee@redhat.com)
|
||||
*
|
||||
* @version $Rev$, $Date$
|
||||
*/
|
||||
public class FixedReceiveBufferSizePredictor implements
|
||||
ReceiveBufferSizePredictor {
|
||||
|
||||
private final int bufferSize;
|
||||
|
||||
/**
|
||||
* Creates a new predictor that always returns the same prediction of
|
||||
* the specified buffer size.
|
||||
*/
|
||||
public FixedReceiveBufferSizePredictor(int bufferSize) {
|
||||
if (bufferSize <= 0) {
|
||||
throw new IllegalArgumentException(
|
||||
"bufferSize must greater than 0: " + bufferSize);
|
||||
}
|
||||
this.bufferSize = bufferSize;
|
||||
}
|
||||
|
||||
public int nextReceiveBufferSize() {
|
||||
return bufferSize;
|
||||
}
|
||||
|
||||
public void previousReceiveBufferSize(int previousReceiveBufferSize) {
|
||||
// Ignore
|
||||
}
|
||||
}
|
@ -25,7 +25,7 @@ package org.jboss.netty.channel.socket.nio;
|
||||
import java.net.Socket;
|
||||
import java.util.Map;
|
||||
|
||||
import org.jboss.netty.channel.DefaultReceiveBufferSizePredictor;
|
||||
import org.jboss.netty.channel.AdaptiveReceiveBufferSizePredictor;
|
||||
import org.jboss.netty.channel.ReceiveBufferSizePredictor;
|
||||
import org.jboss.netty.channel.socket.DefaultSocketChannelConfig;
|
||||
import org.jboss.netty.logging.InternalLogger;
|
||||
@ -50,7 +50,7 @@ class DefaultNioSocketChannelConfig extends DefaultSocketChannelConfig
|
||||
private volatile int writeBufferHighWaterMark = 64 * 1024;
|
||||
private volatile int writeBufferLowWaterMark = 32 * 1024;
|
||||
private volatile ReceiveBufferSizePredictor predictor =
|
||||
new DefaultReceiveBufferSizePredictor();
|
||||
new AdaptiveReceiveBufferSizePredictor();
|
||||
private volatile int writeSpinCount = 16;
|
||||
|
||||
DefaultNioSocketChannelConfig(Socket socket) {
|
||||
|
@ -26,7 +26,7 @@ import java.nio.ByteBuffer;
|
||||
import java.nio.channels.WritableByteChannel;
|
||||
|
||||
import org.jboss.netty.channel.ChannelConfig;
|
||||
import org.jboss.netty.channel.DefaultReceiveBufferSizePredictor;
|
||||
import org.jboss.netty.channel.AdaptiveReceiveBufferSizePredictor;
|
||||
import org.jboss.netty.channel.ReceiveBufferSizePredictor;
|
||||
import org.jboss.netty.channel.socket.SocketChannel;
|
||||
import org.jboss.netty.channel.socket.SocketChannelConfig;
|
||||
@ -89,14 +89,14 @@ public interface NioSocketChannelConfig extends SocketChannelConfig {
|
||||
/**
|
||||
* Returns the {@link ReceiveBufferSizePredictor} which predicts the
|
||||
* number of readable bytes in the socket receive buffer. The default
|
||||
* predictor is {@link DefaultReceiveBufferSizePredictor}.
|
||||
* predictor is {@link AdaptiveReceiveBufferSizePredictor}.
|
||||
*/
|
||||
ReceiveBufferSizePredictor getReceiveBufferSizePredictor();
|
||||
|
||||
/**
|
||||
* Sets the {@link ReceiveBufferSizePredictor} which predicts the
|
||||
* number of readable bytes in the socket receive buffer. The default
|
||||
* predictor is {@link DefaultReceiveBufferSizePredictor}.
|
||||
* predictor is {@link AdaptiveReceiveBufferSizePredictor}.
|
||||
*/
|
||||
void setReceiveBufferSizePredictor(ReceiveBufferSizePredictor predictor);
|
||||
|
||||
|
@ -28,7 +28,7 @@ import java.util.Map.Entry;
|
||||
import org.jboss.netty.buffer.ChannelBufferFactory;
|
||||
import org.jboss.netty.buffer.HeapChannelBufferFactory;
|
||||
import org.jboss.netty.channel.ChannelPipelineFactory;
|
||||
import org.jboss.netty.channel.DefaultReceiveBufferSizePredictor;
|
||||
import org.jboss.netty.channel.AdaptiveReceiveBufferSizePredictor;
|
||||
import org.jboss.netty.channel.ReceiveBufferSizePredictor;
|
||||
import org.jboss.netty.logging.InternalLogger;
|
||||
import org.jboss.netty.logging.InternalLoggerFactory;
|
||||
@ -53,7 +53,7 @@ final class DefaultXnioChannelConfig implements XnioChannelConfig {
|
||||
private volatile int writeBufferHighWaterMark = 64 * 1024;
|
||||
private volatile int writeBufferLowWaterMark = 32 * 1024;
|
||||
private volatile ReceiveBufferSizePredictor predictor =
|
||||
new DefaultReceiveBufferSizePredictor();
|
||||
new AdaptiveReceiveBufferSizePredictor();
|
||||
private volatile int writeSpinCount = 16;
|
||||
|
||||
DefaultXnioChannelConfig() {
|
||||
|
@ -26,7 +26,7 @@ import java.nio.ByteBuffer;
|
||||
import java.nio.channels.WritableByteChannel;
|
||||
|
||||
import org.jboss.netty.channel.ChannelConfig;
|
||||
import org.jboss.netty.channel.DefaultReceiveBufferSizePredictor;
|
||||
import org.jboss.netty.channel.AdaptiveReceiveBufferSizePredictor;
|
||||
import org.jboss.netty.channel.ReceiveBufferSizePredictor;
|
||||
import org.jboss.netty.channel.socket.SocketChannelConfig;
|
||||
|
||||
@ -86,14 +86,14 @@ public interface XnioChannelConfig extends ChannelConfig {
|
||||
/**
|
||||
* Returns the {@link ReceiveBufferSizePredictor} which predicts the
|
||||
* number of readable bytes in the socket receive buffer. The default
|
||||
* predictor is {@link DefaultReceiveBufferSizePredictor}.
|
||||
* predictor is {@link AdaptiveReceiveBufferSizePredictor}.
|
||||
*/
|
||||
ReceiveBufferSizePredictor getReceiveBufferSizePredictor();
|
||||
|
||||
/**
|
||||
* Sets the {@link ReceiveBufferSizePredictor} which predicts the
|
||||
* number of readable bytes in the socket receive buffer. The default
|
||||
* predictor is {@link DefaultReceiveBufferSizePredictor}.
|
||||
* predictor is {@link AdaptiveReceiveBufferSizePredictor}.
|
||||
*/
|
||||
void setReceiveBufferSizePredictor(ReceiveBufferSizePredictor predictor);
|
||||
}
|
Loading…
Reference in New Issue
Block a user