use of io.netty.handler.codec.http2.DefaultHttp2FrameReader in project grpc-java by grpc.
the class NettyClientHandler method newHandler.
static NettyClientHandler newHandler(ClientTransportLifecycleManager lifecycleManager, @Nullable KeepAliveManager keepAliveManager, int flowControlWindow, int maxHeaderListSize, Ticker ticker) {
Preconditions.checkArgument(maxHeaderListSize > 0, "maxHeaderListSize must be positive");
Http2HeadersDecoder headersDecoder = new GrpcHttp2ClientHeadersDecoder(maxHeaderListSize);
Http2FrameReader frameReader = new DefaultHttp2FrameReader(headersDecoder);
Http2FrameWriter frameWriter = new DefaultHttp2FrameWriter();
Http2Connection connection = new DefaultHttp2Connection(false);
return newHandler(connection, frameReader, frameWriter, lifecycleManager, keepAliveManager, flowControlWindow, maxHeaderListSize, ticker);
}
use of io.netty.handler.codec.http2.DefaultHttp2FrameReader in project grpc-java by grpc.
the class NettyServerHandler method newHandler.
static NettyServerHandler newHandler(ServerTransportListener transportListener, ChannelPromise channelUnused, List<? extends ServerStreamTracer.Factory> streamTracerFactories, TransportTracer transportTracer, int maxStreams, boolean autoFlowControl, int flowControlWindow, int maxHeaderListSize, int maxMessageSize, long keepAliveTimeInNanos, long keepAliveTimeoutInNanos, long maxConnectionIdleInNanos, long maxConnectionAgeInNanos, long maxConnectionAgeGraceInNanos, boolean permitKeepAliveWithoutCalls, long permitKeepAliveTimeInNanos, Attributes eagAttributes) {
Preconditions.checkArgument(maxHeaderListSize > 0, "maxHeaderListSize must be positive: %s", maxHeaderListSize);
Http2FrameLogger frameLogger = new Http2FrameLogger(LogLevel.DEBUG, NettyServerHandler.class);
Http2HeadersDecoder headersDecoder = new GrpcHttp2ServerHeadersDecoder(maxHeaderListSize);
Http2FrameReader frameReader = new Http2InboundFrameLogger(new DefaultHttp2FrameReader(headersDecoder), frameLogger);
Http2FrameWriter frameWriter = new Http2OutboundFrameLogger(new DefaultHttp2FrameWriter(), frameLogger);
return newHandler(channelUnused, frameReader, frameWriter, transportListener, streamTracerFactories, transportTracer, maxStreams, autoFlowControl, flowControlWindow, maxHeaderListSize, maxMessageSize, keepAliveTimeInNanos, keepAliveTimeoutInNanos, maxConnectionIdleInNanos, maxConnectionAgeInNanos, maxConnectionAgeGraceInNanos, permitKeepAliveWithoutCalls, permitKeepAliveTimeInNanos, eagAttributes);
}
use of io.netty.handler.codec.http2.DefaultHttp2FrameReader in project netty by netty.
the class DataCompressionHttp2Test method bootstrapEnv.
private void bootstrapEnv(int serverOutSize) throws Exception {
final CountDownLatch prefaceWrittenLatch = new CountDownLatch(1);
serverOut = new ByteArrayOutputStream(serverOutSize);
serverLatch = new CountDownLatch(1);
sb = new ServerBootstrap();
cb = new Bootstrap();
// Streams are created before the normal flow for this test, so these connection must be initialized up front.
serverConnection = new DefaultHttp2Connection(true);
clientConnection = new DefaultHttp2Connection(false);
serverConnection.addListener(new Http2ConnectionAdapter() {
@Override
public void onStreamClosed(Http2Stream stream) {
serverLatch.countDown();
}
});
doAnswer(new Answer<Integer>() {
@Override
public Integer answer(InvocationOnMock in) throws Throwable {
ByteBuf buf = (ByteBuf) in.getArguments()[2];
int padding = (Integer) in.getArguments()[3];
int processedBytes = buf.readableBytes() + padding;
buf.readBytes(serverOut, buf.readableBytes());
if (in.getArgument(4)) {
serverConnection.stream((Integer) in.getArgument(1)).close();
}
return processedBytes;
}
}).when(serverListener).onDataRead(any(ChannelHandlerContext.class), anyInt(), any(ByteBuf.class), anyInt(), anyBoolean());
final CountDownLatch serverChannelLatch = new CountDownLatch(1);
sb.group(new NioEventLoopGroup(), new NioEventLoopGroup());
sb.channel(NioServerSocketChannel.class);
sb.childHandler(new ChannelInitializer<Channel>() {
@Override
protected void initChannel(Channel ch) throws Exception {
serverConnectedChannel = ch;
ChannelPipeline p = ch.pipeline();
Http2FrameWriter frameWriter = new DefaultHttp2FrameWriter();
serverConnection.remote().flowController(new DefaultHttp2RemoteFlowController(serverConnection));
serverConnection.local().flowController(new DefaultHttp2LocalFlowController(serverConnection).frameWriter(frameWriter));
Http2ConnectionEncoder encoder = new CompressorHttp2ConnectionEncoder(new DefaultHttp2ConnectionEncoder(serverConnection, frameWriter));
Http2ConnectionDecoder decoder = new DefaultHttp2ConnectionDecoder(serverConnection, encoder, new DefaultHttp2FrameReader());
Http2ConnectionHandler connectionHandler = new Http2ConnectionHandlerBuilder().frameListener(new DelegatingDecompressorFrameListener(serverConnection, serverListener)).codec(decoder, encoder).build();
p.addLast(connectionHandler);
serverChannelLatch.countDown();
}
});
cb.group(new NioEventLoopGroup());
cb.channel(NioSocketChannel.class);
cb.handler(new ChannelInitializer<Channel>() {
@Override
protected void initChannel(Channel ch) throws Exception {
ChannelPipeline p = ch.pipeline();
Http2FrameWriter frameWriter = new DefaultHttp2FrameWriter();
clientConnection.remote().flowController(new DefaultHttp2RemoteFlowController(clientConnection));
clientConnection.local().flowController(new DefaultHttp2LocalFlowController(clientConnection).frameWriter(frameWriter));
clientEncoder = new CompressorHttp2ConnectionEncoder(new DefaultHttp2ConnectionEncoder(clientConnection, frameWriter));
Http2ConnectionDecoder decoder = new DefaultHttp2ConnectionDecoder(clientConnection, clientEncoder, new DefaultHttp2FrameReader());
clientHandler = new Http2ConnectionHandlerBuilder().frameListener(new DelegatingDecompressorFrameListener(clientConnection, clientListener)).gracefulShutdownTimeoutMillis(0).codec(decoder, clientEncoder).build();
p.addLast(clientHandler);
p.addLast(new ChannelInboundHandlerAdapter() {
@Override
public void userEventTriggered(ChannelHandlerContext ctx, Object evt) throws Exception {
if (evt == Http2ConnectionPrefaceAndSettingsFrameWrittenEvent.INSTANCE) {
prefaceWrittenLatch.countDown();
ctx.pipeline().remove(this);
}
}
});
}
});
serverChannel = sb.bind(new InetSocketAddress(0)).sync().channel();
int port = ((InetSocketAddress) serverChannel.localAddress()).getPort();
ChannelFuture ccf = cb.connect(new InetSocketAddress(NetUtil.LOCALHOST, port));
assertTrue(ccf.awaitUninterruptibly().isSuccess());
clientChannel = ccf.channel();
assertTrue(prefaceWrittenLatch.await(5, SECONDS));
assertTrue(serverChannelLatch.await(5, SECONDS));
}
Aggregations