Example usage for io.netty.handler.codec.http2 Http2Settings initialWindowSize

List of usage examples for io.netty.handler.codec.http2 Http2Settings initialWindowSize

Introduction

In this page you can find the example usage for io.netty.handler.codec.http2 Http2Settings initialWindowSize.

Prototype

public Http2Settings initialWindowSize(int value) 

Source Link

Document

Sets the SETTINGS_INITIAL_WINDOW_SIZE value.

Usage

From source file:com.linecorp.armeria.client.HttpClientPipelineConfigurator.java

License:Apache License

private Http2Settings http2Settings() {
    final Http2Settings http2Settings = new Http2Settings();
    if (clientFactory.initialHttp2StreamWindowSize() != DEFAULT_WINDOW_SIZE) {
        http2Settings.initialWindowSize(clientFactory.initialHttp2StreamWindowSize());
    }//w w  w .j a  v  a 2  s. c  om
    if (clientFactory.http2MaxFrameSize() != DEFAULT_MAX_FRAME_SIZE) {
        http2Settings.maxFrameSize(clientFactory.http2MaxFrameSize());
    }
    return http2Settings;
}

From source file:com.netty.grpc.proxy.demo.handler.GrpcProxyBackendHandler.java

License:Apache License

@Override
public void channelActive(ChannelHandlerContext ctx) {
    // /*from  ww w . j a  v  a 2  s .c o m*/
    Http2Settings settings = new Http2Settings();
    settings.initialWindowSize(DEFAULT_FLOW_CONTROL_WINDOW);
    settings.pushEnabled(false);
    settings.maxConcurrentStreams(0);
    ByteBuf preface = Http2CodecUtil.connectionPrefaceBuf().retainedDuplicate();
    ctx.write(preface);
    writer.writeSettings(ctx, settings, ctx.newPromise());
    writer.writeWindowUpdate(ctx, 0, 983041, ctx.newPromise());
    ctx.flush();
    ctx.read();
}

From source file:com.vmware.xenon.common.http.netty.NettyHttpClientRequestInitializer.java

License:Open Source License

/**
 * For HTTP/2 we don't have anything as simple as the HttpClientCodec (at least, not in Netty
 * 5.0alpha 2), so we create the equivalent here.
 *
 * @return//from  www. j  a v a2 s.  co m
 */
private NettyHttpToHttp2Handler makeHttp2ConnectionHandler() {
    // DefaultHttp2Connection is for client or server. False means "client".
    Http2Connection connection = new DefaultHttp2Connection(false);
    InboundHttp2ToHttpAdapter inboundAdapter = new InboundHttp2ToHttpAdapterBuilder(connection)
            .maxContentLength(this.requestPayloadSizeLimit).propagateSettings(true).build();
    DelegatingDecompressorFrameListener frameListener = new DelegatingDecompressorFrameListener(connection,
            inboundAdapter);

    Http2Settings settings = new Http2Settings();
    settings.initialWindowSize(NettyChannelContext.INITIAL_HTTP2_WINDOW_SIZE);

    NettyHttpToHttp2HandlerBuilder builder = new NettyHttpToHttp2HandlerBuilder().connection(connection)
            .frameListener(frameListener).initialSettings(settings);
    if (this.debugLogging) {
        Http2FrameLogger frameLogger = new Http2FrameLogger(LogLevel.INFO,
                NettyHttpClientRequestInitializer.class);
        builder.frameLogger(frameLogger);
    }
    NettyHttpToHttp2Handler connectionHandler = builder.build();

    return connectionHandler;
}

From source file:com.vmware.xenon.common.http.netty.NettyHttpServerInitializer.java

License:Open Source License

/**
 * For HTTP/2 we don't have anything as simple as the HttpServerCodec (at least, not in Netty
 * 5.0alpha 2), so we create the equivalent.
 *
 * @return//ww  w  . ja  v a 2 s  .c om
 */
