ChannelHanlerContext调用写方法消息的走向

我在阅读Netty实战的时候有这样一段描述:

2021-08-11-19-26-19

我觉得这段话和这张图描述的并不够严谨,因为在我的实验中,前后是要看是入站还是出站数据的,如果是入站数据,下一个ChannelHandler在当前ChannelHandler的右侧,如果是出站数据,下一个ChannelHandler在当前ChannelHandler的左侧。我实验代码如下:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29

ch.pipeline()
        .addLast(new ChannelInboundHandlerAdapter() {
            @Override
            public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
                System.out.println("Running 1");
                ctx.fireChannelRead(msg);
            }
        })
        .addLast(new ChannelOutboundHandlerAdapter() {
            @Override
            public void write(ChannelHandlerContext ctx, Object msg, ChannelPromise promise) throws Exception {
                System.out.println("Running 2");
            }
        })
        .addLast(new ChannelInboundHandlerAdapter() {
            @Override
            public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
                System.out.println("Running 3");
                ctx.write(msg);
            }
        })
        .addLast(new ChannelOutboundHandlerAdapter() {
            @Override
            public void write(ChannelHandlerContext ctx, Object msg, ChannelPromise promise) throws Exception {
                System.out.println("Running 4");
            }
        });