本文整理汇总了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);
}
}
}
示例2: read
import io.netty.channel.ChannelHandlerContext; //导入方法依赖的package包/类
@Override
public void read(ChannelHandlerContext ctx) throws Exception
{
ctx.read();
}
示例3: channelActive
import io.netty.channel.ChannelHandlerContext; //导入方法依赖的package包/类
@Override
public void channelActive(ChannelHandlerContext ctx) {
ctx.read();
}