netty-基本类

SimpleChannelInboundHandler channelInactive userEventTriggered channelRead0

ChannelInitializer

SpringBeanFactory

@Component @PostConstruct @PreDestroy

IdleStateHandler

HeartbeatDecoder ByteToMessageDecoder

@Configuration


ChannelRead channelRead0 messageReceived


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.*

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

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

转载于:https://my.oschina.net/u/864135/blog/2088165

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值