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

The following examples show how to use io.netty.handler.codec.http2.Http2StreamChannelBootstrap. 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: H2ClientParentConnectionContext.java    From servicetalk with Apache License 2.0 5 votes vote down vote up
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());
}
 
Example #2
Source File: MultiplexedChannelRecord.java    From aws-sdk-java-v2 with Apache License 2.0 5 votes vote down vote up
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);
}
 
Example #3
Source File: MultiplexedChannelRecord.java    From ambry with Apache License 2.0 5 votes vote down vote up
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);
}
 
Example #4
Source File: HttpClientConfig.java    From reactor-netty with Apache License 2.0 4 votes vote down vote up
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();
}