List of usage examples for io.netty.handler.codec.http2 Http2Connection remote
Endpoint<Http2RemoteFlowController> remote();
From source file:io.grpc.netty.NettyClientHandler.java
License:Apache License
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);/*ww w . j a v a 2 s . co m*/ }
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 w w w . ja v a 2 s . c o 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()/*from www . ja va 2s. co 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.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//w w w . ja v a2s .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); }