@Test public void createStreamShouldSucceed() throws Exception { createStream(); verifyWrite().writeHeaders(eq(ctx()), eq(3), eq(grpcHeaders), eq(0), eq(DEFAULT_PRIORITY_WEIGHT), eq(false), eq(0), eq(false), any(ChannelPromise.class)); }
private void createStream(final CreateStreamCommand command, final ChannelPromise promise) throws Exception { if (lifecycleManager.getShutdownThrowable() != null) { command.stream().transportReportStatus( lifecycleManager.getShutdownStatus(), RpcProgress.REFUSED, true, new Metadata()); promise.setFailure(lifecycleManager.getShutdownThrowable()); return; } final int streamId; try { streamId = incrementAndGetNextStreamId(); } catch (StatusException e) { promise.setFailure(e); if (!connection().goAwaySent()) { logger.fine("Stream IDs have been exhausted for this connection. " + "Initiating graceful shutdown of the connection."); lifecycleManager.notifyShutdown(e.getStatus()); close(ctx(), ctx().newPromise()); } return; } final NettyClientStream.TransportState stream = command.stream(); final Http2Headers headers = command.headers(); stream.setId(streamId); ChannelPromise tempPromise = ctx().newPromise(); encoder().writeHeaders(ctx(), streamId, headers, 0, command.isGet(), tempPromise) .addListener(new ChannelFutureListener() { @Override public void operationComplete(ChannelFuture future) throws Exception { if (future.isSuccess()) { Http2Stream http2Stream = connection().stream(streamId); if (http2Stream != null) { stream.getStatsTraceContext().clientOutboundHeaders(); http2Stream.setProperty(streamKey, stream); if (command.shouldBeCountedForInUse()) { inUseState.updateObjectInUse(http2Stream, true); } stream.setHttp2Stream(http2Stream); } promise.setSuccess(); } else { final Throwable cause = future.cause(); if (cause instanceof StreamBufferingEncoder.Http2GoAwayException) { StreamBufferingEncoder.Http2GoAwayException e = (StreamBufferingEncoder.Http2GoAwayException) cause; lifecycleManager.notifyShutdown(statusFromGoAway(e.errorCode(), e.debugData())); promise.setFailure(lifecycleManager.getShutdownThrowable()); } else { promise.setFailure(cause); } } } }); }
NettyClientHandler extends AbstractNettyHandler { private void createStream(final CreateStreamCommand command, final ChannelPromise promise) throws Exception { if (lifecycleManager.getShutdownThrowable() != null) { command.stream().transportReportStatus( lifecycleManager.getShutdownStatus(), RpcProgress.REFUSED, true, new Metadata()); promise.setFailure(lifecycleManager.getShutdownThrowable()); return; } final int streamId; try { streamId = incrementAndGetNextStreamId(); } catch (StatusException e) { promise.setFailure(e); if (!connection().goAwaySent()) { logger.fine("Stream IDs have been exhausted for this connection. " + "Initiating graceful shutdown of the connection."); lifecycleManager.notifyShutdown(e.getStatus()); close(ctx(), ctx().newPromise()); } return; } final NettyClientStream.TransportState stream = command.stream(); final Http2Headers headers = command.headers(); stream.setId(streamId); ChannelPromise tempPromise = ctx().newPromise(); encoder().writeHeaders(ctx(), streamId, headers, 0, command.isGet(), tempPromise) .addListener(new ChannelFutureListener() { @Override public void operationComplete(ChannelFuture future) throws Exception { if (future.isSuccess()) { Http2Stream http2Stream = connection().stream(streamId); if (http2Stream != null) { stream.getStatsTraceContext().clientOutboundHeaders(); http2Stream.setProperty(streamKey, stream); if (command.shouldBeCountedForInUse()) { inUseState.updateObjectInUse(http2Stream, true); } stream.setHttp2Stream(http2Stream); } promise.setSuccess(); } else { final Throwable cause = future.cause(); if (cause instanceof StreamBufferingEncoder.Http2GoAwayException) { StreamBufferingEncoder.Http2GoAwayException e = (StreamBufferingEncoder.Http2GoAwayException) cause; lifecycleManager.notifyShutdown(statusFromGoAway(e.errorCode(), e.debugData())); promise.setFailure(lifecycleManager.getShutdownThrowable()); } else { promise.setFailure(cause); } } } }); } }
NettyClientHandler extends AbstractNettyHandler { private void createStream(final CreateStreamCommand command, final ChannelPromise promise) throws Exception { if (lifecycleManager.getShutdownThrowable() != null) { command.stream().transportReportStatus( lifecycleManager.getShutdownStatus(), RpcProgress.REFUSED, true, new Metadata()); promise.setFailure(lifecycleManager.getShutdownThrowable()); return; } final int streamId; try { streamId = incrementAndGetNextStreamId(); } catch (StatusException e) { promise.setFailure(e); if (!connection().goAwaySent()) { logger.fine("Stream IDs have been exhausted for this connection. " + "Initiating graceful shutdown of the connection."); lifecycleManager.notifyShutdown(e.getStatus()); close(ctx(), ctx().newPromise()); } return; } final NettyClientStream.TransportState stream = command.stream(); final Http2Headers headers = command.headers(); stream.setId(streamId); ChannelPromise tempPromise = ctx().newPromise(); encoder().writeHeaders(ctx(), streamId, headers, 0, command.isGet(), tempPromise) .addListener(new ChannelFutureListener() { @Override public void operationComplete(ChannelFuture future) throws Exception { if (future.isSuccess()) { Http2Stream http2Stream = connection().stream(streamId); if (http2Stream != null) { stream.getStatsTraceContext().clientOutboundHeaders(); http2Stream.setProperty(streamKey, stream); if (command.shouldBeCountedForInUse()) { inUseState.updateObjectInUse(http2Stream, true); } stream.setHttp2Stream(http2Stream); } promise.setSuccess(); } else { final Throwable cause = future.cause(); if (cause instanceof StreamBufferingEncoder.Http2GoAwayException) { StreamBufferingEncoder.Http2GoAwayException e = (StreamBufferingEncoder.Http2GoAwayException) cause; lifecycleManager.notifyShutdown(statusFromGoAway(e.errorCode(), e.debugData())); promise.setFailure(lifecycleManager.getShutdownThrowable()); } else { promise.setFailure(cause); } } } }); } private  NettyClientHandler(
      Http2ConnectionDecoder decoder,
      StreamBufferingEncoder encoder,
      Http2Settings settings,
      ClientTransportLifecycleManager lifecycleManager,
      KeepAliveManager keepAliveManager,
      Supplier<Stopwatch> stopwatchFactory,
      final Runnable tooManyPingsRunnable,
      TransportTracer transportTracer,
      Attributes eagAttributes,
      String authority); }
