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

The following examples show how to use io.netty.handler.codec.http2.Http2ConnectionDecoder. 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: AbstractNettyHandler.java    From grpc-java with Apache License 2.0 6 votes vote down vote up
AbstractNettyHandler(
    ChannelPromise channelUnused,
    Http2ConnectionDecoder decoder,
    Http2ConnectionEncoder encoder,
    Http2Settings initialSettings,
    boolean autoFlowControl) {
  super(channelUnused, decoder, encoder, initialSettings);

  // During a graceful shutdown, wait until all streams are closed.
  gracefulShutdownTimeoutMillis(GRACEFUL_SHUTDOWN_NO_TIMEOUT);

  // Extract the connection window from the settings if it was set.
  this.initialConnectionWindow = initialSettings.initialWindowSize() == null ? -1 :
          initialSettings.initialWindowSize();
  this.autoTuneFlowControlOn = autoFlowControl;
  if (encoder instanceof ListeningEncoder) {
    ((ListeningEncoder) encoder).setListener(pingCountingListener);
  }
}
 
Example #2
Source File: GrpcHttp2ConnectionHandler.java    From grpc-nebula-java with Apache License 2.0 5 votes vote down vote up
public GrpcHttp2ConnectionHandler(
    ChannelPromise channelUnused,
    Http2ConnectionDecoder decoder,
    Http2ConnectionEncoder encoder,
    Http2Settings initialSettings) {
  super(decoder, encoder, initialSettings);
  this.channelUnused = channelUnused;
}
 
Example #3
Source File: ProtocolNegotiatorsTest.java    From grpc-java with Apache License 2.0 5 votes vote down vote up
FakeGrpcHttp2ConnectionHandler(ChannelPromise channelUnused,
    Http2ConnectionDecoder decoder,
    Http2ConnectionEncoder encoder,
    Http2Settings initialSettings,
    boolean noop) {
  super(channelUnused, decoder, encoder, initialSettings);
  this.noop = noop;
}
 
Example #4
Source File: GrpcHttp2ConnectionHandler.java    From grpc-java with Apache License 2.0 5 votes vote down vote up
public GrpcHttp2ConnectionHandler(
    ChannelPromise channelUnused,
    Http2ConnectionDecoder decoder,
    Http2ConnectionEncoder encoder,
    Http2Settings initialSettings) {
  super(decoder, encoder, initialSettings);
  this.channelUnused = channelUnused;
}
 
Example #5
Source File: SdsProtocolNegotiatorsTest.java    From grpc-java with Apache License 2.0 5 votes vote down vote up
FakeGrpcHttp2ConnectionHandler(
    ChannelPromise channelUnused,
    Http2ConnectionDecoder decoder,
    Http2ConnectionEncoder encoder,
    Http2Settings initialSettings) {
  super(channelUnused, decoder, encoder, initialSettings);
}
 
Example #6
Source File: Http2Server.java    From glowroot with Apache License 2.0 5 votes vote down vote up
@Override
protected Http2ServerHandler build(Http2ConnectionDecoder decoder,
        Http2ConnectionEncoder encoder, Http2Settings initialSettings) {
    Http2ServerHandler handler = new Http2ServerHandler(decoder, encoder, initialSettings);
    frameListener(handler);
    return handler;
}
 
Example #7
Source File: Http2ServerConnectionHandler.java    From armeria with Apache License 2.0 5 votes vote down vote up
Http2ServerConnectionHandler(Http2ConnectionDecoder decoder, Http2ConnectionEncoder encoder,
                             Http2Settings initialSettings, Channel channel, ServerConfig config,
                             Timer keepAliveTimer, GracefulShutdownSupport gracefulShutdownSupport,
                             String scheme) {

    super(decoder, encoder, initialSettings);
    this.gracefulShutdownSupport = gracefulShutdownSupport;

    if (config.idleTimeoutMillis() > 0 || config.pingIntervalMillis() > 0) {
        keepAliveHandler = new Http2ServerKeepAliveHandler(
                channel, encoder().frameWriter(), keepAliveTimer,
                config.idleTimeoutMillis(), config.pingIntervalMillis(), config.maxConnectionAgeMillis());
    } else {
        keepAliveHandler = null;
    }

    requestDecoder = new Http2RequestDecoder(config, channel, encoder(), scheme, keepAliveHandler);
    connection().addListener(requestDecoder);
    decoder().frameListener(requestDecoder);

    // Setup post build options
    final long timeout = config.idleTimeoutMillis();
    if (timeout > 0) {
        gracefulShutdownTimeoutMillis(timeout);
    } else {
        // Timeout disabled
        gracefulShutdownTimeoutMillis(-1);
    }
}
 
