首页  

netty代码debug切入点     所属分类 netty 浏览量 1286
断点
NioEventLoop.run()    事件循环 捕捉事件

ChannelInitializer  initChannel
客户端连接成功 创建channel 时  , 添加 handler 到 pipeline


PooledByteBufAllocator
newDirectBuffer 
newHeapBuffer 

读写都要创建 ByteBuf  一般使用 newDirectBuffer



 PooledByteBufAllocator跟踪调试 



ChannelInitializer  initChannel


Thread [nioEventLoopGroup-4-1] (Suspended (breakpoint at line 18 in EchoServerInit))	
	EchoServerInit.initChannel(SocketChannel) line: 18	
	EchoServerInit.initChannel(Channel) line: 1	
	EchoServerInit(ChannelInitializer<C>).channelRegistered(ChannelHandlerContext) line: 69	
	DefaultChannelHandlerContext.invokeChannelRegistered() line: 165	
	DefaultChannelHandlerContext.fireChannelRegistered() line: 151	
	DefaultChannelPipeline.fireChannelRegistered() line: 730	
	AbstractNioByteChannel$NioByteUnsafe(AbstractChannel$AbstractUnsafe).register0(ChannelPromise) line: 442	
	AbstractNioByteChannel$NioByteUnsafe(AbstractChannel$AbstractUnsafe).register(EventLoop, ChannelPromise) line: 412	
	NioEventLoop(SingleThreadEventLoop).register(Channel, ChannelPromise) line: 60	
	NioEventLoop(SingleThreadEventLoop).register(Channel) line: 48	
	NioEventLoopGroup(MultithreadEventLoopGroup).register(Channel) line: 64	
	ServerBootstrap$ServerBootstrapAcceptor.channelRead(ChannelHandlerContext, Object) line: 252	
	DefaultChannelHandlerContext.invokeChannelRead(Object) line: 340	
	DefaultChannelHandlerContext.fireChannelRead(Object) line: 326	
	LoggingHandler.channelRead(ChannelHandlerContext, Object) line: 283	
	DefaultChannelHandlerContext.invokeChannelRead(Object) line: 340	
	DefaultChannelHandlerContext.fireChannelRead(Object) line: 326	
	DefaultChannelPipeline.fireChannelRead(Object) line: 785	
	AbstractNioMessageChannel$NioMessageUnsafe.read() line: 95	
	NioEventLoop.processSelectedKey(SelectionKey, AbstractNioChannel) line: 494	
	NioEventLoop.processSelectedKeysOptimized(SelectionKey[]) line: 461	
	NioEventLoop.processSelectedKeys() line: 378	
	NioEventLoop.run() line: 350	
	SingleThreadEventExecutor$2.run() line: 101	
	Thread.run() line: 745	


private static void processSelectedKey(SelectionKey k, AbstractNioChannel ch) {
// 16 accept 
int readyOps = k.readyOps();

SelectionKey
public static final int OP_READ = 1 << 0;
// 为何没有 1 << 1 ?
public static final int OP_WRITE = 1 << 2;
public static final int OP_CONNECT = 1 << 3;
public static final int OP_ACCEPT = 1 << 4;

// Object msg  [id: 0xa6b9d284, /127.0.0.1:53949 => /127.0.0.1:6789]
ServerBootstrap$ServerBootstrapAcceptor.channelRead(ChannelHandlerContext, Object) line: 252

          try {
                childGroup.register(child).addListener(new ChannelFutureListener() {
                    @Override
                    public void operationComplete(ChannelFuture future) throws Exception {
                        if (!future.isSuccess()) {
                            forceClose(child, future.cause());
                        }
                    }
                });
            } catch (Throwable t) {
                forceClose(child, t);
            }


NioEventLoopGroup(MultithreadEventLoopGroup).register(Channel) line: 64	

@Override
    public ChannelFuture register(Channel channel) {
        return next().register(channel);
    }


NioEventLoop(SingleThreadEventLoop).register(Channel) line: 48	





channel  
pipeline
DefaultChannelPipeline{
(logging = io.netty.handler.logging.LoggingHandler), 
(framer = io.netty.handler.codec.DelimiterBasedFrameDecoder), 
(decoder = io.netty.handler.codec.string.StringDecoder), 
(encoder = io.netty.handler.codec.string.StringEncoder), 
(EchoServerHandler#0 = dyyx.echo.EchoServerHandler)}


parent 
NioServerSocketChannel  (id=156)	  [id: 0x2b988144, /0:0:0:0:0:0:0:0:6789]
pipeline
DefaultChannelPipeline{
(LoggingHandler#0 = io.netty.handler.logging.LoggingHandler), 
(ServerBootstrap$ServerBootstrapAcceptor#0 = io.netty.bootstrap.ServerBootstrap$ServerBootstrapAcceptor)
}
selectionKey	SelectionKeyImpl  (id=269)	
    selector	KQueueSelectorImpl  (id=199)


MacOSX 下 	selector 实现 为 KQueueSelectorImpl
linux2.6以后 EpollSelectorImpl
Windows平台 WindowsSelectorImpl

上一篇     下一篇
netty ByteBuf vs java NIO ByteBuffer

netty高性能之道

PooledByteBufAllocator跟踪调试

java NIO selector

缓存雪崩穿透预热更新降级

服务器性能指标介绍