1 bytebuf已经被池化管理,在netty自带的decode、encode中自己会申请和释放bytebuf.
在外面使用bytebuf时,需要注意分配bytebuf时,还需要进行手工调用释放操作。
2 nett4的ServerBootstrap设置option采用的是childOption,而netty3直接使用setOption
3 IdleStateHandler.
netty4使用的读超时、写超时,没有使用时间轮,直接使用的是EventExecutor.
netty3使用了时间轮。
4 Netty4: MessageToMessageDecoder
Nett3: OneTonOneDecoder
4 channel
netty4中channel使用的是metadata,而netty3使用的是attachment.
5 ServerBootstrap
中的handler只处理tcp linsten和accept消息的处理。
childHandle只处理和每一个客户端连接socket。
tcp socket原理请参照http://wenwen.soso.com/z/q157314275.htm
6 码流日志
io.netty.handler.logging.LoggingHandler
7 在channel的pipline共用的对象需要声明sharable.否则会无法注册通道
i.e
ServerBootstrap serverBootstrap = new ServerBootstrap();
serverBootstrap.group(group)
.channel(NioServerSocketChannel.class)
.option(ChannelOption.SO_BACKLOG, 10)
.option(ChannelOption.SO_REUSEADDR, true)
.option(ChannelOption.TCP_NODELAY, true)
.childOption(ChannelOption.ALLOCATOR, PooledByteBufAllocator.DEFAULT)
.childHandler(new ChannelInitializer<SocketChannel>() {
@Override
protected void initChannel(SocketChannel socketChannel) throws Exception {
socketChannel.pipeline().addLast("frameDecoder", new LengthFieldBasedFrameDecoder(65536, 12, 2, 2, 0, false))
.addLast("packageCodec", codec)
.addLast("packageHandler", tcpMessageHandlerManager);
}
});
则codec和tcpMessageHandlerManager均 要声明@ChannelHandler.Sharable