类 io.netty.handler.codec.http2.Http2StreamChannelBootstrap 源码实例Demo

下面列出了怎么用 io.netty.handler.codec.http2.Http2StreamChannelBootstrap 的API类实例代码及写法,或者点击链接到github查看源代码。


DefaultH2ClientParentConnection(H2ClientParentConnectionContext connection,
                                Subscriber<? super H2ClientParentConnection> subscriber,
                                DelayedCancellable delayedCancellable,
                                boolean waitForSslHandshake,
                                HttpHeadersFactory headersFactory,
                                StreamingHttpRequestResponseFactory reqRespFactory) {
    super(connection, delayedCancellable, waitForSslHandshake);
    this.subscriber = requireNonNull(subscriber);
    this.headersFactory = requireNonNull(headersFactory);
    this.reqRespFactory = requireNonNull(reqRespFactory);
    maxConcurrencyProcessor = newPublisherProcessor(16);
    // Set maxConcurrency to the initial value recommended by the HTTP/2 spec
    maxConcurrencyProcessor.onNext(DEFAULT_H2_MAX_CONCURRENCY_EVENT);
    bs = new Http2StreamChannelBootstrap(connection.channel());
}
 

void acquireClaimedStream(Promise<Channel> promise) {
    doInEventLoop(connection.eventLoop(), () -> {
        if (state != RecordState.OPEN) {
            String message;
            // GOAWAY
            if (state == RecordState.CLOSED_TO_NEW) {
                message = String.format("Connection %s received GOAWAY with Last Stream ID %d. Unable to open new "
                                        + "streams on this connection.", connection, lastStreamId);
            } else {
                message = String.format("Connection %s was closed while acquiring new stream.", connection);
            }
            log.warn(() -> message);
            promise.setFailure(new IOException(message));
            return;
        }

        Future<Http2StreamChannel> streamFuture = new Http2StreamChannelBootstrap(connection).open();
        streamFuture.addListener((GenericFutureListener<Future<Http2StreamChannel>>) future -> {
            warnIfNotInEventLoop(connection.eventLoop());

            if (!future.isSuccess()) {
                promise.setFailure(future.cause());
                return;
            }

            Http2StreamChannel channel = future.getNow();
            channel.pipeline().addLast(UnusedChannelExceptionHandler.getInstance());
            childChannels.put(channel.id(), channel);
            promise.setSuccess(channel);

            if (closeIfIdleTask == null && allowedIdleConnectionTimeMillis != null) {
                enableCloseIfIdleTask();
            }
        });
    }, promise);
}
 
源代码3 项目: ambry   文件: MultiplexedChannelRecord.java

void acquireClaimedStream(Promise<Channel> promise) {
  NettyUtils.doInEventLoop(parentChannel.eventLoop(), () -> {
    if (state != RecordState.OPEN) {
      String message;
      // GOAWAY
      if (state == RecordState.CLOSED_TO_NEW) {
        message = String.format("Connection %s received GOAWAY with Last Stream ID %d. Unable to open new "
            + "streams on this connection.", parentChannel, lastStreamId);
      } else {
        message = String.format("Connection %s was closed while acquiring new stream.", parentChannel);
      }
      log.warn(message);
      promise.setFailure(new IOException(message));
      return;
    }

    Future<Http2StreamChannel> streamFuture =
        new Http2StreamChannelBootstrap(parentChannel).handler(streamChannelInitializer).open();
    streamFuture.addListener((GenericFutureListener<Future<Http2StreamChannel>>) future -> {
      NettyUtils.warnIfNotInEventLoop(parentChannel.eventLoop());

      if (!future.isSuccess()) {
        promise.setFailure(future.cause());
        return;
      }

      Http2StreamChannel channel = future.getNow();
      streamChannels.put(channel.id(), channel);
      promise.setSuccess(channel);

      if (closeIfIdleTask == null && allowedIdleTimeInMs != null && allowedIdleTimeInMs > 0) {
        enableCloseIfIdleTask();
      }
    });
  }, promise);
}
 
源代码4 项目: reactor-netty   文件: HttpClientConfig.java

static Future<Http2StreamChannel> openStream(Channel channel, ConnectionObserver observer, ChannelOperations.OnSetup opsFactory) {
	Http2StreamChannelBootstrap bootstrap = new Http2StreamChannelBootstrap(channel);
	bootstrap.option(ChannelOption.AUTO_READ, false);
	bootstrap.handler(new H2Codec(observer, opsFactory));
	return bootstrap.open();
}
 
 类方法
 同包方法