io.netty.handler.codec.http2.Http2Connection Java Examples

The following examples show how to use io.netty.handler.codec.http2.Http2Connection. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: Http2ClientInitializer.java    From netty-cookbook with Apache License 2.0 6 votes vote down vote up
@Override
public void initChannel(SocketChannel ch) throws Exception {
    final Http2Connection connection = new DefaultHttp2Connection(false);
    final Http2FrameWriter frameWriter = frameWriter();
    connectionHandler = new HttpToHttp2ConnectionHandler(connection,
            frameReader(),
            frameWriter,
            new DelegatingDecompressorFrameListener(connection,
                    new InboundHttp2ToHttpAdapter.Builder(connection)
                            .maxContentLength(maxContentLength)
                            .propagateSettings(true)
                            .build()));
    responseHandler = new HttpResponseHandler();
    settingsHandler = new Http2SettingsHandler(ch.newPromise());
    configureClearText(ch);
}
 
Example #2
Source File: Http2ClientInitializer.java    From netty-4.1.22 with Apache License 2.0 6 votes vote down vote up
@Override
public void initChannel(SocketChannel ch) throws Exception {
    final Http2Connection connection = new DefaultHttp2Connection(false);
    connectionHandler = new HttpToHttp2ConnectionHandlerBuilder()
            .frameListener(new DelegatingDecompressorFrameListener(
                    connection,
                    new InboundHttp2ToHttpAdapterBuilder(connection)
                            .maxContentLength(maxContentLength)
                            .propagateSettings(true)
                            .build()))
            .frameLogger(logger)
            .connection(connection)
            .build();
    responseHandler = new HttpResponseHandler();
    settingsHandler = new Http2SettingsHandler(ch.newPromise());
    if (sslCtx != null) {
        configureSsl(ch);
    } else {
        configureClearText(ch);
    }
}
 
Example #3
Source File: Http2ClientInitializer.java    From product-microgateway with Apache License 2.0 6 votes vote down vote up
@Override
public void initChannel(SocketChannel ch) {
    final Http2Connection connection = new DefaultHttp2Connection(false);
    connectionHandler = new HttpToHttp2ConnectionHandlerBuilder()
            .frameListener(new DelegatingDecompressorFrameListener(
                    connection,
                    new InboundHttp2ToHttpAdapterBuilder(connection)
                            .maxContentLength(maxContentLength)
                            .propagateSettings(true)
                            .build()))
            .frameLogger(logger)
            .connection(connection)
            .build();
    responseHandler = new Http2ResponseHandler();
    settingsHandler = new Http2SettingsHandler(ch.newPromise());
    if (sslCtx != null) {
        configureSsl(ch);
    } else {
        configureClearText(ch);
    }
}
 
Example #4
Source File: Http2ClientInitializer.java    From sofa-rpc with Apache License 2.0 6 votes vote down vote up
@Override
public void initChannel(SocketChannel ch) throws Exception {
    final Http2Connection connection = new DefaultHttp2Connection(false);
    connectionHandler = new HttpToHttp2ConnectionHandlerBuilder()
        .frameListener(
            new DelegatingDecompressorFrameListener(connection, new InboundHttp2ToHttpAdapterBuilder(connection)
                .maxContentLength(transportConfig.getPayload()).propagateSettings(true).build()))
        .connection(connection).build();
    responseHandler = new Http2ClientChannelHandler();
    settingsHandler = new Http2SettingsHandler(ch.newPromise());
    String protocol = transportConfig.getProviderInfo().getProtocolType();
    if (RpcConstants.PROTOCOL_TYPE_H2.equals(protocol)) {
        configureSsl(ch);
    } else if (RpcConstants.PROTOCOL_TYPE_H2C.equals(protocol)) {
        if (!useH2cPriorKnowledge) {
            configureClearTextWithHttpUpgrade(ch);
        } else {
            configureClearTextWithPriorKnowledge(ch);
        }
    }
}
 
