Java Code Examples for io.netty.handler.codec.http2.Http2Settings#maxConcurrentStreams()

The following examples show how to use io.netty.handler.codec.http2.Http2Settings#maxConcurrentStreams() . 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: HttpServerPipelineConfigurator.java    From armeria with Apache License 2.0 6 votes vote down vote up
private Http2Settings http2Settings() {
    final Http2Settings settings = new Http2Settings();
    final int initialWindowSize = config.http2InitialStreamWindowSize();
    if (initialWindowSize != Http2CodecUtil.DEFAULT_WINDOW_SIZE) {
        settings.initialWindowSize(initialWindowSize);
    }

    final int maxFrameSize = config.http2MaxFrameSize();
    if (maxFrameSize != Http2CodecUtil.DEFAULT_MAX_FRAME_SIZE) {
        settings.maxFrameSize(maxFrameSize);
    }

    // Not using the value greater than 2^31-1 because some HTTP/2 client implementations use a signed
    // 32-bit integer to represent an HTTP/2 SETTINGS parameter value.
    settings.maxConcurrentStreams(Math.min(config.http2MaxStreamsPerConnection(), Integer.MAX_VALUE));
    settings.maxHeaderListSize(config.http2MaxHeaderListSize());
    return settings;
}
 
Example 2
Source File: Http2SettingsFrameHandlerTest.java    From aws-sdk-java-v2 with Apache License 2.0 5 votes vote down vote up
private Http2SettingsFrame http2SettingsFrame(long serverMaxStreams) {
    return new Http2SettingsFrame() {
        @Override
        public Http2Settings settings() {
            Http2Settings http2Settings = new Http2Settings();
            http2Settings.maxConcurrentStreams(serverMaxStreams);
            return http2Settings;
        }

        @Override
        public String name() {
            return "test";
        }
    };
}
 
Example 3
Source File: Http2SettingsSpec.java    From reactor-netty with Apache License 2.0 5 votes vote down vote up
Http2SettingsSpec(Build build) {
	Http2Settings settings = build.http2Settings;
	headerTableSize = settings.headerTableSize();
	initialWindowSize = settings.initialWindowSize();
	maxConcurrentStreams = settings.maxConcurrentStreams();
	maxFrameSize = settings.maxFrameSize();
	maxHeaderListSize = settings.maxHeaderListSize();
	pushEnabled = settings.pushEnabled();
}
 
Example 4
Source File: HttpClientConfig.java    From reactor-netty with Apache License 2.0 5 votes vote down vote up
Http2Settings http2Settings() {
	Http2Settings settings = Http2Settings.defaultSettings();

	if (http2Settings != null) {
		Long headerTableSize = http2Settings.headerTableSize();
		if (headerTableSize != null) {
			settings.headerTableSize(headerTableSize);
		}

		Integer initialWindowSize = http2Settings.initialWindowSize();
		if (initialWindowSize != null) {
			settings.initialWindowSize(initialWindowSize);
		}

		Long maxConcurrentStreams = http2Settings.maxConcurrentStreams();
		if (maxConcurrentStreams != null) {
			settings.maxConcurrentStreams(maxConcurrentStreams);
		}

		Integer maxFrameSize = http2Settings.maxFrameSize();
		if (maxFrameSize != null) {
			settings.maxFrameSize(maxFrameSize);
		}

		settings.maxHeaderListSize(http2Settings.maxHeaderListSize());

		Boolean pushEnabled = http2Settings.pushEnabled();
		if (pushEnabled != null) {
			settings.pushEnabled(pushEnabled);
		}
	}

	return settings;
}
 
Example 5
Source File: HttpServerConfig.java    From reactor-netty with Apache License 2.0 5 votes vote down vote up
Http2Settings http2Settings() {
	Http2Settings settings = Http2Settings.defaultSettings();

	if (http2Settings != null) {
		Long headerTableSize = http2Settings.headerTableSize();
		if (headerTableSize != null) {
			settings.headerTableSize(headerTableSize);
		}

		Integer initialWindowSize = http2Settings.initialWindowSize();
		if (initialWindowSize != null) {
			settings.initialWindowSize(initialWindowSize);
		}

		Long maxConcurrentStreams = http2Settings.maxConcurrentStreams();
		if (maxConcurrentStreams != null) {
			settings.maxConcurrentStreams(maxConcurrentStreams);
		}

		Integer maxFrameSize = http2Settings.maxFrameSize();
		if (maxFrameSize != null) {
			settings.maxFrameSize(maxFrameSize);
		}

		settings.maxHeaderListSize(http2Settings.maxHeaderListSize());

		Boolean pushEnabled = http2Settings.pushEnabled();
		if (pushEnabled != null) {
			settings.pushEnabled(pushEnabled);
		}
	}

	return settings;
}
 
Example 6
Source File: Http2ClientInitializer.java    From jmeter-http2-plugin with Apache License 2.0 5 votes vote down vote up
private Http2FrameWriter frameWriter() {
    // Set initial SETTINGS
    Http2Settings settings = new Http2Settings();
    settings.pushEnabled(false);
    settings.maxConcurrentStreams(100);

    return new Http2OutboundFrameLogger(new CustomHttp2FrameWriter(settings), logger);
}
 
Example 7
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);
}
 
Example 8
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);
}