private HttpToHttp2ConnectionHandler makeHttp2ConnectionHandler() {
    // DefaultHttp2Connection is for client or server. True means "server".
    Http2Connection connection = new DefaultHttp2Connection(true);
    InboundHttp2ToHttpAdapter inboundAdapter = new InboundHttp2ToHttpAdapterBuilder(connection)
            .maxContentLength(this.responsePayloadSizeLimit).propagateSettings(false).build();
    DelegatingDecompressorFrameListener frameListener = new DelegatingDecompressorFrameListener(connection,
            inboundAdapter);

    Http2Settings settings = new Http2Settings();
    //settings.maxConcurrentStreams(NettyHttpServiceClient.DEFAULT_HTTP2_STREAMS_PER_HOST);
    settings.initialWindowSize(NettyChannelContext.INITIAL_HTTP2_WINDOW_SIZE);

    HttpToHttp2ConnectionHandlerBuilder builder = new HttpToHttp2ConnectionHandlerBuilder()
            .frameListener(frameListener).initialSettings(settings).connection(connection);

    if (debugLogging) {
        Http2FrameLogger frameLogger = new Http2FrameLogger(LogLevel.INFO,
                NettyHttpClientRequestInitializer.class);
        builder.frameLogger(frameLogger);
    }

    HttpToHttp2ConnectionHandler connectionHandler = builder.build();

    return connectionHandler;
}

From source file:io.grpc.netty.FixedHttp2ConnectionDecoder.java

License:Apache License

@Override
public Http2Settings localSettings() {
    Http2Settings settings = new Http2Settings();
    Http2FrameReader.Configuration config = frameReader.configuration();
    Http2HeadersDecoder.Configuration headersConfig = config.headersConfiguration();
    Http2FrameSizePolicy frameSizePolicy = config.frameSizePolicy();
    settings.initialWindowSize(flowController().initialWindowSize());
    settings.maxConcurrentStreams(connection.remote().maxActiveStreams());
    settings.headerTableSize(headersConfig.maxHeaderTableSize());
    settings.maxFrameSize(frameSizePolicy.maxFrameSize());
    settings.maxHeaderListSize(headersConfig.maxHeaderListSize());
    if (!connection.isServer()) {
        // Only set the pushEnabled flag if this is a client endpoint.
        settings.pushEnabled(connection.local().allowPushTo());
    }//  ww w  . ja va 2s  . c o  m
    return settings;
}

From source file:io.grpc.netty.NettyClientHandler.java

License:Apache License

@VisibleForTesting
static NettyClientHandler newHandler(final Http2Connection connection, Http2FrameReader frameReader,
        Http2FrameWriter frameWriter, ClientTransportLifecycleManager lifecycleManager,
        KeepAliveManager keepAliveManager, int flowControlWindow, int maxHeaderListSize,
        Supplier<Stopwatch> stopwatchFactory, Runnable tooManyPingsRunnable, TransportTracer transportTracer,
        Attributes eagAttributes, String authority) {
    Preconditions.checkNotNull(connection, "connection");
    Preconditions.checkNotNull(frameReader, "frameReader");
    Preconditions.checkNotNull(lifecycleManager, "lifecycleManager");
    Preconditions.checkArgument(flowControlWindow > 0, "flowControlWindow must be positive");
    Preconditions.checkArgument(maxHeaderListSize > 0, "maxHeaderListSize must be positive");
    Preconditions.checkNotNull(stopwatchFactory, "stopwatchFactory");
    Preconditions.checkNotNull(tooManyPingsRunnable, "tooManyPingsRunnable");
    Preconditions.checkNotNull(eagAttributes, "eagAttributes");
    Preconditions.checkNotNull(authority, "authority");

    Http2FrameLogger frameLogger = new Http2FrameLogger(LogLevel.DEBUG, NettyClientHandler.class);
    frameReader = new Http2InboundFrameLogger(frameReader, frameLogger);
    frameWriter = new Http2OutboundFrameLogger(frameWriter, frameLogger);

    StreamBufferingEncoder encoder = new StreamBufferingEncoder(
            new DefaultHttp2ConnectionEncoder(connection, frameWriter));

    // Create the local flow controller configured to auto-refill the connection window.
    connection.local()//from  ww w.  j a  v a2 s. co  m
            .flowController(new DefaultHttp2LocalFlowController(connection, DEFAULT_WINDOW_UPDATE_RATIO, true));

    Http2ConnectionDecoder decoder = new DefaultHttp2ConnectionDecoder(connection, encoder, frameReader);

    transportTracer.setFlowControlWindowReader(new TransportTracer.FlowControlReader() {
        final Http2FlowController local = connection.local().flowController();
        final Http2FlowController remote = connection.remote().flowController();

        @Override
        public TransportTracer.FlowControlWindows read() {
            return new TransportTracer.FlowControlWindows(local.windowSize(connection.connectionStream()),
                    remote.windowSize(connection.connectionStream()));
        }
    });

    Http2Settings settings = new Http2Settings();
    settings.pushEnabled(false);
    settings.initialWindowSize(flowControlWindow);
    settings.maxConcurrentStreams(0);
    settings.maxHeaderListSize(maxHeaderListSize);

    return new NettyClientHandler(decoder, encoder, settings, lifecycleManager, keepAliveManager,
            stopwatchFactory, tooManyPingsRunnable, transportTracer, eagAttributes, authority);
}