Example #5
Source File: Http2FrontendHandler.java    From nitmproxy with MIT License 6 votes vote down vote up
@Override
public void handlerAdded(ChannelHandlerContext ctx) throws Exception {
    LOGGER.info("{} : handlerAdded", connectionInfo);

    Http2Connection connection = new DefaultHttp2Connection(true);
    ChannelHandler http2ConnHandler = new HttpToHttp2ConnectionHandlerBuilder()
            .frameListener(new DelegatingDecompressorFrameListener(
                    connection,
                    new InboundHttp2ToHttpAdapterBuilder(connection)
                            .maxContentLength(master.config().getMaxContentLength())
                            .propagateSettings(true)
                            .build()))
            .connection(connection)
            .frameLogger(new Http2FrameLogger(LogLevel.DEBUG))
            .build();
    ctx.pipeline()
       .addBefore(ctx.name(), null, http2ConnHandler)
       .addBefore(ctx.name(), null, new Http2Handler());
}
 
Example #6
Source File: Http2BackendHandler.java    From nitmproxy with MIT License 6 votes vote down vote up
@Override
public void handlerAdded(ChannelHandlerContext ctx) throws Exception {
    LOGGER.info("{} : handlerAdded", connectionInfo);

    Http2Connection connection = new DefaultHttp2Connection(false);
    ChannelHandler http2ConnHandler = new HttpToHttp2ConnectionHandlerBuilder()
            .frameListener(new DelegatingDecompressorFrameListener(
                    connection,
                    new InboundHttp2ToHttpAdapterBuilder(connection)
                            .maxContentLength(master.config().getMaxContentLength())
                            .propagateSettings(true)
                            .build()))
            .frameLogger(new Http2FrameLogger(LogLevel.DEBUG))
            .connection(connection)
            .build();
    ctx.pipeline()
       .addBefore(ctx.name(), null, http2ConnHandler)
       .addBefore(ctx.name(), null, new Http2Handler());
}
 
Example #7
Source File: Http2MultiplexedChannelPool.java    From aws-sdk-java-v2 with Apache License 2.0 6 votes vote down vote up
/**
 * By default, connection window size is a constant value:
 * connectionWindowSize = 65535 + (configureInitialWindowSize - 65535) * 2.
 * See https://github.com/netty/netty/blob/5c458c9a98d4d3d0345e58495e017175156d624f/codec-http2/src/main/java/io/netty
 * /handler/codec/http2/Http2FrameCodec.java#L255
 * We should expand connection window so that the window size proportional to the number of concurrent streams within the
 * connection.
 * Note that when {@code WINDOW_UPDATE} will be sent depends on the processedWindow in DefaultHttp2LocalFlowController.
 */
private void tryExpandConnectionWindow(Channel parentChannel) {
    doInEventLoop(parentChannel.eventLoop(), () -> {
        Http2Connection http2Connection = parentChannel.attr(HTTP2_CONNECTION).get();
        Integer initialWindowSize = parentChannel.attr(HTTP2_INITIAL_WINDOW_SIZE).get();

        Validate.notNull(http2Connection, "http2Connection should not be null on channel " + parentChannel);
        Validate.notNull(http2Connection, "initialWindowSize should not be null on channel " + parentChannel);

        Http2Stream connectionStream = http2Connection.connectionStream();
        log.debug(() -> "Expanding connection window size for " + parentChannel + " by " + initialWindowSize);
        try {
            Http2LocalFlowController localFlowController = http2Connection.local().flowController();
            localFlowController.incrementWindowSize(connectionStream, initialWindowSize);

        } catch (Http2Exception e) {
            log.warn(() -> "Failed to increment windowSize of connection " + parentChannel, e);
        }
    });
}
 
