gpt4 book ai didi

java - netty ChannelPipeline addLast

转载 作者:行者123 更新时间:2023-12-02 22:33:04 24 4
gpt4 key购买 nike

我正在学习 netty,示例代码如下

ChannelPipeline pipeline = pipeline();
// Enable stream compression (you can remove these two if unnecessary)
pipeline.addLast("deflater", new ZlibEncoder(ZlibWrapper.GZIP));
pipeline.addLast("inflater", new ZlibDecoder(ZlibWrapper.GZIP));

// Add the number codec first,
pipeline.addLast("decoder", new BigIntegerDecoder());
pipeline.addLast("encoder", new NumberEncoder());

// and then business logic.
// Please note we create a handler for every new channel
// because it has stateful properties.
pipeline.addLast("handler", new FactorialServerHandler());

我的问题是在哪里可以看到 addLast 方法的有效第一个参数列表,例如 deflater、inflater、解码器、编码器、处理程序等。

而且我在源代码中找不到实现映射的地方。这里我的意思是消息到达并且 ChannelPipeline 检查是否设置了 deflater 并调用 ZlibEncoder.GZIP 方法。

最佳答案

添加的顺序

ChannelPipeline p = pipeline();
p.addLast("1", new InboundHandlerA());
p.addLast("2", new InboundHandlerB());
p.addLast("3", new OutboundHandlerA());
p.addLast("4", new OutboundHandlerB());
p.addLast("5", new InboundOutboundHandlerX());

在给定的示例配置中,当事件进入时,处理程序评估顺序为 1、2、3、4、5。当一个事件出站时,顺序是5、4、3、2、1。在这个原则之上,ChannelPipeline跳过某些处理程序的评估以缩短堆栈深度

你可以查看这个网站了解更多详情

https://netty.io/4.0/api/io/netty/channel/ChannelPipeline.html

关于java - netty ChannelPipeline addLast,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11896852/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com