Java 类io.netty.handler.codec.http2.Http2Connection 实例源码

项目:nitmproxy    文件:Http2FrontendHandler.java   
@Override
public void handlerAdded(ChannelHandlerContext ctx) throws Exception {
    LOGGER.info("{} : handlerAdded", connectionInfo);

    Http2Connection connection = new DefaultHttp2Connection(true);
    ChannelHandler http2ConnHandler = new HttpToHttp2ConnectionHandlerBuilder()
            .frameListener(new DelegatingDecompressorFrameListener(
                    connection,
                    new InboundHttp2ToHttpAdapterBuilder(connection)
                            .maxContentLength(master.config().getMaxContentLength())
                            .propagateSettings(true)
                            .build()))
            .connection(connection)
            .frameLogger(new Http2FrameLogger(LogLevel.DEBUG))
            .build();
    ctx.pipeline()
       .addBefore(ctx.name(), null, http2ConnHandler)
       .addBefore(ctx.name(), null, new Http2Handler());
}
项目:nitmproxy    文件:Http2BackendHandler.java   
@Override
public void handlerAdded(ChannelHandlerContext ctx) throws Exception {
    LOGGER.info("{} : handlerAdded", connectionInfo);

    Http2Connection connection = new DefaultHttp2Connection(false);
    ChannelHandler http2ConnHandler = new HttpToHttp2ConnectionHandlerBuilder()
            .frameListener(new DelegatingDecompressorFrameListener(
                    connection,
                    new InboundHttp2ToHttpAdapterBuilder(connection)
                            .maxContentLength(master.config().getMaxContentLength())
                            .propagateSettings(true)
                            .build()))
            .frameLogger(new Http2FrameLogger(LogLevel.DEBUG))
            .connection(connection)
            .build();
    ctx.pipeline()
       .addBefore(ctx.name(), null, http2ConnHandler)
       .addBefore(ctx.name(), null, new Http2Handler());
}
项目:JavaAyo    文件:Http2ClientInitializer.java   
@Override
public void initChannel(SocketChannel ch) throws Exception {
    final Http2Connection connection = new DefaultHttp2Connection(false);
    connectionHandler = new HttpToHttp2ConnectionHandlerBuilder()
            .frameListener(new DelegatingDecompressorFrameListener(
                    connection,
                    new InboundHttp2ToHttpAdapterBuilder(connection)
                            .maxContentLength(maxContentLength)
                            .propagateSettings(true)
                            .build()))
            .frameLogger(logger)
            .connection(connection)
            .build();
    responseHandler = new HttpResponseHandler();
    settingsHandler = new Http2SettingsHandler(ch.newPromise());
    if (sslCtx != null) {
        configureSsl(ch);
    } else {
        configureClearText(ch);
    }
}
项目:netty-cookbook    文件:Http2ClientInitializer.java   
@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);
}
项目:jmeter-http2-plugin    文件:Http2ClientInitializer.java   
@Override
public void initChannel(SocketChannel ch) throws Exception {
    final Http2Connection connection = new DefaultHttp2Connection(false);

    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());
    if (sslCtx != null) {
        configureSsl(ch);
    } else {
        configureClearText(ch);
    }
}
项目:armeria    文件:HttpClientPipelineConfigurator.java   
private Http2ClientConnectionHandler newHttp2ConnectionHandler(Channel ch) {
    final boolean validateHeaders = false;
    final Http2Connection conn = new DefaultHttp2Connection(false);
    conn.addListener(new Http2GoAwayListener(ch));

    Http2FrameReader reader = new DefaultHttp2FrameReader(validateHeaders);
    Http2FrameWriter writer = new DefaultHttp2FrameWriter();

    Http2ConnectionEncoder encoder = new DefaultHttp2ConnectionEncoder(conn, writer);
    Http2ConnectionDecoder decoder = new DefaultHttp2ConnectionDecoder(conn, encoder, reader);

    final Http2Settings http2Settings = http2Settings();

    final Http2ResponseDecoder listener = new Http2ResponseDecoder(conn, ch, encoder);
    final Http2ClientConnectionHandler handler =
            new Http2ClientConnectionHandler(decoder, encoder, http2Settings, listener);
    // Setup post build options
    handler.gracefulShutdownTimeoutMillis(clientFactory.idleTimeoutMillis());

    return handler;
}
项目:armeria    文件:HttpServerPipelineConfigurator.java   
private Http2ConnectionHandler newHttp2ConnectionHandler(ChannelPipeline pipeline) {

        final Http2Connection conn = new DefaultHttp2Connection(true);
        conn.addListener(new Http2GoAwayListener(pipeline.channel()));

        Http2FrameReader reader = new DefaultHttp2FrameReader(true);
        Http2FrameWriter writer = new DefaultHttp2FrameWriter();

        Http2ConnectionEncoder encoder = new DefaultHttp2ConnectionEncoder(conn, writer);
        Http2ConnectionDecoder decoder = new DefaultHttp2ConnectionDecoder(conn, encoder, reader);

        final Http2ConnectionHandler handler =
                new Http2ServerConnectionHandler(decoder, encoder, new Http2Settings());

        // Setup post build options
        final Http2RequestDecoder listener =
                new Http2RequestDecoder(config, pipeline.channel(), handler.encoder());

        handler.connection().addListener(listener);
        handler.decoder().frameListener(listener);
        handler.gracefulShutdownTimeoutMillis(config.idleTimeoutMillis());

        return handler;
    }