Example #8
Source File: Http2ClientInitializer.java    From jmeter-http2-plugin with Apache License 2.0 6 votes vote down vote up
@Override
public void initChannel(SocketChannel ch) throws Exception {
    final Http2Connection connection = new DefaultHttp2Connection(false);

    connectionHandler = new HttpToHttp2ConnectionHandler(connection,
            frameReader(),
            frameWriter(),
            new DelegatingDecompressorFrameListener(connection,
                    new InboundHttp2ToHttpAdapter.Builder(connection)
                            .maxContentLength(maxContentLength)
                            .propagateSettings(true)
                            .build()));
    responseHandler = new HttpResponseHandler();
    settingsHandler = new Http2SettingsHandler(ch.newPromise());
    if (sslCtx != null) {
        configureSsl(ch);
    } else {
        configureClearText(ch);
    }
}
 
Example #9
Source File: ClientHttp2ObjectEncoder.java    From armeria with Apache License 2.0 6 votes vote down vote up
@Override
public ChannelFuture doWriteHeaders(int id, int streamId, RequestHeaders headers, boolean endStream) {
    final Http2Connection conn = encoder().connection();
    if (isStreamPresentAndWritable(streamId)) {
        if (keepAliveHandler != null) {
            keepAliveHandler.onReadOrWrite();
        }
        return encoder().writeHeaders(ctx(), streamId, convertHeaders(headers), 0,
                                      endStream, ctx().newPromise());
    }

    final Endpoint<Http2LocalFlowController> local = conn.local();
    if (local.mayHaveCreatedStream(streamId)) {
        final ClosedStreamException closedStreamException =
                new ClosedStreamException("Cannot create a new stream. streamId: " + streamId +
                                          ", lastStreamCreated: " + local.lastStreamCreated());
        return newFailedFuture(UnprocessedRequestException.of(closedStreamException));
    }

    // Client starts a new stream.
    return encoder().writeHeaders(ctx(), streamId, convertHeaders(headers), 0, endStream,
                                  ctx().newPromise());
}
 
Example #10
Source File: Http2Util.java    From tutorials with MIT License 5 votes vote down vote up
public static ApplicationProtocolNegotiationHandler getClientAPNHandler(int maxContentLength, Http2SettingsHandler settingsHandler, Http2ClientResponseHandler responseHandler) {
    final Http2FrameLogger logger = new Http2FrameLogger(INFO, Http2Util.class);
    final Http2Connection connection = new DefaultHttp2Connection(false);

    HttpToHttp2ConnectionHandler connectionHandler = new HttpToHttp2ConnectionHandlerBuilder()
        .frameListener(new DelegatingDecompressorFrameListener(connection, new InboundHttp2ToHttpAdapterBuilder(connection).maxContentLength(maxContentLength)
        .propagateSettings(true)
        .build()))
        .frameLogger(logger)
        .connection(connection)
        .build();

    ApplicationProtocolNegotiationHandler clientAPNHandler = new ApplicationProtocolNegotiationHandler(ApplicationProtocolNames.HTTP_2) {
        @Override
        protected void configurePipeline(ChannelHandlerContext ctx, String protocol) {
            if (ApplicationProtocolNames.HTTP_2.equals(protocol)) {
                ChannelPipeline p = ctx.pipeline();
                p.addLast(connectionHandler);
                p.addLast(settingsHandler, responseHandler);
                return;
            }
            ctx.close();
            throw new IllegalStateException("Protocol: " + protocol + " not supported");
        }
    };

    return clientAPNHandler;

}
 
Example #11
Source File: AltsProtocolNegotiatorTest.java    From grpc-java with Apache License 2.0 5 votes vote down vote up
private CapturingGrpcHttp2ConnectionHandler capturingGrpcHandler() {
  // Netty Boilerplate.  We don't really need any of this, but there is a tight coupling
  // between an Http2ConnectionHandler and its dependencies.
  Http2Connection connection = new DefaultHttp2Connection(true);
  Http2FrameWriter frameWriter = new DefaultHttp2FrameWriter();
  Http2FrameReader frameReader = new DefaultHttp2FrameReader(false);
  DefaultHttp2ConnectionEncoder encoder =
      new DefaultHttp2ConnectionEncoder(connection, frameWriter);
  DefaultHttp2ConnectionDecoder decoder =
      new DefaultHttp2ConnectionDecoder(connection, encoder, frameReader);

  return new CapturingGrpcHttp2ConnectionHandler(decoder, encoder, new Http2Settings());
}
 