From source file:io.grpc.netty.NettyServerHandler.java

License:Apache License

@VisibleForTesting
static NettyServerHandler newHandler(ChannelPromise channelUnused, Http2FrameReader frameReader,
        Http2FrameWriter frameWriter, ServerTransportListener transportListener,
        List<? extends 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()//  ww w. j av  a 2 s .  c o m
            .flowController(new DefaultHttp2LocalFlowController(connection, DEFAULT_WINDOW_UPDATE_RATIO, true));
    frameWriter = new WriteMonitoringFrameWriter(frameWriter, keepAliveEnforcer);
    Http2ConnectionEncoder encoder = new DefaultHttp2ConnectionEncoder(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);
}

From source file:io.vertx.core.http.impl.HttpUtils.java

License:Open Source License

public static void fromVertxInitialSettings(boolean server, io.vertx.core.http.Http2Settings vertxSettings,
        Http2Settings nettySettings) {
    if (vertxSettings != null) {
        if (!server && vertxSettings.isPushEnabled() != DEFAULT_ENABLE_PUSH) {
            nettySettings.pushEnabled(vertxSettings.isPushEnabled());
        }/*  w w w  .  j  a va  2s  . co  m*/
        if (vertxSettings.getHeaderTableSize() != DEFAULT_HEADER_TABLE_SIZE) {
            nettySettings.put('\u0001', (Long) vertxSettings.getHeaderTableSize());
        }
        if (vertxSettings.getInitialWindowSize() != DEFAULT_INITIAL_WINDOW_SIZE) {
            nettySettings.initialWindowSize(vertxSettings.getInitialWindowSize());
        }
        if (vertxSettings.getMaxConcurrentStreams() != DEFAULT_MAX_CONCURRENT_STREAMS) {
            nettySettings.maxConcurrentStreams(vertxSettings.getMaxConcurrentStreams());
        }
        if (vertxSettings.getMaxFrameSize() != DEFAULT_MAX_FRAME_SIZE) {
            nettySettings.maxFrameSize(vertxSettings.getMaxFrameSize());
        }
        if (vertxSettings.getMaxHeaderListSize() != DEFAULT_MAX_HEADER_LIST_SIZE) {
            nettySettings.maxHeaderListSize(vertxSettings.getMaxHeaderListSize());
        }
        Map<Integer, Long> extraSettings = vertxSettings.getExtraSettings();
        if (extraSettings != null) {
            extraSettings.forEach((code, setting) -> {
                nettySettings.put((char) (int) code, setting);
            });
        }
    }
}

From source file:io.vertx.core.http.impl.HttpUtils.java

License:Open Source License

public static Http2Settings fromVertxSettings(io.vertx.core.http.Http2Settings settings) {
    Http2Settings converted = new Http2Settings();
    converted.pushEnabled(settings.isPushEnabled());
    converted.maxFrameSize(settings.getMaxFrameSize());
    converted.initialWindowSize(settings.getInitialWindowSize());
    converted.headerTableSize(settings.getHeaderTableSize());
    converted.maxConcurrentStreams(settings.getMaxConcurrentStreams());
    converted.maxHeaderListSize(settings.getMaxHeaderListSize());
    if (settings.getExtraSettings() != null) {
        settings.getExtraSettings().forEach((key, value) -> {
            converted.put((char) (int) key, value);
        });/*from  w w w  .j  av a2  s  .c o m*/
    }
    return converted;
}

From source file:netty.http2.NettyHttp2ClientInitializer.java

License:Apache License

@Override
public void initChannel(SocketChannel ch) throws Exception {
    final Http2Connection connection = new DefaultHttp2Connection(false);
    final Http2Settings settings = new Http2Settings();
    settings.initialWindowSize(65535);
    settings.headerTableSize(4096);/*from   www .  j  a v a 2  s  .c  om*/
    connectionHandler = new HttpToHttp2ConnectionHandlerBuilder()
            .frameListener(new DelegatingDecompressorFrameListener(connection,
                    new InboundHttp2ToHttpAdapterBuilder(connection).maxContentLength(maxContentLength)
                            .propagateSettings(true).build()))
            .frameLogger(logger).initialSettings(settings).connection(connection).build();
    responseHandler = new HttpResponseHandler();
    settingsHandler = new Http2SettingsHandler(ch.newPromise());
    if (sslCtx != null) {
        configureSsl(ch);
    } else {
        configureClearText(ch);
    }
}