NettyClientHandler extends AbstractNettyHandler { private void createStream(final CreateStreamCommand command, final ChannelPromise promise) throws Exception { if (lifecycleManager.getShutdownThrowable() != null) { command.stream().transportReportStatus( lifecycleManager.getShutdownStatus(), RpcProgress.REFUSED, true, new Metadata()); promise.setFailure(lifecycleManager.getShutdownThrowable()); return; } final int streamId; try { streamId = incrementAndGetNextStreamId(); } catch (StatusException e) { promise.setFailure(e); if (!connection().goAwaySent()) { logger.fine("Stream IDs have been exhausted for this connection. " + "Initiating graceful shutdown of the connection."); lifecycleManager.notifyShutdown(e.getStatus()); close(ctx(), ctx().newPromise()); } return; } final NettyClientStream.TransportState stream = command.stream(); final Http2Headers headers = command.headers(); stream.setId(streamId); ChannelPromise tempPromise = ctx().newPromise(); encoder().writeHeaders(ctx(), streamId, headers, 0, command.isGet(), tempPromise) .addListener(new ChannelFutureListener() { @Override public void operationComplete(ChannelFuture future) throws Exception { if (future.isSuccess()) { Http2Stream http2Stream = connection().stream(streamId); if (http2Stream != null) { stream.getStatsTraceContext().clientOutboundHeaders(); http2Stream.setProperty(streamKey, stream); if (command.shouldBeCountedForInUse()) { inUseState.updateObjectInUse(http2Stream, true); } stream.setHttp2Stream(http2Stream); } promise.setSuccess(); } else { final Throwable cause = future.cause(); if (cause instanceof StreamBufferingEncoder.Http2GoAwayException) { StreamBufferingEncoder.Http2GoAwayException e = (StreamBufferingEncoder.Http2GoAwayException) cause; lifecycleManager.notifyShutdown(statusFromGoAway(e.errorCode(), e.debugData())); promise.setFailure(lifecycleManager.getShutdownThrowable()); } else { promise.setFailure(cause); } } } }); } private  NettyClientHandler(
      Http2ConnectionDecoder decoder,
      StreamBufferingEncoder encoder,
      Http2Settings settings,
      ClientTransportLifecycleManager lifecycleManager,
      KeepAliveManager keepAliveManager,
      Supplier<Stopwatch> stopwatchFactory,
      final Runnable tooManyPingsRunnable,
      TransportTracer transportTracer,
      Attributes eagAttributes,
      String authority); @Override void write(ChannelHandlerContext ctx, Object msg, ChannelPromise promise); @Override void close(ChannelHandlerContext ctx, ChannelPromise promise); @Override void channelInactive(ChannelHandlerContext ctx); @Override void handleProtocolNegotiationCompleted(
      Attributes attributes, InternalChannelz.Security securityInfo); @Override Attributes getEagAttributes(); @Override String getAuthority(); }
