public class FlowControlHandler extends ChannelDuplexHandler
FlowControlHandler确保每read()只向下游发送一条消息。
诸如ByteToMessageDecoder或MessageToByteEncoder等类可以自由地为任何给定的输入发出尽可能多的事件。
频道的自动阅读配置通常不适用于这些情况。
这导致下游ChannelHandler的问题,它们想要在处理一个事件时保留后续事件。
这是HttpObjectDecoder常见的问题,通常会触发HttpRequest ,紧接着是LastHttpContent事件。
{@code
ChannelPipeline pipeline = ...;
pipeline.addLast(new HttpServerCodec());
pipeline.addLast(new FlowControlHandler());
pipeline.addLast(new MyExampleHandler());
class MyExampleHandler extends ChannelInboundHandlerAdapter {
ChannelHandler.Sharable| Constructor and Description |
|---|
FlowControlHandler() |
FlowControlHandler(boolean releaseMessages) |
| Modifier and Type | Method and Description |
|---|---|
void |
channelInactive(ChannelHandlerContext ctx)
|
void |
channelRead(ChannelHandlerContext ctx, java.lang.Object msg)
|
void |
channelReadComplete(ChannelHandlerContext ctx)
|
void |
handlerAdded(ChannelHandlerContext ctx)
子类可以忽略这个方法。
|
void |
read(ChannelHandlerContext ctx)
|
bind, close, connect, deregister, disconnect, flush, writechannelActive, channelRegistered, channelUnregistered, channelWritabilityChanged, exceptionCaught, userEventTriggeredensureNotSharable, handlerRemoved, isSharableclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitexceptionCaught, handlerRemovedpublic FlowControlHandler()
public FlowControlHandler(boolean releaseMessages)
public void handlerAdded(ChannelHandlerContext ctx) throws java.lang.Exception
ChannelHandlerAdapter
handlerAdded ,界面
ChannelHandler
handlerAdded在课堂上
ChannelHandlerAdapter
java.lang.Exception
public void channelInactive(ChannelHandlerContext ctx) throws java.lang.Exception
ChannelInboundHandlerAdapter
ChannelHandlerContext.fireChannelInactive()转发到ChannelPipeline中的下一个ChannelInboundHandler 。
子类可以重写此方法来更改行为。
channelInactive在界面
ChannelInboundHandler
channelInactive在课堂上
ChannelInboundHandlerAdapter
java.lang.Exception
public void read(ChannelHandlerContext ctx) throws java.lang.Exception
ChannelDuplexHandler
ChannelHandlerContext.read()转发到ChannelPipeline中的下一个ChannelOutboundHandler 。
子类可以重写此方法来更改行为。
read在界面
ChannelOutboundHandler
read在课堂上
ChannelDuplexHandler
java.lang.Exception
public void channelRead(ChannelHandlerContext ctx, java.lang.Object msg) throws java.lang.Exception
ChannelInboundHandlerAdapter
ChannelHandlerContext.fireChannelRead(Object)转发到ChannelPipeline中的下一个ChannelInboundHandler 。
子类可以重写此方法来更改行为。
channelRead在界面
ChannelInboundHandler
channelRead在课堂上
ChannelInboundHandlerAdapter
java.lang.Exception
public void channelReadComplete(ChannelHandlerContext ctx) throws java.lang.Exception
ChannelInboundHandlerAdapter
ChannelHandlerContext.fireChannelReadComplete()转发到ChannelPipeline中的下一个ChannelInboundHandler 。
子类可以重写此方法来更改行为。
channelReadComplete在界面
ChannelInboundHandler
channelReadComplete在课堂上
ChannelInboundHandlerAdapter
java.lang.Exception
Copyright © 2008–2018 The Netty Project. All rights reserved.