记录一下Netty已提供的主要的ChannelHandler,有助于快速开发。
解码
- LineBasedFrameDecoder:A decoder that splits the received ByteBufs on line endings.
- DelimiterBasedFrameDecoder:A decoder that splits the received ByteBufs by one or more delimiters.
- FixedLengthFrameDecoder:A decoder that splits the received ByteBufs by the fixed number of bytes.
- LengthFieldBasedFrameDecoder:A decoder that splits the received ByteBufs dynamically by the value of the length field in the message.
- ByteToMessageDecoder:抽象类,由于你不可能知道远程节点是否会一次性地发送一个完整 的消息,所以这个类会对入站数据进行缓冲,直到它准备好处理。
- MessageToMessageDecoder:
编码
- MessageToByteEncoder: 抽象类,继承该类的实现任意类型到ByteBuf的转化,其他事情有该类完成。
- MessageToMessageEncoder:抽象类,
超时检测
- ReadTimeoutHandler:Raises a ReadTimeoutException when no data was read within a certain period of time. 如果在指定的时间间隔内没有收到任何的入站数据,则抛出一个 Read- TimeoutException 并关闭对应的 Channel。可以通过重写你的 ChannelHandler 中的 exceptionCaught()方法来检测该 Read- TimeoutException
- WriteTimeoutHandler:Raises a WriteTimeoutException when no data was written within a certain period of time. 如果在指定的时间间隔内没有任何出站数据写入,则抛出一个 Write- TimeoutException 并关闭对应的 Channel。可以通过重写你的 ChannelHandler 的 exceptionCaught()方法检测该 WriteTimeout- Exception
- IdleStateHandler: 当连接空闲时间太长时,将会触发一个 IdleStateEvent 事件。然后, 你可以通过在你的 ChannelInboundHandler 中重写 userEvent- Triggered()方法来处理该 IdleStateEvent 事件
日志:
- LoggingHandler:A ChannelHandler that logs all events using a logging framework.
安全:
- SslHandler:
支持HTTP、WebSocket
写大数据,FileRegion 零拷贝
序列化:JDK 序列化,JBoss Marshalling ,Protocol Buffers
网友评论