Example #12
Source File: NettyClientHandlerTest.java    From grpc-java with Apache License 2.0 5 votes vote down vote up
@Override
protected NettyClientHandler newHandler() throws Http2Exception {
  Http2Connection connection = new DefaultHttp2Connection(false);

  // Create and close a stream previous to the nextStreamId.
  Http2Stream stream = connection.local().createStream(streamId - 2, true);
  stream.close();

  final Ticker ticker = new Ticker() {
    @Override
    public long read() {
      return nanoTime;
    }
  };
  Supplier<Stopwatch> stopwatchSupplier = new Supplier<Stopwatch>() {
    @Override
    public Stopwatch get() {
      return Stopwatch.createUnstarted(ticker);
    }
  };
  return NettyClientHandler.newHandler(
      connection,
      frameReader(),
      frameWriter(),
      lifecycleManager,
      mockKeepAliveManager,
      false,
      flowControlWindow,
      maxHeaderListSize,
      stopwatchSupplier,
      tooManyPingsRunnable,
      transportTracer,
      Attributes.EMPTY,
      "someauthority");
}
 
Example #13
Source File: NettyClientHandler.java    From grpc-java with Apache License 2.0 5 votes vote down vote up
static NettyClientHandler newHandler(
    ClientTransportLifecycleManager lifecycleManager,
    @Nullable KeepAliveManager keepAliveManager,
    boolean autoFlowControl,
    int flowControlWindow,
    int maxHeaderListSize,
    Supplier<Stopwatch> stopwatchFactory,
    Runnable tooManyPingsRunnable,
    TransportTracer transportTracer,
    Attributes eagAttributes,
    String authority) {
  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);
  WeightedFairQueueByteDistributor dist = new WeightedFairQueueByteDistributor(connection);
  dist.allocationQuantum(16 * 1024); // Make benchmarks fast again.
  DefaultHttp2RemoteFlowController controller =
      new DefaultHttp2RemoteFlowController(connection, dist);
  connection.remote().flowController(controller);

  return newHandler(
      connection,
      frameReader,
      frameWriter,
      lifecycleManager,
      keepAliveManager,
      autoFlowControl,
      flowControlWindow,
      maxHeaderListSize,
      stopwatchFactory,
      tooManyPingsRunnable,
      transportTracer,
      eagAttributes,
      authority);
}
 
Example #14
Source File: Http2ClientStreamMapper.java    From xio with Apache License 2.0 5 votes vote down vote up
public Integer outboundStreamId(Http2Connection connection, Integer id) {
  Integer mappedId = streamMap.get(id);
  if (mappedId == null) {
    mappedId = connection.local().incrementAndGetNextStreamId();
    log.debug("h2 client outbound stream id {} : {}", id, mappedId);
    streamMap.put(id, mappedId);
  }
  return mappedId;
}
 
Example #15
Source File: HttpServerHandler.java    From armeria with Apache License 2.0 5 votes vote down vote up
private static void incrementLocalWindowSize(ChannelPipeline pipeline, int delta) {
    try {
        final Http2Connection connection = pipeline.get(Http2ServerConnectionHandler.class).connection();
        connection.local().flowController().incrementWindowSize(connection.connectionStream(), delta);
    } catch (Http2Exception e) {
        logger.warn("Failed to increment local flowController window size: {}", delta, e);
    }
}
 
Example #16
Source File: HttpClientPipelineConfigurator.java    From armeria with Apache License 2.0 5 votes vote down vote up
private static void incrementLocalWindowSize(ChannelPipeline pipeline, int delta) {
    try {
        final Http2Connection connection = pipeline.get(Http2ClientConnectionHandler.class).connection();
        connection.local().flowController().incrementWindowSize(connection.connectionStream(), delta);
    } catch (Http2Exception e) {
        logger.warn("Failed to increment local flowController window size: {}", delta, e);
    }
}
 