NettyClientHandler extends AbstractNettyHandler { private void createStream(final CreateStreamCommand command, final ChannelPromise promise) throws Exception { if (lifecycleManager.getShutdownThrowable() != null) { command.stream().transportReportStatus( lifecycleManager.getShutdownStatus(), RpcProgress.REFUSED, true, new Metadata()); promise.setFailure(lifecycleManager.getShutdownThrowable()); return; } final int streamId; try { streamId = incrementAndGetNextStreamId(); } catch (StatusException e) { promise.setFailure(e); if (!connection().goAwaySent()) { logger.fine("Stream IDs have been exhausted for this connection. " + "Initiating graceful shutdown of the connection."); lifecycleManager.notifyShutdown(e.getStatus()); close(ctx(), ctx().newPromise()); } return; } final NettyClientStream.TransportState stream = command.stream(); final Http2Headers headers = command.headers(); stream.setId(streamId); ChannelPromise tempPromise = ctx().newPromise(); encoder().writeHeaders(ctx(), streamId, headers, 0, command.isGet(), tempPromise) .addListener(new ChannelFutureListener() { @Override public void operationComplete(ChannelFuture future) throws Exception { if (future.isSuccess()) { Http2Stream http2Stream = connection().stream(streamId); if (http2Stream != null) { stream.getStatsTraceContext().clientOutboundHeaders(); http2Stream.setProperty(streamKey, stream); if (command.shouldBeCountedForInUse()) { inUseState.updateObjectInUse(http2Stream, true); } stream.setHttp2Stream(http2Stream); } promise.setSuccess(); } else { final Throwable cause = future.cause(); if (cause instanceof StreamBufferingEncoder.Http2GoAwayException) { StreamBufferingEncoder.Http2GoAwayException e = (StreamBufferingEncoder.Http2GoAwayException) cause; lifecycleManager.notifyShutdown(statusFromGoAway(e.errorCode(), e.debugData())); promise.setFailure(lifecycleManager.getShutdownThrowable()); } else { promise.setFailure(cause); } } } }); } private  NettyClientHandler(
      Http2ConnectionDecoder decoder,
      StreamBufferingEncoder encoder,
      Http2Settings settings,
      ClientTransportLifecycleManager lifecycleManager,
      KeepAliveManager keepAliveManager,
      Supplier<Stopwatch> stopwatchFactory,
      final Runnable tooManyPingsRunnable,
      TransportTracer transportTracer,
      Attributes eagAttributes,
      String authority); @Override void write(ChannelHandlerContext ctx, Object msg, ChannelPromise promise); @Override void close(ChannelHandlerContext ctx, ChannelPromise promise); @Override void channelInactive(ChannelHandlerContext ctx); @Override void handleProtocolNegotiationCompleted(
      Attributes attributes, InternalChannelz.Security securityInfo); @Override Attributes getEagAttributes(); @Override String getAuthority();  }