本文整理匯總了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();
}