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

The following examples show how to use io.netty.handler.codec.http2.Http2FrameWriter. 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: Http2ClientInitializer.java    From netty-cookbook with Apache License 2.0 6 votes vote down vote up
@Override
public void initChannel(SocketChannel ch) throws Exception {
    final Http2Connection connection = new DefaultHttp2Connection(false);
    final Http2FrameWriter frameWriter = frameWriter();
    connectionHandler = new HttpToHttp2ConnectionHandler(connection,
            frameReader(),
            frameWriter,
            new DelegatingDecompressorFrameListener(connection,
                    new InboundHttp2ToHttpAdapter.Builder(connection)
                            .maxContentLength(maxContentLength)
                            .propagateSettings(true)
                            .build()));
    responseHandler = new HttpResponseHandler();
    settingsHandler = new Http2SettingsHandler(ch.newPromise());
    configureClearText(ch);
}
 
Example #2
Source File: Http2KeepAliveHandler.java    From armeria with Apache License 2.0 5 votes vote down vote up
protected Http2KeepAliveHandler(Channel channel, Http2FrameWriter frameWriter, String name,
                                Timer keepAliveTimer, long idleTimeoutMillis, long pingIntervalMillis,
                                long maxConnectionAgeMillis) {
    super(channel, name, keepAliveTimer, idleTimeoutMillis, pingIntervalMillis, maxConnectionAgeMillis);
    this.channel = requireNonNull(channel, "channel");
    this.frameWriter = requireNonNull(frameWriter, "frameWriter");
}
 
Example #3
Source File: AltsProtocolNegotiatorTest.java    From grpc-java with Apache License 2.0 5 votes vote down vote up
private CapturingGrpcHttp2ConnectionHandler capturingGrpcHandler() {
  // Netty Boilerplate.  We don't really need any of this, but there is a tight coupling
  // between an Http2ConnectionHandler and its dependencies.
  Http2Connection connection = new DefaultHttp2Connection(true);
  Http2FrameWriter frameWriter = new DefaultHttp2FrameWriter();
  Http2FrameReader frameReader = new DefaultHttp2FrameReader(false);
  DefaultHttp2ConnectionEncoder encoder =
      new DefaultHttp2ConnectionEncoder(connection, frameWriter);
  DefaultHttp2ConnectionDecoder decoder =
      new DefaultHttp2ConnectionDecoder(connection, encoder, frameReader);

  return new CapturingGrpcHttp2ConnectionHandler(decoder, encoder, new Http2Settings());
}
 
Example #4
Source File: NettyHandlerTestBase.java    From grpc-java with Apache License 2.0 5 votes vote down vote up
/**
 * Must be called by subclasses to initialize the handler and channel.
 */
protected final void initChannel(Http2HeadersDecoder headersDecoder) throws Exception {
  content = Unpooled.copiedBuffer("hello world", UTF_8);
  frameWriter = mock(Http2FrameWriter.class, delegatesTo(new DefaultHttp2FrameWriter()));
  frameReader = new DefaultHttp2FrameReader(headersDecoder);

  channel = new FakeClockSupportedChanel();
  handler = newHandler();
  channel.pipeline().addLast(handler);
  ctx = channel.pipeline().context(handler);

  writeQueue = initWriteQueue();
}
 
Example #5
Source File: NettyClientHandler.java    From grpc-java with Apache License 2.0 5 votes vote down vote up
static NettyClientHandler newHandler(
    ClientTransportLifecycleManager lifecycleManager,
    @Nullable KeepAliveManager keepAliveManager,
    boolean autoFlowControl,
    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,
      autoFlowControl,
      flowControlWindow,
      maxHeaderListSize,
      stopwatchFactory,
      tooManyPingsRunnable,
      transportTracer,
      eagAttributes,
      authority);
}
 
Example #6
Source File: Http2ClientKeepAliveHandler.java    From armeria with Apache License 2.0 5 votes vote down vote up
Http2ClientKeepAliveHandler(Channel channel, Http2FrameWriter frameWriter, Timer keepAliveTimer,
                            long idleTimeoutMillis, long pingIntervalMillis) {

    // TODO(ikhoon): Should set maxConnectionAgeMillis by https://github.com/line/armeria/pull/2741
    super(channel, frameWriter, "client", keepAliveTimer,
          idleTimeoutMillis, pingIntervalMillis, /* maxConnectionAgeMillis */ 0);
}
 