Example #17
Source File: THttp2Client.java    From armeria with Apache License 2.0 5 votes vote down vote up
@Override
public void initChannel(SocketChannel ch) throws Exception {
    final ChannelPipeline p = ch.pipeline();
    final Http2Connection conn = new DefaultHttp2Connection(false);
    final HttpToHttp2ConnectionHandler connHandler = new HttpToHttp2ConnectionHandlerBuilder()
            .connection(conn)
            .frameListener(new DelegatingDecompressorFrameListener(
                    conn,
                    new InboundHttp2ToHttpAdapterBuilder(conn)
                            .maxContentLength(Integer.MAX_VALUE)
                            .propagateSettings(true).build()))
            .build();

    clientHandler = new THttp2ClientHandler(ch.eventLoop());

    if (sslCtx != null) {
        p.addLast(sslCtx.newHandler(p.channel().alloc()));
        p.addLast(connHandler);
        configureEndOfPipeline(p);
    } else {
        final HttpClientCodec sourceCodec = new HttpClientCodec();
        final HttpClientUpgradeHandler upgradeHandler = new HttpClientUpgradeHandler(
                sourceCodec, new Http2ClientUpgradeCodec(connHandler), 65536);

        p.addLast(sourceCodec, upgradeHandler, new UpgradeRequestHandler());
    }
}
 
Example #18
Source File: AltsProtocolNegotiatorTest.java    From grpc-nebula-java with Apache License 2.0 5 votes vote down vote up
private CapturingGrpcHttp2ConnectionHandler capturingGrpcHandler() {
  // Netty Boilerplate.  We don't really need any of this, but there is a tight coupling
  // between a Http2ConnectionHandler and its dependencies.
  Http2Connection connection = new DefaultHttp2Connection(true);
  Http2FrameWriter frameWriter = new DefaultHttp2FrameWriter();
  Http2FrameReader frameReader = new DefaultHttp2FrameReader(false);
  DefaultHttp2ConnectionEncoder encoder =
      new DefaultHttp2ConnectionEncoder(connection, frameWriter);
  DefaultHttp2ConnectionDecoder decoder =
      new DefaultHttp2ConnectionDecoder(connection, encoder, frameReader);

  return new CapturingGrpcHttp2ConnectionHandler(decoder, encoder, new Http2Settings());
}
 
Example #19
Source File: NettyClientHandlerTest.java    From grpc-nebula-java with Apache License 2.0 5 votes vote down vote up
@Override
protected NettyClientHandler newHandler() throws Http2Exception {
  Http2Connection connection = new DefaultHttp2Connection(false);

  // Create and close a stream previous to the nextStreamId.
  Http2Stream stream = connection.local().createStream(streamId - 2, true);
  stream.close();

  final Ticker ticker = new Ticker() {
    @Override
    public long read() {
      return nanoTime;
    }
  };
  Supplier<Stopwatch> stopwatchSupplier = new Supplier<Stopwatch>() {
    @Override
    public Stopwatch get() {
      return Stopwatch.createUnstarted(ticker);
    }
  };
  return NettyClientHandler.newHandler(
      connection,
      frameReader(),
      frameWriter(),
      lifecycleManager,
      mockKeepAliveManager,
      flowControlWindow,
      maxHeaderListSize,
      stopwatchSupplier,
      tooManyPingsRunnable,
      transportTracer,
      Attributes.EMPTY,
      "someauthority");
}
 
