Remove unused configuration properties and their related classes

This commit is contained in:
Trustin Lee 2012-05-01 17:53:38 +09:00
parent c34d63d159
commit f4423ac555
7 changed files with 2 additions and 441 deletions

View File

@ -1,167 +0,0 @@
/*
* Copyright 2011 The Netty Project
*
* The Netty Project 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 io.netty.channel;
import java.util.ArrayList;
import java.util.List;
/**
* 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 fully 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 same prediction.
*/
public class AdaptiveReceiveBufferSizePredictor implements
ReceiveBufferSizePredictor {
static final int DEFAULT_MINIMUM = 64;
static final int DEFAULT_INITIAL = 1024;
static final int DEFAULT_MAXIMUM = 65536;
private static final int INDEX_INCREMENT = 4;
private static final int INDEX_DECREMENT = 1;
private static final int[] SIZE_TABLE;
static {
List<Integer> sizeTable = new ArrayList<Integer>();
for (int i = 1; i <= 8; i ++) {
sizeTable.add(i);
}
for (int i = 4; i < 32; i ++) {
long v = 1L << i;
long inc = v >>> 4;
v -= inc << 3;
for (int j = 0; j < 8; j ++) {
v += inc;
if (v > Integer.MAX_VALUE) {
sizeTable.add(Integer.MAX_VALUE);
} else {
sizeTable.add((int) v);
}
}
}
SIZE_TABLE = new int[sizeTable.size()];
for (int i = 0; i < SIZE_TABLE.length; i ++) {
SIZE_TABLE[i] = sizeTable.get(i);
}
}
private static int getSizeTableIndex(final int size) {
if (size <= 16) {
return size - 1;
}
int bits = 0;
int v = size;
do {
v >>>= 1;
bits ++;
} while (v != 0);
final int baseIdx = bits << 3;
final int startIdx = baseIdx - 18;
final int endIdx = baseIdx - 25;
for (int i = startIdx; i >= endIdx; i --) {
if (size >= SIZE_TABLE[i]) {
return i;
}
}
throw new Error("shouldn't reach here; please file a bug report.");
}
private final int minIndex;
private final int maxIndex;
private int index;
private int nextReceiveBufferSize;
private boolean decreaseNow;
/**
* Creates a new predictor with the default parameters. With the default
* 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 AdaptiveReceiveBufferSizePredictor() {
this(DEFAULT_MINIMUM, DEFAULT_INITIAL, DEFAULT_MAXIMUM);
}
/**
* Creates a new predictor with the specified parameters.
*
* @param minimum the inclusive lower bound of the expected buffer size
* @param initial the initial buffer size when no feed back was received
* @param maximum the inclusive upper bound of the expected buffer size
*/
public AdaptiveReceiveBufferSizePredictor(int minimum, int initial, int maximum) {
if (minimum <= 0) {
throw new IllegalArgumentException("minimum: " + minimum);
}
if (initial < minimum) {
throw new IllegalArgumentException("initial: " + initial);
}
if (maximum < initial) {
throw new IllegalArgumentException("maximum: " + maximum);
}
int minIndex = getSizeTableIndex(minimum);
if (SIZE_TABLE[minIndex] < minimum) {
this.minIndex = minIndex + 1;
} else {
this.minIndex = minIndex;
}
int maxIndex = getSizeTableIndex(maximum);
if (SIZE_TABLE[maxIndex] > maximum) {
this.maxIndex = maxIndex - 1;
} else {
this.maxIndex = maxIndex;
}
index = getSizeTableIndex(initial);
nextReceiveBufferSize = SIZE_TABLE[index];
}
@Override
public int nextReceiveBufferSize() {
return nextReceiveBufferSize;
}
@Override
public void previousReceiveBufferSize(int previousReceiveBufferSize) {
if (previousReceiveBufferSize <= SIZE_TABLE[Math.max(0, index - INDEX_DECREMENT - 1)]) {
if (decreaseNow) {
index = Math.max(index - INDEX_DECREMENT, minIndex);
nextReceiveBufferSize = SIZE_TABLE[index];
decreaseNow = false;
} else {
decreaseNow = true;
}
} else if (previousReceiveBufferSize >= nextReceiveBufferSize) {
index = Math.min(index + INDEX_INCREMENT, maxIndex);
nextReceiveBufferSize = SIZE_TABLE[index];
decreaseNow = false;
}
}
}

View File

@ -1,68 +0,0 @@
/*
* Copyright 2011 The Netty Project
*
* The Netty Project 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 io.netty.channel;
/**
* The {@link ReceiveBufferSizePredictorFactory} that creates a new
* {@link AdaptiveReceiveBufferSizePredictor}.
*/
public class AdaptiveReceiveBufferSizePredictorFactory implements
ReceiveBufferSizePredictorFactory {
private final int minimum;
private final int initial;
private final int maximum;
/**
* Creates a new factory with the default parameters. With the default
* 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 AdaptiveReceiveBufferSizePredictorFactory() {
this(AdaptiveReceiveBufferSizePredictor.DEFAULT_MINIMUM,
AdaptiveReceiveBufferSizePredictor.DEFAULT_INITIAL,
AdaptiveReceiveBufferSizePredictor.DEFAULT_MAXIMUM);
}
/**
* Creates a new factory with the specified parameters.
*
* @param minimum the inclusive lower bound of the expected buffer size
* @param initial the initial buffer size when no feed back was received
* @param maximum the inclusive upper bound of the expected buffer size
*/
public AdaptiveReceiveBufferSizePredictorFactory(int minimum, int initial, int maximum) {
if (minimum <= 0) {
throw new IllegalArgumentException("minimum: " + minimum);
}
if (initial < minimum) {
throw new IllegalArgumentException("initial: " + initial);
}
if (maximum < initial) {
throw new IllegalArgumentException("maximum: " + maximum);
}
this.minimum = minimum;
this.initial = initial;
this.maximum = maximum;
}
@Override
public ReceiveBufferSizePredictor getPredictor() throws Exception {
return new AdaptiveReceiveBufferSizePredictor(minimum, initial, maximum);
}
}