Example #7
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 #8
Source File: AltsProtocolNegotiatorTest.java    From grpc-nebula-java with Apache License 2.0 5 votes vote down vote up
private CapturingGrpcHttp2ConnectionHandler capturingGrpcHandler() {
  // Netty Boilerplate.  We don't really need any of this, but there is a tight coupling
  // between a Http2ConnectionHandler and its dependencies.
  Http2Connection connection = new DefaultHttp2Connection(true);
  Http2FrameWriter frameWriter = new DefaultHttp2FrameWriter();
  Http2FrameReader frameReader = new DefaultHttp2FrameReader(false);
  DefaultHttp2ConnectionEncoder encoder =
      new DefaultHttp2ConnectionEncoder(connection, frameWriter);
  DefaultHttp2ConnectionDecoder decoder =
      new DefaultHttp2ConnectionDecoder(connection, encoder, frameReader);

  return new CapturingGrpcHttp2ConnectionHandler(decoder, encoder, new Http2Settings());
}
 
Example #9
Source File: NettyHandlerTestBase.java    From grpc-nebula-java with Apache License 2.0 5 votes vote down vote up
/**
 * Must be called by subclasses to initialize the handler and channel.
 */
protected final void initChannel(Http2HeadersDecoder headersDecoder) throws Exception {
  content = Unpooled.copiedBuffer("hello world", UTF_8);
  frameWriter = mock(Http2FrameWriter.class, delegatesTo(new DefaultHttp2FrameWriter()));
  frameReader = new DefaultHttp2FrameReader(headersDecoder);

  channel = new FakeClockSupportedChanel();
  handler = newHandler();
  channel.pipeline().addLast(handler);
  ctx = channel.pipeline().context(handler);

  writeQueue = initWriteQueue();
}
 
Example #10
Source File: NettyClientHandler.java    From grpc-nebula-java with Apache License 2.0 5 votes vote down vote up
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);
}
 
Example #11
Source File: NettyServerHandler.java    From grpc-java with Apache License 2.0 4 votes vote down vote up
static NettyServerHandler newHandler(
    ServerTransportListener transportListener,
    ChannelPromise channelUnused,
    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(maxHeaderListSize > 0, "maxHeaderListSize must be positive: %s",
      maxHeaderListSize);
  Http2FrameLogger frameLogger = new Http2FrameLogger(LogLevel.DEBUG, NettyServerHandler.class);
  Http2HeadersDecoder headersDecoder = new GrpcHttp2ServerHeadersDecoder(maxHeaderListSize);
  Http2FrameReader frameReader = new Http2InboundFrameLogger(
      new DefaultHttp2FrameReader(headersDecoder), frameLogger);
  Http2FrameWriter frameWriter =
      new Http2OutboundFrameLogger(new DefaultHttp2FrameWriter(), frameLogger);
  return newHandler(
      channelUnused,
      frameReader,
      frameWriter,
      transportListener,
      streamTracerFactories,
      transportTracer,
      maxStreams,
      autoFlowControl,
      flowControlWindow,
      maxHeaderListSize,
      maxMessageSize,
      keepAliveTimeInNanos,
      keepAliveTimeoutInNanos,
      maxConnectionIdleInNanos,
      maxConnectionAgeInNanos,
      maxConnectionAgeGraceInNanos,
      permitKeepAliveWithoutCalls,
      permitKeepAliveTimeInNanos);
}
 
Example #12
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 #13
Source File: NettyHandlerTestBase.java    From grpc-java with Apache License 2.0 4 votes vote down vote up
protected final Http2FrameWriter verifyWrite(VerificationMode verificationMode) {
  return verify(frameWriter, verificationMode);
}
 
Example #14
Source File: NettyHandlerTestBase.java    From grpc-java with Apache License 2.0 4 votes vote down vote up
protected final Http2FrameWriter verifyWrite() {
  return verify(frameWriter);
}
 
Example #15
Source File: NettyHandlerTestBase.java    From grpc-java with Apache License 2.0 4 votes vote down vote up
protected final Http2FrameWriter frameWriter() {
  return frameWriter;
}
 
Example #16
Source File: NettyServerHandler.java    From grpc-nebula-java with Apache License 2.0 4 votes vote down vote up
public WriteMonitoringFrameWriter(Http2FrameWriter delegate,
    KeepAliveEnforcer keepAliveEnforcer) {
  super(delegate);
  this.keepAliveEnforcer = keepAliveEnforcer;
}
 