Example #8
Source File: Http2ServerConnectionHandlerBuilder.java    From armeria with Apache License 2.0 5 votes vote down vote up
@Override
protected Http2ServerConnectionHandler build(Http2ConnectionDecoder decoder,
                                             Http2ConnectionEncoder encoder,
                                             Http2Settings initialSettings) throws Exception {
    return new Http2ServerConnectionHandler(decoder, encoder, initialSettings, channel(),
                                            config, keepAliveTimer, gracefulShutdownSupport, scheme);
}
 
Example #9
Source File: Http2ClientConnectionHandlerBuilder.java    From armeria with Apache License 2.0 5 votes vote down vote up
@Override
protected Http2ClientConnectionHandler build(Http2ConnectionDecoder decoder,
                                             Http2ConnectionEncoder encoder,
                                             Http2Settings initialSettings) throws Exception {
    return new Http2ClientConnectionHandler(
            decoder, encoder, initialSettings, channel(), clientFactory, protocol);
}
 
Example #10
Source File: Http2ClientConnectionHandler.java    From armeria with Apache License 2.0 5 votes vote down vote up
Http2ClientConnectionHandler(Http2ConnectionDecoder decoder, Http2ConnectionEncoder encoder,
                             Http2Settings initialSettings, Channel channel,
                             HttpClientFactory clientFactory, SessionProtocol protocol) {

    super(decoder, encoder, initialSettings);
    this.clientFactory = clientFactory;

    if (clientFactory.idleTimeoutMillis() > 0 || clientFactory.pingIntervalMillis() > 0) {
        final Timer keepAliveTimer =
                MoreMeters.newTimer(clientFactory.meterRegistry(), "armeria.client.connections.lifespan",
                                    ImmutableList.of(Tag.of("protocol", protocol.uriText())));
        keepAliveHandler = new Http2ClientKeepAliveHandler(
                channel, encoder.frameWriter(), keepAliveTimer,
                clientFactory.idleTimeoutMillis(), clientFactory.pingIntervalMillis());
    } else {
        keepAliveHandler = null;
    }

    responseDecoder = new Http2ResponseDecoder(channel, encoder(), clientFactory, keepAliveHandler);
    connection().addListener(responseDecoder);
    decoder().frameListener(responseDecoder);

    // Setup post build options
    final long timeout = clientFactory.idleTimeoutMillis();
    if (timeout > 0) {
        gracefulShutdownTimeoutMillis(timeout);
    } else {
        // Timeout disabled
        gracefulShutdownTimeoutMillis(-1);
    }
}
 
Example #11
Source File: Http2HandlerBuilder.java    From xrpc with Apache License 2.0 5 votes vote down vote up
@Override
protected Http2ConnectionHandler build(
    Http2ConnectionDecoder decoder,
    Http2ConnectionEncoder encoder,
    Http2Settings initialSettings) {

  // TODO(jkinkead): Set MAX_CONCURRENT_STREAMS value to something from config.
  decoder.frameListener(new Http2Handler(encoder, maxPayloadBytes, corsHandler));

  return new ConnectionHandler(decoder, encoder, initialSettings);
}
 
Example #12
Source File: AbstractNettyHandler.java    From grpc-nebula-java with Apache License 2.0 5 votes vote down vote up
AbstractNettyHandler(
    ChannelPromise channelUnused,
    Http2ConnectionDecoder decoder,
    Http2ConnectionEncoder encoder,
    Http2Settings initialSettings) {
  super(channelUnused, decoder, encoder, initialSettings);

  // During a graceful shutdown, wait until all streams are closed.
  gracefulShutdownTimeoutMillis(GRACEFUL_SHUTDOWN_NO_TIMEOUT);

  // Extract the connection window from the settings if it was set.
  this.initialConnectionWindow = initialSettings.initialWindowSize() == null ? -1 :
          initialSettings.initialWindowSize();
}
 
Example #13
Source File: Http2HandlerBuilder.java    From product-microgateway with Apache License 2.0 5 votes vote down vote up
@Override
protected Http2Handler build(Http2ConnectionDecoder decoder, Http2ConnectionEncoder encoder,
                             Http2Settings initialSettings) {
    Http2Handler handler = new Http2Handler(decoder, encoder, initialSettings);
    frameListener(handler);
    return handler;
}
 
Example #14
Source File: HelloWorldHttp2HandlerBuilder.java    From netty-4.1.22 with Apache License 2.0 5 votes vote down vote up
@Override
protected HelloWorldHttp2Handler build(Http2ConnectionDecoder decoder, Http2ConnectionEncoder encoder,
                                       Http2Settings initialSettings) {
    HelloWorldHttp2Handler handler = new HelloWorldHttp2Handler(decoder, encoder, initialSettings);
    frameListener(handler);
    return handler;
}
 
