當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。