Example #17
Source File: ListeningEncoder.java    From grpc-java with Apache License 2.0 4 votes vote down vote up
public ListeningDefaultHttp2ConnectionEncoder(
    Http2Connection connection, Http2FrameWriter frameWriter) {
  super(connection, frameWriter);
}
 
Example #18
Source File: NettyServerHandler.java    From grpc-java with Apache License 2.0 4 votes vote down vote up
public WriteMonitoringFrameWriter(Http2FrameWriter delegate,
    KeepAliveEnforcer keepAliveEnforcer) {
  super(delegate);
  this.keepAliveEnforcer = keepAliveEnforcer;
}
 
Example #19
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 #20
Source File: NettyHandlerTestBase.java    From grpc-nebula-java with Apache License 2.0 4 votes vote down vote up
protected final Http2FrameWriter verifyWrite(VerificationMode verificationMode) {
  return verify(frameWriter, verificationMode);
}
 
Example #21
Source File: HelloWorldHttp2Handler.java    From netty-cookbook with Apache License 2.0 4 votes vote down vote up
private HelloWorldHttp2Handler(Http2Connection connection, Http2FrameReader frameReader,
        Http2FrameWriter frameWriter, SimpleHttp2FrameListener listener) {
    super(connection, frameReader, frameWriter, listener);
    listener.encoder(encoder());
}
 
Example #22
Source File: Http2ClientInitializer.java    From netty-cookbook with Apache License 2.0 4 votes vote down vote up
private static Http2FrameWriter frameWriter() {
    return new Http2OutboundFrameLogger(new DefaultHttp2FrameWriter(), logger);
}
 
Example #23
Source File: NettyServerHandler.java    From grpc-nebula-java with Apache License 2.0 4 votes vote down vote up
static NettyServerHandler newHandler(
    ServerTransportListener transportListener,
    ChannelPromise channelUnused,
    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(maxHeaderListSize > 0, "maxHeaderListSize must be positive");
  Http2FrameLogger frameLogger = new Http2FrameLogger(LogLevel.DEBUG, NettyServerHandler.class);
  Http2HeadersDecoder headersDecoder = new GrpcHttp2ServerHeadersDecoder(maxHeaderListSize);
  Http2FrameReader frameReader = new Http2InboundFrameLogger(
      new DefaultHttp2FrameReader(headersDecoder), frameLogger);
  Http2FrameWriter frameWriter =
      new Http2OutboundFrameLogger(new DefaultHttp2FrameWriter(), frameLogger);
  return newHandler(
      channelUnused,
      frameReader,
      frameWriter,
      transportListener,
      streamTracerFactories,
      transportTracer,
      maxStreams,
      flowControlWindow,
      maxHeaderListSize,
      maxMessageSize,
      keepAliveTimeInNanos,
      keepAliveTimeoutInNanos,
      maxConnectionIdleInNanos,
      maxConnectionAgeInNanos,
      maxConnectionAgeGraceInNanos,
      permitKeepAliveWithoutCalls,
      permitKeepAliveTimeInNanos);
}
 
Example #24
Source File: Http2ServerKeepAliveHandler.java    From armeria with Apache License 2.0 4 votes vote down vote up
Http2ServerKeepAliveHandler(Channel channel, Http2FrameWriter frameWriter, Timer keepAliveTimer,
                            long idleTimeoutMillis, long pingIntervalMillis, long maxConnectionAgeMillis) {
    super(channel, frameWriter, "server", keepAliveTimer,
          idleTimeoutMillis, pingIntervalMillis, maxConnectionAgeMillis);
}
 
Example #25
Source File: NettyHandlerTestBase.java    From grpc-nebula-java with Apache License 2.0 4 votes vote down vote up
protected final Http2FrameWriter frameWriter() {
  return frameWriter;
}
 
Example #26
Source File: NettyHandlerTestBase.java    From grpc-nebula-java with Apache License 2.0 4 votes vote down vote up
protected final Http2FrameWriter verifyWrite() {
  return verify(frameWriter);
}
 
Example #27
Source File: GoAwayTest.java    From aws-sdk-java-v2 with Apache License 2.0 4 votes vote down vote up
protected final Http2FrameWriter frameWriter() {
    return frameWriter;
}