Netty学习笔记一

来源:互联网 发布:it监控平台软件 编辑:程序博客网 时间:2024/05/01 23:26

Handler模块:

ChannelHandler

{@link ChannelHandler} itself does not provide any method.  To handle a
 * {@link ChannelEvent} you need to implement its sub-interfaces.  There are
 * two sub-interfaces which handles a received event, one for upstream events
 * and the other for downstream events

不提供任何方法,在应用中,要根据需要选择实现它的子接口:ChannelUpstreamHandler或者ChannelDownstreamHandler,或者两者的合成接口--SimpleChannelHandler(继承了ChannelUpstreamHandler接口和ChannelDownstreamHandler接口)

ChannelUpstreamHandler :【 extends ChannelHandler】

Handles or intercepts an upstream {@link ChannelEvent}, and sends a
 {@link ChannelEvent} to the next handler in a {@link ChannelPipeline}.
The most common use case of this interface is to intercept an I/O event
generated by I/O workers to transform the received messages or execute
the relevant business logic.

ChannelDownstreamHandler:【 extends ChannelHandler】

 Handles or intercepts a downstream {@link ChannelEvent}, and sends a
 {@link ChannelEvent} to the next handler in a {@link ChannelPipeline}.
The most common use case of this interface is to intercept an I/O request
such as {@link Channel#write(Object)} and {@link Channel#close()}.

SimpleChannelHandler:【 implements ChannelUpstreamHandler, ChannelDownstreamHandler】

A {@link ChannelHandler} which provides an individual handler method
 * for each event type.  This handler down-casts the received upstream or
 * or downstream event into more meaningful sub-type event and calls an
 * appropriate handler method with the down-cast event.


SimpleChannelHandler提供了足够多的网络事件响应方法:

handleUpstream

messageReceived

exceptionCaught

channelOpen

channelBound

channelConnected

channelInterestChanged

channelDisconnected

channelUnbound

channelClosed

writeComplete

childChannelOpen

childChannelClosed

handleDownstream

writeRequested

bindRequested

connectRequested

setInterestOpsRequested

disconnectRequested

unbindRequested

closeRequested

大多数情况下,我们开发过程中要创建自己的ChannelHandler,一般实现自SimpleChannelHandler接口,覆盖里面相应的方法,或者创建自己的方法即可。

原创粉丝点击
热门问题 老师的惩罚 人脸识别 我在镇武司摸鱼那些年 重生之率土为王 我在大康的咸鱼生活 盘龙之生命进化 天生仙种 凡人之先天五行 春回大明朝 姑娘不必设防,我是瞎子 孩子在学校被坏孩子欺负了该怎么办 老师像个傻叉我妈还喷我我怎么办啊 承台上预埋桥墩连接钢筋错了怎么办 冲床油缸螺栓拆不下来怎么办 汇款到账银行写错了怎么办 搜狗输入法数字序号超过20怎么办 苹果手机保存的图片变模糊怎么办 微信视频保存到手机变模糊怎么办 自己的位置被别人取代了怎么办 给工厂做半成品老板跑了怎么办 微信变成英文再恢复汉字怎么办 cad中标注尺寸数字太小怎么办 扣扣的钱包手势密码忘记了怎么办 台式电脑带符号的数字打不出怎么办 情侣之间出现看见对方就烦怎么办 电信卡号和联通卡号怎么办情侣号 电脑能登qq但打不开网页怎么办 想跟朋友聊天但对方不理怎么办 刚进婆家门被婆婆欺负怎么办 支付宝的聊天记录被删了怎么办 彩票站买彩票把钱付了没出票怎么办 与异性朋友聊天没话题了怎么办 快递写错地址但已经发货了怎么办 快递写错电话但已经发货了怎么办 微信添加好友功能被限制怎么办 qq号被冻结了限制解封怎么办 被别人强制拉入qq群怎么办 qq群里的图片过期了怎么办 q附近人不能关注不能发信息怎么办 qq畅聊之火掉了怎么办 打印机打印时上面空白留太多怎么办 发短信一直空格里面写0怎么办 网贷获取我新手机号通讯录怎么办 系统音频驱动异常或未安装怎么办 附近功能已屏蔽你的qq好友怎么办 新申请的qq号忘了怎么办 刚申请的qq号忘了怎么办 以前申请的qq号忘了怎么办 小孩玩手机游戏扣费了怎么办 手机qq好友头像显示不出来怎么办 qq的一些重要数据被清理怎么办