下面列出了io.netty.channel.ChannelHandlerContext#fireChannelReadComplete ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
@Override
public final void handlerRemoved(ChannelHandlerContext ctx) throws Exception {
ByteBuf buf = internalBuffer();
int readable = buf.readableBytes();
if (readable > 0) {
ByteBuf bytes = buf.readBytes(readable);
buf.release();
ctx.fireChannelRead(bytes);
} else {
buf.release();
}
cumulation = null;
numReads = 0;
ctx.fireChannelReadComplete();
handlerRemoved0(ctx);
}
@Override
public void channelReadComplete(ChannelHandlerContext ctx) throws Exception {
if (cumulation != null && !first && cumulation.refCnt() == 1) {
// discard some bytes if possible to make more room in the
// buffer but only if the refCnt == 1 as otherwise the user may have
// used slice().retain() or duplicate().retain().
//
// See:
// - https://github.com/netty/netty/issues/2327
// - https://github.com/netty/netty/issues/1764
cumulation.discardSomeReadBytes();
}
ctx.fireChannelReadComplete();
}
/**
* Dequeues one or many (or none) messages depending on the channel's auto
* reading state and returns the number of messages that were consumed from
* the internal queue.
*
* The {@code minConsume} argument is used to force {@code dequeue()} into
* consuming that number of messages regardless of the channel's auto
* reading configuration.
*
* @see #read(ChannelHandlerContext)
* @see #channelRead(ChannelHandlerContext, Object)
* 根据通道的自动读取状态对一个或多个(或多个)消息进行反队列处理,并返回从内部队列中消费的消息数量。minuse参数用于强制dequeue()使用该数量的消息,而不考虑通道的自动读取配置。
*/
private int dequeue(ChannelHandlerContext ctx, int minConsume) {
if (queue != null) {
int consumed = 0;
Object msg;
while ((consumed < minConsume) || config.isAutoRead()) {
msg = queue.poll();
if (msg == null) {
break;
}
++consumed;
ctx.fireChannelRead(msg);
}
// We're firing a completion event every time one (or more)
// messages were consumed and the queue ended up being drained
// to an empty state.
if (queue.isEmpty() && consumed > 0) {
ctx.fireChannelReadComplete();
}
return consumed;
}
return 0;
}
@Override
public void channelReadComplete(ChannelHandlerContext ctx) throws Exception {
try {
ctx.fireChannelReadComplete();
} catch (Throwable t) {
ctx.fireExceptionCaught(t);
}
}
@Override
public void channelReadComplete(ChannelHandlerContext ctx) throws Exception {
numReads = 0;
discardSomeReadBytes();
if (decodeWasNull) {
decodeWasNull = false;
if (!ctx.channel().config().isAutoRead()) {
ctx.read();
}
}
ctx.fireChannelReadComplete();
}
@Override
public void channelReadComplete(ChannelHandlerContext ctx) throws Exception {
// We might need keep reading the channel until the full message is aggregated.我们可能需要一直读取通道,直到聚合完整的消息。
//
// See https://github.com/netty/netty/issues/6583
if (currentMessage != null && !ctx.channel().config().isAutoRead()) {
ctx.read();
}
ctx.fireChannelReadComplete();
}
@Override
public void channelReadComplete(ChannelHandlerContext ctx) throws Exception {
if (ignoreBodyRead) {
ctx.read();
} else {
ctx.fireChannelReadComplete();
}
}
@Override
public void channelReadComplete(ChannelHandlerContext ctx) throws Exception {
if (isWebSocket) {
if (stringBuilder != null) {
NettyWebSocketRequest nettyWebSocketRequest = new NettyWebSocketRequest(ctx, new TextWebSocketFrame(stringBuilder.toString()));
nettyWebSocketRequest.setMessage(nettyWebSocketRequest.message());
webSocketHandler.doRequest(nettyWebSocketRequest);
stringBuilder = null;
}
ctx.fireChannelReadComplete();
} else {
super.channelReadComplete(ctx);
}
}
@Override
public void channelReadComplete(ChannelHandlerContext ctx) throws Exception {
numReads = 0;
discardSomeReadBytes();
if (decodeWasNull) {
decodeWasNull = false;
if (!ctx.channel().config().isAutoRead()) {
ctx.read();
}
}
ctx.fireChannelReadComplete();
}
@Override
public void channelReadComplete(ChannelHandlerContext ctx) {
if (!handshakeDone) {
ctx.read(); /* continue consuming. */
}
ctx.fireChannelReadComplete();
}
@Override
public void channelReadComplete(ChannelHandlerContext ctx) throws Exception {
ctx.fireChannelReadComplete();
}
@Override
public void channelReadComplete(final ChannelHandlerContext ctx) throws Exception {
counter.arrive();
ctx.fireChannelReadComplete();
}
@Override
public void channelReadComplete(ChannelHandlerContext nettyctx) throws Exception {
log.debug("channelReadComplete().");
nettyctx.fireChannelReadComplete();
}
@Override
public void channelReadComplete(ChannelHandlerContext ctx) throws Exception {
ctx.fireChannelReadComplete();
}
@Override
public void channelReadComplete(ChannelHandlerContext ctx) throws Exception {
ctx.fireChannelReadComplete();
}
@Override
public void channelReadComplete(ChannelHandlerContext ctx) throws Exception {
Gdx.app.debug(TAG, "channelReadComplete");
ctx.fireChannelReadComplete();
}
@Override
public void channelReadComplete(ChannelHandlerContext ctx) throws Exception {
ctx.fireChannelReadComplete();
}
@Override
public void channelReadComplete(ChannelHandlerContext nettyctx) throws Exception {
nettyctx.fireChannelReadComplete();
}
@Override
public boolean decode(ChannelHandlerContext ctx, ByteBuf m, List<Object> out) throws Exception {
if (state == State.INIT) {
if (logger.isTraceEnabled()) {
logger.trace("init readable {} bytes", m.readableBytes());
}
if (!m.isReadable()) {
return false;
}
if (m.getByte(0) != ServerEvent.FRAMEBUFFER_UPDATE.getType()) {
logger.error("no FBU type!!! {}", m.getByte(0));
ctx.fireChannelReadComplete();
return false;
}
if (!m.isReadable(4)) {
return false;
}
m.skipBytes(2); // padding
numberRects = m.readUnsignedShort();
currentRect = 0;
if (logger.isTraceEnabled()) {
logger.trace("number of rectangles: {}", numberRects);
}
if (numberRects < 1) {
return true;
}
state = State.NEW_RECT;
}
if (state == State.NEW_RECT) {
if (!readRect(ctx, m, out)) {
return false;
}
state = State.READ_RECT;
}
FrameRectDecoder dec = frameRectDecoder.get(rect.getEncoding());
if (dec == null) {
throw new ProtocolException("Encoding not supported: " + rect.getEncoding());
}
dec.setRect(rect);
if (!dec.decode(ctx, m, out)) {
return false;
}
if (currentRect == numberRects) {
state = State.INIT;
ctx.fireUserEventTriggered(ProtocolState.FBU_REQUEST);
return true;
}
if (!readRect(ctx, m, out)) {
state = State.NEW_RECT;
}
return false;
}
/**
* The {@link Channel} of the {@link ChannelHandlerContext} has fully consumed the most-recent message read.
* <p>
* If {@link ChannelOption#AUTO_READ} is off, no further attempt to read inbound data from the current
* {@link Channel} will be made until {@link ChannelHandlerContext#read} is called. This leaves time
* for outbound messages to be written.
*
* @param context {@link ChannelHandlerContext} to which this {@link RntbdRequestManager} belongs
*/
@Override
public void channelReadComplete(final ChannelHandlerContext context) {
this.traceOperation(context, "channelReadComplete");
this.timestamps.channelReadCompleted();
context.fireChannelReadComplete();
}