Example #15
Source File: HelloWorldHttp2HandlerBuilder.java    From netty-4.1.22 with Apache License 2.0 5 votes vote down vote up
@Override
protected HelloWorldHttp2Handler build(Http2ConnectionDecoder decoder, Http2ConnectionEncoder encoder,
                                       Http2Settings initialSettings) {
    HelloWorldHttp2Handler handler = new HelloWorldHttp2Handler(decoder, encoder, initialSettings);
    frameListener(handler);
    return handler;
}
 
Example #16
Source File: Http2ChannelHandlerBuilder.java    From sofa-rpc with Apache License 2.0 5 votes vote down vote up
@Override
protected Http2ServerChannelHandler build(Http2ConnectionDecoder decoder, Http2ConnectionEncoder encoder,
                                          Http2Settings initialSettings) {
    Http2ServerChannelHandler handler = new Http2ServerChannelHandler(serverHandler, decoder, encoder,
        initialSettings);
    frameListener(handler);
    return handler;
}
 
Example #17
Source File: Http2ServerHandler.java    From xio with Apache License 2.0 4 votes vote down vote up
public Http2ServerHandler(
    Http2ConnectionDecoder decoder,
    Http2ConnectionEncoder encoder,
    Http2Settings initialSettings) {
  super(decoder, encoder, initialSettings);
}
 
Example #18
Source File: AltsProtocolNegotiatorTest.java    From grpc-java with Apache License 2.0 4 votes vote down vote up
private CapturingGrpcHttp2ConnectionHandler(
    Http2ConnectionDecoder decoder,
    Http2ConnectionEncoder encoder,
    Http2Settings initialSettings) {
  super(null, decoder, encoder, initialSettings);
}
 
Example #19
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 #20
Source File: AltsProtocolNegotiatorTest.java    From grpc-nebula-java with Apache License 2.0 4 votes vote down vote up
private CapturingGrpcHttp2ConnectionHandler(
    Http2ConnectionDecoder decoder,
    Http2ConnectionEncoder encoder,
    Http2Settings initialSettings) {
  super(null, decoder, encoder, initialSettings);
}
 
Example #21
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 #22
Source File: HelloWorldHttp2Handler.java    From netty-4.1.22 with Apache License 2.0 4 votes vote down vote up
HelloWorldHttp2Handler(Http2ConnectionDecoder decoder, Http2ConnectionEncoder encoder,
                       Http2Settings initialSettings) {
    super(decoder, encoder, initialSettings);
}
 
Example #23
Source File: Http2ServerHandler.java    From glowroot with Apache License 2.0 4 votes vote down vote up
Http2ServerHandler(Http2ConnectionDecoder decoder, Http2ConnectionEncoder encoder,
        Http2Settings initialSettings) {
    super(decoder, encoder, initialSettings);
}
 
Example #24
Source File: AbstractHttp2ConnectionHandler.java    From armeria with Apache License 2.0 4 votes vote down vote up
/**
 * Creates a new instance.
 */
protected AbstractHttp2ConnectionHandler(
        Http2ConnectionDecoder decoder, Http2ConnectionEncoder encoder, Http2Settings initialSettings) {
    super(decoder, encoder, initialSettings);
}
 
Example #25
Source File: AbstractHttp2ConnectionHandlerBuilder.java    From armeria with Apache License 2.0 4 votes vote down vote up
@Override
public B codec(Http2ConnectionDecoder decoder, Http2ConnectionEncoder encoder) {
    return super.codec(decoder, encoder);
}
 
Example #26
Source File: HelloWorldHttp2Handler.java    From netty-4.1.22 with Apache License 2.0 4 votes vote down vote up
HelloWorldHttp2Handler(Http2ConnectionDecoder decoder, Http2ConnectionEncoder encoder,
                       Http2Settings initialSettings) {
    super(decoder, encoder, initialSettings);
}
 
Example #27
Source File: Http2Handler.java    From product-microgateway with Apache License 2.0 4 votes vote down vote up
Http2Handler(Http2ConnectionDecoder decoder, Http2ConnectionEncoder encoder,
             Http2Settings initialSettings) {
    super(decoder, encoder, initialSettings);
}
 
Example #28
Source File: Http2HandlerBuilder.java    From xrpc with Apache License 2.0 4 votes vote down vote up
ConnectionHandler(
    Http2ConnectionDecoder decoder,
    Http2ConnectionEncoder encoder,
    Http2Settings initialSettings) {
  super(decoder, encoder, initialSettings);
}
 
Example #29
Source File: Http2ServerChannelHandler.java    From sofa-rpc with Apache License 2.0 4 votes vote down vote up
Http2ServerChannelHandler(HttpServerHandler serverHandler, Http2ConnectionDecoder decoder,
                          Http2ConnectionEncoder encoder,
                          Http2Settings initialSettings) {
    super(decoder, encoder, initialSettings);
    this.serverHandler = serverHandler;
}