View File

@ -15,15 +15,12 @@
*/
package io.netty.channel;
import java.nio.ByteOrder;
import java.util.Map;
import io.netty.buffer.ChannelBuffer;
import io.netty.buffer.ChannelBufferFactory;
import io.netty.buffer.HeapChannelBufferFactory;
import io.netty.channel.socket.SocketChannelConfig;
import io.netty.channel.socket.nio.NioSocketChannelConfig;
import java.util.Map;
/**
* A set of configuration properties of a {@link Channel}.
* <p>
@ -93,38 +90,6 @@ public interface ChannelConfig {
*/
boolean setOption(String name, Object value);
/**
* Returns the default {@link ChannelBufferFactory} used to create a new
* {@link ChannelBuffer}. The default is {@link HeapChannelBufferFactory}.
* You can specify a different factory to change the default
* {@link ByteOrder} for example.
*/
ChannelBufferFactory getBufferFactory();
/**
* Sets the default {@link ChannelBufferFactory} used to create a new
* {@link ChannelBuffer}. The default is {@link HeapChannelBufferFactory}.
* You can specify a different factory to change the default
* {@link ByteOrder} for example.
*/
void setBufferFactory(ChannelBufferFactory bufferFactory);
/**
* Returns the {@link ChannelPipelineFactory} which will be used when
* a child channel is created. If the {@link Channel} does not create
* a child channel, this property is not used at all, and therefore will
* be ignored.
*/
ChannelPipelineFactory getPipelineFactory();
/**
* Sets the {@link ChannelPipelineFactory} which will be used when
* a child channel is created. If the {@link Channel} does not create
* a child channel, this property is not used at all, and therefore will
* be ignored.
*/
void setPipelineFactory(ChannelPipelineFactory pipelineFactory);
/**
* Returns the connect timeout of the channel in milliseconds. If the
* {@link Channel} does not support connect operation, this property is not

View File

@ -1,49 +0,0 @@
/*
* Copyright 2011 The Netty Project
*
* The Netty Project 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 io.netty.channel;
/**
* The {@link ReceiveBufferSizePredictor} that always yields the same buffer
* size prediction. This predictor ignores the feed back from the I/O thread.
*/
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;
}
@Override
public int nextReceiveBufferSize() {
return bufferSize;
}
@Override
public void previousReceiveBufferSize(int previousReceiveBufferSize) {
// Ignore
}
}

View File

@ -1,40 +0,0 @@
/*
* Copyright 2011 The Netty Project
*
* The Netty Project 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 io.netty.channel;
/**
* The {@link ReceiveBufferSizePredictorFactory} that returns a
* {@link FixedReceiveBufferSizePredictor} with the pre-defined configuration.
*/
public class FixedReceiveBufferSizePredictorFactory implements
ReceiveBufferSizePredictorFactory {
private final ReceiveBufferSizePredictor predictor;
/**
* Creates a new factory that returns a {@link FixedReceiveBufferSizePredictor}
* which always returns the same prediction of the specified buffer size.
*/
public FixedReceiveBufferSizePredictorFactory(int bufferSize) {
predictor = new FixedReceiveBufferSizePredictor(bufferSize);
}
@Override
public ReceiveBufferSizePredictor getPredictor() throws Exception {
return predictor;
}
}

View File

@ -1,52 +0,0 @@
/*
* Copyright 2011 The Netty Project
*
* The Netty Project 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 io.netty.channel;
import io.netty.buffer.ChannelBuffer;
/**
* Predicts the number of readable bytes in the receive buffer of a
* {@link Channel}.
* <p>
* It calculates the close-to-optimal capacity of the {@link ChannelBuffer}
* for the next read operation depending on the actual number of read bytes
* in the previous read operation. More accurate the prediction is, more
* effective the memory utilization will be.
* <p>
* Once a read operation is performed and the actual number of read bytes is
* known, an I/O thread will call {@link #previousReceiveBufferSize(int)} to
* update the predictor so it can predict more accurately next time.
*/
public interface ReceiveBufferSizePredictor {
/**
* Predicts the capacity of the {@link ChannelBuffer} for the next
* read operation depending on the actual number of read bytes in the
* previous read operation.
*
* @return the expected number of readable bytes this time
*/
int nextReceiveBufferSize();
/**
* Updates this predictor by specifying the actual number of read bytes
* in the previous read operation.
*
* @param previousReceiveBufferSize
* the actual number of read bytes in the previous read operation
*/
void previousReceiveBufferSize(int previousReceiveBufferSize);
}

View File

@ -1,28 +0,0 @@
/*
* Copyright 2011 The Netty Project
*
* The Netty Project 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 io.netty.channel;
/**
* Creates a new {@link ReceiveBufferSizePredictor}.
* @apiviz.has io.netty.channel.ReceiveBufferSizePredictor oneway - - creates
*/
public interface ReceiveBufferSizePredictorFactory {
/**
* Returns a newly created {@link ReceiveBufferSizePredictor}.
*/
ReceiveBufferSizePredictor getPredictor() throws Exception;
}