Use proper buffer factory in OioWorker
Removed unnecessary local variables in OioDatagramWorker
This commit is contained in:
parent
c7c2c71935
commit
b859f120d8
@ -24,7 +24,6 @@ import java.net.SocketAddress;
|
|||||||
import java.nio.ByteBuffer;
|
import java.nio.ByteBuffer;
|
||||||
|
|
||||||
import org.jboss.netty.buffer.ChannelBuffer;
|
import org.jboss.netty.buffer.ChannelBuffer;
|
||||||
import org.jboss.netty.buffer.ChannelBufferFactory;
|
|
||||||
import org.jboss.netty.channel.Channel;
|
import org.jboss.netty.channel.Channel;
|
||||||
import org.jboss.netty.channel.ChannelFuture;
|
import org.jboss.netty.channel.ChannelFuture;
|
||||||
import org.jboss.netty.channel.ReceiveBufferSizePredictor;
|
import org.jboss.netty.channel.ReceiveBufferSizePredictor;
|
||||||
@ -66,9 +65,6 @@ class OioDatagramWorker implements Runnable {
|
|||||||
|
|
||||||
ReceiveBufferSizePredictor predictor =
|
ReceiveBufferSizePredictor predictor =
|
||||||
channel.getConfig().getReceiveBufferSizePredictor();
|
channel.getConfig().getReceiveBufferSizePredictor();
|
||||||
ChannelBufferFactory bufferFactory =
|
|
||||||
channel.getConfig().getBufferFactory();
|
|
||||||
|
|
||||||
|
|
||||||
byte[] buf = new byte[predictor.nextReceiveBufferSize()];
|
byte[] buf = new byte[predictor.nextReceiveBufferSize()];
|
||||||
DatagramPacket packet = new DatagramPacket(buf, buf.length);
|
DatagramPacket packet = new DatagramPacket(buf, buf.length);
|
||||||
@ -87,7 +83,7 @@ class OioDatagramWorker implements Runnable {
|
|||||||
|
|
||||||
fireMessageReceived(
|
fireMessageReceived(
|
||||||
channel,
|
channel,
|
||||||
bufferFactory.getBuffer(buf, 0, packet.getLength()),
|
channel.getConfig().getBufferFactory().getBuffer(buf, 0, packet.getLength()),
|
||||||
packet.getSocketAddress());
|
packet.getSocketAddress());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -24,7 +24,6 @@ import java.nio.channels.ClosedChannelException;
|
|||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
import org.jboss.netty.buffer.ChannelBuffer;
|
import org.jboss.netty.buffer.ChannelBuffer;
|
||||||
import org.jboss.netty.buffer.ChannelBuffers;
|
|
||||||
import org.jboss.netty.channel.Channel;
|
import org.jboss.netty.channel.Channel;
|
||||||
import org.jboss.netty.channel.ChannelFuture;
|
import org.jboss.netty.channel.ChannelFuture;
|
||||||
|
|
||||||
@ -88,15 +87,9 @@ class OioWorker implements Runnable {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
ChannelBuffer buffer;
|
fireMessageReceived(
|
||||||
if (readBytes == buf.length) {
|
channel,
|
||||||
buffer = ChannelBuffers.wrappedBuffer(buf);
|
channel.getConfig().getBufferFactory().getBuffer(buf, 0, readBytes));
|
||||||
} else {
|
|
||||||
// A rare case, but it sometimes happen.
|
|
||||||
buffer = ChannelBuffers.wrappedBuffer(buf, 0, readBytes);
|
|
||||||
}
|
|
||||||
|
|
||||||
fireMessageReceived(channel, buffer);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Setting the workerThread to null will prevent any channel
|
// Setting the workerThread to null will prevent any channel
|
||||||
|
Loading…
Reference in New Issue
Block a user