netty-基本類

SimpleChannelInboundHandler channelInactive userEventTriggered channelRead0bootstrap

ChannelInitializer緩存

SpringBeanFactory.net

@Component @PostConstruct @PreDestroynetty

IdleStateHandlercode

HeartbeatDecoder ByteToMessageDecoder事件

@Configuration內存


ChannelRead channelRead0 messageReceivedget


org.jboss.netty.bootstrap.; First, in Netty 3.X the packages were from org.jboss.netty. io.netty.bootstrap.ServerBootstrap; But started Netty 4.X the packeages are from io.netty.*it

Now, if you are using Netty 4.X to read message use the methodio

ChannelRead(ChannelHandleContext ctx, Object msg) { ... } inherited from ChannelInboundHandlerAdapter class. The method:

messageReceived(ChannelHandlerContext, I) { ...} was used in Netty 3.X version.

ByteBuf ByteBuf buf = Unpooled.buffer();

池化buffer Netty4引入了一種高效緩存池(buffer pool),它是結合了 buddy allocation 以及 slab allocation 的 jemalloc 的變體。

減少buffer的頻繁分配及回收致使的GC壓力 減小新建buffer時0值填充產生的內存帶寬消耗 及時回收直接內存(direct buffers) 爲了能夠利用這些特性,用戶都應該使用 ByteBufAllocator 獲取buffer,除非你但願使用非池化buffer:

Channel channel = ...; ByteBufAllocator alloc = channel.alloc(); ByteBuf buf = alloc.buffer(512);

ChannelInboundHandlerAdapter channelRead (ChannelHandlerContext ctx, Object msg) channelReadComplete(ChannelHandlerContext ctx) exceptionCaught(ChannelHandlerContext ctx, Throwable cause)

Netty的核心組件 在本節中我將要討論Netty的主要構件塊: Channel; 回調; Future; 事件和ChannelHandler。 ChannelFutureListener ChannelFuture

相關文章
相關標籤/搜索