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

推荐订阅源

S
Secure Thoughts
Security Latest
Security Latest
Simon Willison's Weblog
Simon Willison's Weblog
O
OpenAI News
GbyAI
GbyAI
L
LINUX DO - 最新话题
A
Arctic Wolf
T
Tor Project blog
G
GRAHAM CLULEY
I
InfoQ
博客园_首页
IT之家
IT之家
The Register - Security
The Register - Security
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
P
Proofpoint News Feed
The GitHub Blog
The GitHub Blog
Blog — PlanetScale
Blog — PlanetScale
N
Netflix TechBlog - Medium
K
Kaspersky official blog
博客园 - 三生石上(FineUI控件)
S
SegmentFault 最新的问题
U
Unit 42
PCI Perspectives
PCI Perspectives
量子位
P
Palo Alto Networks Blog
S
Securelist
T
Troy Hunt's Blog
博客园 - 【当耐特】
Recorded Future
Recorded Future
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
S
Security Affairs
Engineering at Meta
Engineering at Meta
T
The Blog of Author Tim Ferriss
博客园 - 聂微东
罗磊的独立博客
N
News and Events Feed by Topic
人人都是产品经理
人人都是产品经理
B
Blog RSS Feed
NISL@THU
NISL@THU
C
Cisco Blogs
T
Threatpost
有赞技术团队
有赞技术团队
Forbes - Security
Forbes - Security
Hugging Face - Blog
Hugging Face - Blog
Last Week in AI
Last Week in AI
T
The Exploit Database - CXSecurity.com
Cloudbric
Cloudbric
Cyberwarzone
Cyberwarzone
Google DeepMind News
Google DeepMind News
C
Cyber Attacks, Cyber Crime and Cyber Security

博客园 - 三驾马车

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 更为常见