Improved AbstractXnioChannelHandler to use ReceiveBufferSizePredictor
This commit is contained in:
parent
23b13eeafe
commit
49c0f33461
@ -11,8 +11,10 @@ import java.nio.channels.ScatteringByteChannel;
|
|||||||
import java.util.Queue;
|
import java.util.Queue;
|
||||||
|
|
||||||
import org.jboss.netty.buffer.ChannelBuffer;
|
import org.jboss.netty.buffer.ChannelBuffer;
|
||||||
|
import org.jboss.netty.buffer.ChannelBufferFactory;
|
||||||
import org.jboss.netty.buffer.ChannelBuffers;
|
import org.jboss.netty.buffer.ChannelBuffers;
|
||||||
import org.jboss.netty.channel.MessageEvent;
|
import org.jboss.netty.channel.MessageEvent;
|
||||||
|
import org.jboss.netty.channel.ReceiveBufferSizePredictor;
|
||||||
import org.jboss.xnio.IoHandler;
|
import org.jboss.xnio.IoHandler;
|
||||||
import org.jboss.xnio.channels.MultipointReadResult;
|
import org.jboss.xnio.channels.MultipointReadResult;
|
||||||
import org.jboss.xnio.channels.MultipointReadableMessageChannel;
|
import org.jboss.xnio.channels.MultipointReadableMessageChannel;
|
||||||
@ -39,8 +41,10 @@ public abstract class AbstractXnioChannelHandler implements IoHandler<java.nio.c
|
|||||||
|
|
||||||
boolean closed = false;
|
boolean closed = false;
|
||||||
|
|
||||||
// TODO: Use ReceiveBufferSizePredictor
|
ReceiveBufferSizePredictor predictor = c.getConfig().getReceiveBufferSizePredictor();
|
||||||
ChannelBuffer buf = c.getConfig().getBufferFactory().getBuffer(2048);
|
ChannelBufferFactory bufferFactory = c.getConfig().getBufferFactory();
|
||||||
|
ChannelBuffer buf = bufferFactory.getBuffer(predictor.nextReceiveBufferSize());
|
||||||
|
|
||||||
SocketAddress remoteAddress = null;
|
SocketAddress remoteAddress = null;
|
||||||
Throwable exception = null;
|
Throwable exception = null;
|
||||||
if (channel instanceof ScatteringByteChannel) {
|
if (channel instanceof ScatteringByteChannel) {
|
||||||
@ -86,8 +90,13 @@ public abstract class AbstractXnioChannelHandler implements IoHandler<java.nio.c
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (buf.readable()) {
|
if (buf.readable()) {
|
||||||
|
// Update the predictor.
|
||||||
|
predictor.previousReceiveBufferSize(buf.readableBytes());
|
||||||
|
|
||||||
|
// Fire the event.
|
||||||
fireMessageReceived(c, buf, remoteAddress);
|
fireMessageReceived(c, buf, remoteAddress);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (exception != null) {
|
if (exception != null) {
|
||||||
fireExceptionCaught(c, exception);
|
fireExceptionCaught(c, exception);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user