Example #20
Source File: NettyClientHandler.java    From grpc-nebula-java with Apache License 2.0 5 votes vote down vote up
static NettyClientHandler newHandler(
    ClientTransportLifecycleManager lifecycleManager,
    @Nullable KeepAliveManager keepAliveManager,
    int flowControlWindow,
    int maxHeaderListSize,
    Supplier<Stopwatch> stopwatchFactory,
    Runnable tooManyPingsRunnable,
    TransportTracer transportTracer,
    Attributes eagAttributes,
    String authority) {
  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);
  WeightedFairQueueByteDistributor dist = new WeightedFairQueueByteDistributor(connection);
  dist.allocationQuantum(16 * 1024); // Make benchmarks fast again.
  DefaultHttp2RemoteFlowController controller =
      new DefaultHttp2RemoteFlowController(connection, dist);
  connection.remote().flowController(controller);

  return newHandler(
      connection,
      frameReader,
      frameWriter,
      lifecycleManager,
      keepAliveManager,
      flowControlWindow,
      maxHeaderListSize,
      stopwatchFactory,
      tooManyPingsRunnable,
      transportTracer,
      eagAttributes,
      authority);
}
 
Example #21
Source File: HelloWorldHttp2Handler.java    From netty-cookbook with Apache License 2.0 4 votes vote down vote up
private HelloWorldHttp2Handler(Http2Connection connection, Http2FrameReader frameReader,
        Http2FrameWriter frameWriter, SimpleHttp2FrameListener listener) {
    super(connection, frameReader, frameWriter, listener);
    listener.encoder(encoder());
}
 
Example #22
Source File: NettyServerHandler.java    From grpc-java with Apache License 2.0 4 votes vote down vote up
@VisibleForTesting
static NettyServerHandler newHandler(
    ChannelPromise channelUnused,
    Http2FrameReader frameReader,
    Http2FrameWriter frameWriter,
    ServerTransportListener transportListener,
    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) {
  Preconditions.checkArgument(maxStreams > 0, "maxStreams must be positive: %s", maxStreams);
  Preconditions.checkArgument(flowControlWindow > 0, "flowControlWindow must be positive: %s",
      flowControlWindow);
  Preconditions.checkArgument(maxHeaderListSize > 0, "maxHeaderListSize must be positive: %s",
      maxHeaderListSize);
  Preconditions.checkArgument(maxMessageSize > 0, "maxMessageSize must be positive: %s",
      maxMessageSize);

  final Http2Connection connection = new DefaultHttp2Connection(true);
  WeightedFairQueueByteDistributor dist = new WeightedFairQueueByteDistributor(connection);
  dist.allocationQuantum(16 * 1024); // Make benchmarks fast again.
  DefaultHttp2RemoteFlowController controller =
      new DefaultHttp2RemoteFlowController(connection, dist);
  connection.remote().flowController(controller);
  final KeepAliveEnforcer keepAliveEnforcer = new KeepAliveEnforcer(
      permitKeepAliveWithoutCalls, permitKeepAliveTimeInNanos, TimeUnit.NANOSECONDS);

  // Create the local flow controller configured to auto-refill the connection window.
  connection.local().flowController(
      new DefaultHttp2LocalFlowController(connection, DEFAULT_WINDOW_UPDATE_RATIO, true));
  frameWriter = new WriteMonitoringFrameWriter(frameWriter, keepAliveEnforcer);
  Http2ConnectionEncoder encoder =
      new ListeningDefaultHttp2ConnectionEncoder(connection, frameWriter);
  encoder = new Http2ControlFrameLimitEncoder(encoder, 10000);
  Http2ConnectionDecoder decoder = new DefaultHttp2ConnectionDecoder(connection, encoder,
      frameReader);

  Http2Settings settings = new Http2Settings();
  settings.initialWindowSize(flowControlWindow);
  settings.maxConcurrentStreams(maxStreams);
  settings.maxHeaderListSize(maxHeaderListSize);

  return new NettyServerHandler(
      channelUnused,
      connection,
      transportListener,
      streamTracerFactories,
      transportTracer,
      decoder, encoder, settings,
      maxMessageSize,
      keepAliveTimeInNanos, keepAliveTimeoutInNanos,
      maxConnectionIdleInNanos,
      maxConnectionAgeInNanos, maxConnectionAgeGraceInNanos,
      keepAliveEnforcer,
      autoFlowControl);
}
 