项目:carbon-transports    文件:HTTP2ClientInitializer.java   
@Override
public void initChannel(SocketChannel ch) throws Exception {
    final Http2Connection connection = new DefaultHttp2Connection(false);
    connectionHandler = new HttpToHttp2ConnectionHandlerBuilder()
            .frameListener(new DelegatingDecompressorFrameListener(
                    connection,
                    new InboundHttp2ToHttpAdapterBuilder(connection)
                            .maxContentLength(maxContentLength)
                            .propagateSettings(true)
                            .build()))
            .frameLogger(logger)
            .connection(connection)
            .build();
    responseHandler = new HTTP2ResponseHandler();
    settingsHandler = new HTTP2SettingsHandler(ch.newPromise());
    if (sslCtx != null) {
        configureSsl(ch);
    } else {
        configureClearText(ch);
    }
}
项目:jooby    文件:NettyPush.java   
@Override
public void push(final String method, final String path, final Map<String, Object> headers) {
  ctx.channel().eventLoop().execute(() -> {
    AsciiString streamIdHeader = HttpConversionUtil.ExtensionHeaderNames.STREAM_ID.text();
    Http2Connection connection = encoder.connection();
    int nextStreamId = connection.local().incrementAndGetNextStreamId();
    Http2Headers h2headers = new DefaultHttp2Headers()
        .path(path)
        .method(method)
        .authority(authority)
        .scheme(scheme);
    headers.forEach((n, v) -> h2headers.add(n, v.toString()));
    encoder.writePushPromise(ctx, streamId, nextStreamId, h2headers, 0, ctx.newPromise());

    // TODO: Is there another way of handling a push promise?
    DefaultFullHttpRequest pushRequest = new DefaultFullHttpRequest(HttpVersion.HTTP_1_1,
        HttpMethod.valueOf(method.toUpperCase()), path, Unpooled.EMPTY_BUFFER,
        new DefaultHttpHeaders(false).set(streamIdHeader, nextStreamId),
        EmptyHttpHeaders.INSTANCE);
    ctx.pipeline().fireChannelRead(pushRequest);
    ctx.pipeline().fireChannelReadComplete();
  });
}
项目:aliyun-oss-hadoop-fs    文件:TestDtpHttp2.java   
@BeforeClass
public static void setUp() throws IOException, URISyntaxException,
    TimeoutException {
  CLUSTER = new MiniDFSCluster.Builder(CONF).numDataNodes(1).build();
  CLUSTER.waitActive();

  RESPONSE_HANDLER = new Http2ResponseHandler();
  Bootstrap bootstrap =
      new Bootstrap()
          .group(WORKER_GROUP)
          .channel(NioSocketChannel.class)
          .remoteAddress("127.0.0.1",
            CLUSTER.getDataNodes().get(0).getInfoPort())
          .handler(new ChannelInitializer<Channel>() {

            @Override
            protected void initChannel(Channel ch) throws Exception {
              Http2Connection connection = new DefaultHttp2Connection(false);
              Http2ConnectionHandler connectionHandler =
                  new HttpToHttp2ConnectionHandler(connection, frameReader(),
                      frameWriter(), new DelegatingDecompressorFrameListener(
                          connection, new InboundHttp2ToHttpAdapter.Builder(
                              connection).maxContentLength(Integer.MAX_VALUE)
                              .propagateSettings(true).build()));
              ch.pipeline().addLast(connectionHandler, RESPONSE_HANDLER);
            }
          });
  CHANNEL = bootstrap.connect().syncUninterruptibly().channel();

}
项目:armeria    文件:THttp2Client.java   
@Override
public void initChannel(SocketChannel ch) throws Exception {
    final ChannelPipeline p = ch.pipeline();
    final Http2Connection conn = new DefaultHttp2Connection(false);
    final HttpToHttp2ConnectionHandler connHandler = new HttpToHttp2ConnectionHandlerBuilder()
            .connection(conn)
            .frameListener(new DelegatingDecompressorFrameListener(
                    conn,
                    new InboundHttp2ToHttpAdapterBuilder(conn)
                            .maxContentLength(Integer.MAX_VALUE)
                            .propagateSettings(true).build()))
            .build();

    clientHandler = new THttp2ClientHandler(ch.eventLoop());

    if (sslCtx != null) {
        p.addLast(sslCtx.newHandler(p.channel().alloc()));
        p.addLast(connHandler);
        configureEndOfPipeline(p);
    } else {
        Http1ClientCodec sourceCodec = new Http1ClientCodec();
        HttpClientUpgradeHandler upgradeHandler = new HttpClientUpgradeHandler(
                sourceCodec, new Http2ClientUpgradeCodec(connHandler), 65536);

        p.addLast(sourceCodec, upgradeHandler, new UpgradeRequestHandler());
    }
}
项目:armeria    文件:HttpClientPipelineConfigurator.java   
private static void incrementLocalWindowSize(ChannelPipeline pipeline, int delta) {
    try {
        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);
    }
}
项目:grpc-java    文件:NettyClientHandler.java   
static NettyClientHandler newHandler(
    ClientTransportLifecycleManager lifecycleManager,
    @Nullable KeepAliveManager keepAliveManager,
    int flowControlWindow,
    int maxHeaderListSize,
    Supplier<Stopwatch> stopwatchFactory,
    Runnable tooManyPingsRunnable,
    TransportTracer transportTracer) {
  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);
}
项目:grpc-java    文件:NettyClientHandlerTest.java   
@Override
protected NettyClientHandler newHandler() throws Http2Exception {
  Http2Connection connection = new DefaultHttp2Connection(false);

  // Create and close a stream previous to the nextStreamId.
  Http2Stream stream = connection.local().createStream(streamId - 2, true);
  stream.close();

  final Ticker ticker = new Ticker() {
    @Override
    public long read() {
      return nanoTime;
    }
  };
  Supplier<Stopwatch> stopwatchSupplier = new Supplier<Stopwatch>() {
    @Override
    public Stopwatch get() {
      return Stopwatch.createUnstarted(ticker);
    }
  };
  return NettyClientHandler.newHandler(
      connection,
      frameReader(),
      frameWriter(),
      lifecycleManager,
      mockKeepAliveManager,
      flowControlWindow,
      maxHeaderListSize,
      stopwatchSupplier,
      tooManyPingsRunnable,
      transportTracer);
}
项目:netty-cookbook    文件:HelloWorldHttp2Handler.java   
private HelloWorldHttp2Handler(Http2Connection connection, Http2FrameReader frameReader,
        Http2FrameWriter frameWriter, SimpleHttp2FrameListener listener) {
    super(connection, frameReader, frameWriter, listener);
    listener.encoder(encoder());
}
项目:armeria    文件:Http2ResponseDecoder.java   
Http2ResponseDecoder(Http2Connection conn, Channel channel, Http2ConnectionEncoder encoder) {
    super(channel);
    this.conn = conn;
    this.encoder = encoder;
}
项目:grpc-java    文件:NettyServerHandler.java   
@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);
}
项目:grpc-java    文件:NettyHandlerTestBase.java   
protected final Http2Connection connection() {
  return handler().connection();
}