当前位置: 首页>>代码示例>>Java>>正文


Java ChannelHandlerContext.read方法代码示例

本文整理汇总了Java中io.netty.channel.ChannelHandlerContext.read方法的典型用法代码示例。如果您正苦于以下问题:Java ChannelHandlerContext.read方法的具体用法?Java ChannelHandlerContext.read怎么用?Java ChannelHandlerContext.read使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在io.netty.channel.ChannelHandlerContext的用法示例。


在下文中一共展示了ChannelHandlerContext.read方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: channelRead0

import io.netty.channel.ChannelHandlerContext; //导入方法依赖的package包/类
@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);
        }
    }
}
 
开发者ID:aws,项目名称:aws-sdk-java-v2,代码行数:43,代码来源:ResponseHandler.java

示例2: read

import io.netty.channel.ChannelHandlerContext; //导入方法依赖的package包/类
@Override
public void read(ChannelHandlerContext ctx) throws Exception
{
    ctx.read();
}
 
开发者ID:F1r3w477,项目名称:CustomWorldGen,代码行数:6,代码来源:NetworkDispatcher.java

示例3: channelActive

import io.netty.channel.ChannelHandlerContext; //导入方法依赖的package包/类
@Override
public void channelActive(ChannelHandlerContext ctx) {
    ctx.read();
}
 
开发者ID:D3adspaceEnterprises,项目名称:cardea,代码行数:5,代码来源:CardeaServerBackendHandler.java


注:本文中的io.netty.channel.ChannelHandlerContext.read方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。