Java Code Examples for io.netty.channel.ChannelHandlerContext#fireChannelReadComplete()

The following examples show how to use io.netty.channel.ChannelHandlerContext#fireChannelReadComplete() . These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may want to check out the right sidebar which shows the related API usage.
Example 1
Source Project: sofa-bolt   File: AbstractBatchDecoder.java    License: Apache License 2.0 6 votes vote down vote up
@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);
}
 
Example 2
@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();
}
 
Example 3
Source Project: netty-4.1.22   File: FlowControlHandler.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * 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;
}
 
Example 4
Source Project: tftp4j   File: TftpExceptionHandler.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void channelReadComplete(ChannelHandlerContext ctx) throws Exception {
    try {
        ctx.fireChannelReadComplete();
    } catch (Throwable t) {
        ctx.fireExceptionCaught(t);
    }
}
 
Example 5
@Override
public void channelReadComplete(ChannelHandlerContext ctx) throws Exception {
    numReads = 0;
    discardSomeReadBytes();
    if (decodeWasNull) {
        decodeWasNull = false;
        if (!ctx.channel().config().isAutoRead()) {
            ctx.read();
        }
    }
    ctx.fireChannelReadComplete();
}
 
Example 6
Source Project: netty-4.1.22   File: MessageAggregator.java    License: Apache License 2.0 5 votes vote down vote up
@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();
}
 
Example 7
@Override
public void channelReadComplete(ChannelHandlerContext ctx) throws Exception {
    if (ignoreBodyRead) {
        ctx.read();
    } else {
        ctx.fireChannelReadComplete();
    }
}
 
Example 8
Source Project: panama   File: HttpWebSocketRequestHandler.java    License: MIT License 5 votes vote down vote up
@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);
    }
}
 
Example 9
Source Project: sofa-bolt   File: AbstractBatchDecoder.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void channelReadComplete(ChannelHandlerContext ctx) throws Exception {
    numReads = 0;
    discardSomeReadBytes();
    if (decodeWasNull) {
        decodeWasNull = false;
        if (!ctx.channel().config().isAutoRead()) {
            ctx.read();
        }
    }
    ctx.fireChannelReadComplete();
}
 
Example 10
Source Project: reactor-netty   File: SslProvider.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void channelReadComplete(ChannelHandlerContext ctx) {
	if (!handshakeDone) {
		ctx.read(); /* continue consuming. */
	}
	ctx.fireChannelReadComplete();
}
 
Example 11
Source Project: Bats   File: ProtobufLengthDecoder.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public void channelReadComplete(ChannelHandlerContext ctx) throws Exception {
  ctx.fireChannelReadComplete();
}
 
Example 12
@Override
public void channelReadComplete(final ChannelHandlerContext ctx) throws Exception {
    counter.arrive();
    ctx.fireChannelReadComplete();
}
 
Example 13
Source Project: Ak47   File: NettyChannelHandlerAdapter.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public void channelReadComplete(ChannelHandlerContext nettyctx) throws Exception {
    log.debug("channelReadComplete().");
    
    nettyctx.fireChannelReadComplete();
}
 
Example 14
Source Project: xio   File: ConnectionLimiter.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public void channelReadComplete(ChannelHandlerContext ctx) throws Exception {
  ctx.fireChannelReadComplete();
}
 
Example 15
Source Project: xio   File: XioResponseClassifier.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public void channelReadComplete(ChannelHandlerContext ctx) throws Exception {
  ctx.fireChannelReadComplete();
}
 
Example 16
Source Project: riiablo   File: ReliableChannelHandler.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public void channelReadComplete(ChannelHandlerContext ctx) throws Exception {
  Gdx.app.debug(TAG, "channelReadComplete");
  ctx.fireChannelReadComplete();
}
 
Example 17
Source Project: dremio-oss   File: MessageDecoder.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public void channelReadComplete(ChannelHandlerContext ctx) throws Exception {
  ctx.fireChannelReadComplete();
}
 
Example 18
@Override
public void channelReadComplete(ChannelHandlerContext nettyctx) throws Exception {
    nettyctx.fireChannelReadComplete();
}
 
Example 19
@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;
}
 
Example 20
/**
 * 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();
}