Java Code Examples for io.netty.channel.ChannelHandlerContext.read()

The following are Jave code examples for showing how to use read() of the io.netty.channel.ChannelHandlerContext class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: aws-sdk-java-v2   File: ResponseHandler.java   View Source Code Vote up 4 votes
@Override
protected void channelRead0(ChannelHandlerContext channelContext, HttpObject msg) throws Exception {
    RequestContext requestContext = channelContext.channel().attr(REQUEST_CONTEXT_KEY).get();

    if (msg instanceof HttpResponse) {
        HttpResponse response = (HttpResponse) msg;
        SdkHttpResponse sdkResponse = SdkHttpFullResponse.builder()
                                                         .headers(fromNettyHeaders(response.headers()))
                                                         .statusCode(response.status().code())
                                                         .statusText(response.status().reasonPhrase())
                                                         .build();
        channelContext.channel().attr(KEEP_ALIVE).set(HttpUtil.isKeepAlive(response));
        requestContext.handler().headersReceived(sdkResponse);
    }

    if (msg instanceof StreamedHttpResponse) {
        requestContext.handler().onStream(new PublisherAdapter((StreamedHttpResponse) msg, channelContext, requestContext));
    } else if (msg instanceof FullHttpResponse) {
        // TODO: HttpStreamsClientHandler leaves a dangling LastHttpContent
        // in the pipeline. Consume it ourselves to make sure the channel
        // is empty at the end of stream and before releasing it back to he
        // pool.  The HttpStreamsClientHandler should really be doing this
        // for us.
        channelContext.read();

        ByteBuf fullContent = ((FullHttpResponse) msg).content();
        final ByteBuffer bb = copyToByteBuffer(fullContent);
        fullContent.release();
        requestContext.handler().onStream(new FullResponseContentPublisher(channelContext, bb));
        Subscriber<? super ByteBuffer> subscriber = channelContext.channel().attr(ChannelAttributeKeys.SUBSCRIBER_KEY).get();
        try {
            subscriber.onComplete();
            requestContext.handler().complete();
        } catch (RuntimeException e) {
            subscriber.onError(e);
            requestContext.handler().exceptionOccurred(e);
            throw e;
        } finally {
            finalizeRequest(requestContext, channelContext);
        }
    }
}
 
Example 2
Project: CustomWorldGen   File: NetworkDispatcher.java   View Source Code Vote up 4 votes
@Override
public void read(ChannelHandlerContext ctx) throws Exception
{
    ctx.read();
}
 
Example 3
Project: cardea   File: CardeaServerBackendHandler.java   View Source Code Vote up 4 votes
@Override
public void channelActive(ChannelHandlerContext ctx) {
    ctx.read();
}