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

The following examples show how to use io.netty.channel.ChannelHandlerContext#fireChannelReadComplete() . 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 check out the related API usage on the sidebar.
Example 1
Source File: AbstractBatchDecoder.java    From sofa-bolt with 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
Source File: ByteToMessageDecoder.java    From netty4.0.27Learn with Apache License 2.0 5 votes vote down vote up
@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 File: SslProvider.java    From reactor-netty with 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 4
Source File: FlowControlHandler.java    From netty-4.1.22 with 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 5
Source File: AbstractBatchDecoder.java    From sofa-bolt with 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 6
Source File: TftpExceptionHandler.java    From tftp4j with 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 7
Source File: HttpWebSocketRequestHandler.java    From panama with 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 8
Source File: ByteToMessageDecoder.java    From netty-4.1.22 with 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 9
Source File: MessageAggregator.java    From netty-4.1.22 with 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 10
Source File: HttpStreamsHandler.java    From aws-sdk-java-v2 with Apache License 2.0 5 votes vote down vote up
@Override
public void channelReadComplete(ChannelHandlerContext ctx) throws Exception {
    if (ignoreBodyRead) {
        ctx.read();
    } else {
        ctx.fireChannelReadComplete();
    }
}
 
Example 11
Source File: FramebufferUpdateRectDecoder.java    From jfxvnc with Apache License 2.0 4 votes vote down vote up
@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 12
Source File: Netty4ChannelHandlerAdapter.java    From Ak47 with Apache License 2.0 4 votes vote down vote up
@Override
public void channelReadComplete(ChannelHandlerContext nettyctx) throws Exception {
    nettyctx.fireChannelReadComplete();
}
 
Example 13
Source File: MessageDecoder.java    From dremio-oss with Apache License 2.0 4 votes vote down vote up
@Override
public void channelReadComplete(ChannelHandlerContext ctx) throws Exception {
  ctx.fireChannelReadComplete();
}
 
Example 14
Source File: ReliableChannelHandler.java    From riiablo with 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 15
Source File: XioResponseClassifier.java    From xio with Apache License 2.0 4 votes vote down vote up
@Override
public void channelReadComplete(ChannelHandlerContext ctx) throws Exception {
  ctx.fireChannelReadComplete();
}
 
Example 16
Source File: ConnectionLimiter.java    From xio with Apache License 2.0 4 votes vote down vote up
@Override
public void channelReadComplete(ChannelHandlerContext ctx) throws Exception {
  ctx.fireChannelReadComplete();
}
 
Example 17
Source File: NettyChannelHandlerAdapter.java    From Ak47 with Apache License 2.0 4 votes vote down vote up
@Override
public void channelReadComplete(ChannelHandlerContext nettyctx) throws Exception {
    log.debug("channelReadComplete().");
    
    nettyctx.fireChannelReadComplete();
}
 
Example 18
Source File: ExceptionHandlerFilter.java    From spring-boot-netty with MIT License 4 votes vote down vote up
@Override
public void channelReadComplete(final ChannelHandlerContext ctx) throws Exception {
    counter.arrive();
    ctx.fireChannelReadComplete();
}
 
Example 19
Source File: ProtobufLengthDecoder.java    From Bats with Apache License 2.0 4 votes vote down vote up
@Override
public void channelReadComplete(ChannelHandlerContext ctx) throws Exception {
  ctx.fireChannelReadComplete();
}
 
Example 20
Source File: RntbdRequestManager.java    From azure-cosmosdb-java with MIT License 3 votes vote down vote up
/**
 * 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();
}