Example #23
Source File: NettyHandlerTestBase.java    From grpc-nebula-java with Apache License 2.0 4 votes vote down vote up
protected final Http2Connection connection() {
  return handler().connection();
}
 
Example #24
Source File: ListeningEncoder.java    From grpc-java with Apache License 2.0 4 votes vote down vote up
public ListeningDefaultHttp2ConnectionEncoder(
    Http2Connection connection, Http2FrameWriter frameWriter) {
  super(connection, frameWriter);
}
 
Example #25
Source File: NettyHandlerTestBase.java    From grpc-java with Apache License 2.0 4 votes vote down vote up
protected final Http2Connection connection() {
  return handler().connection();
}
 
Example #26
Source File: NettyServerHandler.java    From grpc-nebula-java with Apache License 2.0 4 votes vote down vote up
@VisibleForTesting
static NettyServerHandler newHandler(
    ChannelPromise channelUnused,
    Http2FrameReader frameReader,
    Http2FrameWriter frameWriter,
    ServerTransportListener transportListener,
    List<ServerStreamTracer.Factory> streamTracerFactories,
    TransportTracer transportTracer,
    int maxStreams,
    int flowControlWindow,
    int maxHeaderListSize,
    int maxMessageSize,
    long keepAliveTimeInNanos,
    long keepAliveTimeoutInNanos,
    long maxConnectionIdleInNanos,
    long maxConnectionAgeInNanos,
    long maxConnectionAgeGraceInNanos,
    boolean permitKeepAliveWithoutCalls,
    long permitKeepAliveTimeInNanos) {
  Preconditions.checkArgument(maxStreams > 0, "maxStreams must be positive");
  Preconditions.checkArgument(flowControlWindow > 0, "flowControlWindow must be positive");
  Preconditions.checkArgument(maxHeaderListSize > 0, "maxHeaderListSize must be positive");
  Preconditions.checkArgument(maxMessageSize > 0, "maxMessageSize must be positive");

  final Http2Connection connection = new DefaultHttp2Connection(true);
  WeightedFairQueueByteDistributor dist = new WeightedFairQueueByteDistributor(connection);
  dist.allocationQuantum(16 * 1024); // Make benchmarks fast again.
  DefaultHttp2RemoteFlowController controller =
      new DefaultHttp2RemoteFlowController(connection, dist);
  connection.remote().flowController(controller);
  final KeepAliveEnforcer keepAliveEnforcer = new KeepAliveEnforcer(
      permitKeepAliveWithoutCalls, permitKeepAliveTimeInNanos, TimeUnit.NANOSECONDS);

  // Create the local flow controller configured to auto-refill the connection window.
  connection.local().flowController(
      new DefaultHttp2LocalFlowController(connection, DEFAULT_WINDOW_UPDATE_RATIO, true));
  frameWriter = new WriteMonitoringFrameWriter(frameWriter, keepAliveEnforcer);
  Http2ConnectionEncoder encoder = new DefaultHttp2ConnectionEncoder(connection, frameWriter);
  Http2ConnectionDecoder decoder = new DefaultHttp2ConnectionDecoder(connection, encoder,
      frameReader);

  Http2Settings settings = new Http2Settings();
  settings.initialWindowSize(flowControlWindow);
  settings.maxConcurrentStreams(maxStreams);
  settings.maxHeaderListSize(maxHeaderListSize);

  return new NettyServerHandler(
      channelUnused,
      connection,
      transportListener,
      streamTracerFactories,
      transportTracer,
      decoder, encoder, settings,
      maxMessageSize,
      keepAliveTimeInNanos, keepAliveTimeoutInNanos,
      maxConnectionIdleInNanos,
      maxConnectionAgeInNanos, maxConnectionAgeGraceInNanos,
      keepAliveEnforcer);
}