惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Google DeepMind News
Google DeepMind News
Stack Overflow Blog
Stack Overflow Blog
Hugging Face - Blog
Hugging Face - Blog
博客园_首页
T
The Blog of Author Tim Ferriss
博客园 - 叶小钗
N
Netflix TechBlog - Medium
腾讯CDC
C
Check Point Blog
P
Proofpoint News Feed
Engineering at Meta
Engineering at Meta
GbyAI
GbyAI
S
SegmentFault 最新的问题
F
Fortinet All Blogs
美团技术团队
U
Unit 42
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
博客园 - 司徒正美
F
Full Disclosure
Recorded Future
Recorded Future
D
DataBreaches.Net
博客园 - 【当耐特】
Martin Fowler
Martin Fowler
J
Java Code Geeks
I
InfoQ
Y
Y Combinator Blog
A
About on SuperTechFans
AI
AI
爱范儿
爱范儿
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
Forbes - Security
Forbes - Security
W
WeLiveSecurity
M
MIT News - Artificial intelligence
雷峰网
雷峰网
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
Simon Willison's Weblog
Simon Willison's Weblog
Schneier on Security
Schneier on Security
The GitHub Blog
The GitHub Blog
Security Archives - TechRepublic
Security Archives - TechRepublic
aimingoo的专栏
aimingoo的专栏
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
G
GRAHAM CLULEY
Know Your Adversary
Know Your Adversary
Latest news
Latest news
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
D
Docker
Recent Commits to openclaw:main
Recent Commits to openclaw:main
量子位
V2EX - 技术
V2EX - 技术
Project Zero
Project Zero

博客园 - 三驾马车

Claude Code 官宣:可以在 IDEA 用了! idea gitee 更新已取消 解决方案 ByteBuffer和ByteBuf区别 Marshalling.getProvidedMarshallerFactory("serial") 参数有那些 ProtobufVarint32FrameDecoder和ProtobufDecoder区别 protobuf 的 Varint 编码规范 netty initChannel ch.pipeline().addLast 先后顺序很重要 ChannelInboundHandlerAdapter 的channelRead和channelReadComplete的区别 Unpooled.buffer()和Unpooled.copiedBuffer区别 ServerBootstrap 和Bootstrap 区别 childhandler 和 handler 区别 ChannelInitializer<SocketChannel> 的作用详解 SimpleChannelInboundHandler 中的 messageReceived 和 channelRead0 ChannelHandlerAdapter 与 ChannelInboundHandler 的区别 Application run failed .ParserException: while parsing a block mapping in 'reader' openssl genrsa 自签名ssl证书 上传本地项目到新建git项目 save download pdf
ChannelHandlerAdapter 和 ChannelInboundHandlerAdapter 的区别
三驾马车 · 2025-05-13 · via 博客园 - 三驾马车

这两个类都是 Netty 框架中的处理器基类,但它们有一些重要区别:

ChannelHandlerAdapter

  • 是一个简单的抽象适配器类,实现了 ChannelHandler 接口

  • 提供了所有 ChannelHandler 方法的空实现

  • 作为所有处理器适配器的基类

  • 主要用于不需要处理所有事件的简单处理器

ChannelInboundHandlerAdapter

  • 继承自 ChannelHandlerAdapter

  • 专门用于处理入站(INBOUND)事件

  • 实现了 ChannelInboundHandler 接口

  • 提供了入站事件处理方法(如 channelReadchannelActive 等)的默认实现

  • 开发者只需覆盖感兴趣的事件处理方法

主要区别

特性ChannelHandlerAdapterChannelInboundHandlerAdapter
功能 通用处理器基类 专门处理入站事件
接口实现 ChannelHandler ChannelInboundHandler
事件处理 不区分入站/出站 专注于入站事件
使用场景 简单处理器或自定义处理器基类 需要处理入站消息/事件的处理器

使用建议

  • 如果你只需要处理入站事件,继承 ChannelInboundHandlerAdapter 更合适

  • 如果你需要创建自定义的处理器基类或处理出站事件,可以使用 ChannelHandlerAdapter

  • 大多数情况下,处理网络数据时使用 ChannelInboundHandlerAdapter 更为常见