Example usage for io.netty.handler.codec.http2 Http2Connection connectionStream

List of usage examples for io.netty.handler.codec.http2 Http2Connection connectionStream

Introduction

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

Prototype

Http2Stream connectionStream();

Source Link

Document

Gets the stream object representing the connection, itself (i.e.

Usage

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

License:Apache License

private static void incrementLocalWindowSize(ChannelPipeline pipeline, int delta) {
    try {/*from w ww.  j a v a 2  s. c o m*/
        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);
    }
}

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  . jav  a  2 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

@Override
public void handlerAdded(final ChannelHandlerContext ctx) throws Exception {
    serverWriteQueue = new WriteQueue(ctx.channel());

    // init max connection age monitor
    if (maxConnectionAgeInNanos != MAX_CONNECTION_AGE_NANOS_DISABLED) {
        maxConnectionAgeMonitor = ctx.executor().schedule(new LogExceptionRunnable(new Runnable() {
            @Override/*from w w w .  ja  va 2  s  .co m*/
            public void run() {
                if (gracefulShutdown == null) {
                    gracefulShutdown = new GracefulShutdown("max_age", maxConnectionAgeGraceInNanos);
                    gracefulShutdown.start(ctx);
                    ctx.flush();
                }
            }
        }), maxConnectionAgeInNanos, TimeUnit.NANOSECONDS);
    }

    if (maxConnectionIdleManager != null) {
        maxConnectionIdleManager.start(ctx);
    }

    if (keepAliveTimeInNanos != SERVER_KEEPALIVE_TIME_NANOS_DISABLED) {
        keepAliveManager = new KeepAliveManager(new KeepAlivePinger(ctx), ctx.executor(), keepAliveTimeInNanos,
                keepAliveTimeoutInNanos, true /* keepAliveDuringTransportIdle */);
        keepAliveManager.onTransportStarted();
    }

    if (transportTracer != null) {
        assert encoder().connection().equals(decoder().connection());
        final Http2Connection connection = encoder().connection();
        transportTracer.setFlowControlWindowReader(new TransportTracer.FlowControlReader() {
            private final Http2FlowController local = connection.local().flowController();
            private final Http2FlowController remote = connection.remote().flowController();

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

    super.handlerAdded(ctx);
}