io.netty.handler.codec.http2.Http2StreamVisitor Java Examples
The following examples show how to use
io.netty.handler.codec.http2.Http2StreamVisitor.
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: NettyServerHandler.java From grpc-nebula-java with Apache License 2.0 | 6 votes |
private void forcefulClose(final ChannelHandlerContext ctx, final ForcefulCloseCommand msg, ChannelPromise promise) throws Exception { close(ctx, promise); connection().forEachActiveStream(new Http2StreamVisitor() { @Override public boolean visit(Http2Stream stream) throws Http2Exception { NettyServerStream.TransportState serverStream = serverStream(stream); if (serverStream != null) { serverStream.transportReportStatus(msg.getStatus()); resetStream(ctx, stream.id(), Http2Error.CANCEL.code(), ctx.newPromise()); } stream.close(); return true; } }); }
Example #2
Source File: NettyClientHandler.java From grpc-nebula-java with Apache License 2.0 | 6 votes |
private void forcefulClose(final ChannelHandlerContext ctx, final ForcefulCloseCommand msg, ChannelPromise promise) throws Exception { // close() already called by NettyClientTransport, so just need to clean up streams connection().forEachActiveStream(new Http2StreamVisitor() { @Override public boolean visit(Http2Stream stream) throws Http2Exception { NettyClientStream.TransportState clientStream = clientStream(stream); if (clientStream != null) { clientStream.transportReportStatus(msg.getStatus(), true, new Metadata()); resetStream(ctx, stream.id(), Http2Error.CANCEL.code(), ctx.newPromise()); } stream.close(); return true; } }); promise.setSuccess(); }
Example #3
Source File: NettyClientHandler.java From grpc-nebula-java with Apache License 2.0 | 6 votes |
/** * Handler for a GOAWAY being received. Fails any streams created after the * last known stream. */ private void goingAway(Status status) { lifecycleManager.notifyShutdown(status); final Status goAwayStatus = lifecycleManager.getShutdownStatus(); final int lastKnownStream = connection().local().lastStreamKnownByPeer(); try { connection().forEachActiveStream(new Http2StreamVisitor() { @Override public boolean visit(Http2Stream stream) throws Http2Exception { if (stream.id() > lastKnownStream) { NettyClientStream.TransportState clientStream = clientStream(stream); if (clientStream != null) { clientStream.transportReportStatus( goAwayStatus, RpcProgress.REFUSED, false, new Metadata()); } stream.close(); } return true; } }); } catch (Http2Exception e) { throw new RuntimeException(e); } }
Example #4
Source File: NettyServerHandler.java From grpc-java with Apache License 2.0 | 6 votes |
private void forcefulClose(final ChannelHandlerContext ctx, final ForcefulCloseCommand msg, ChannelPromise promise) throws Exception { super.close(ctx, promise); connection().forEachActiveStream(new Http2StreamVisitor() { @Override public boolean visit(Http2Stream stream) throws Http2Exception { NettyServerStream.TransportState serverStream = serverStream(stream); if (serverStream != null) { PerfMark.startTask("NettyServerHandler.forcefulClose", serverStream.tag()); PerfMark.linkIn(msg.getLink()); try { serverStream.transportReportStatus(msg.getStatus()); resetStream(ctx, stream.id(), Http2Error.CANCEL.code(), ctx.newPromise()); } finally { PerfMark.stopTask("NettyServerHandler.forcefulClose", serverStream.tag()); } } stream.close(); return true; } }); }
Example #5
Source File: NettyClientHandler.java From grpc-java with Apache License 2.0 | 6 votes |
private void forcefulClose(final ChannelHandlerContext ctx, final ForcefulCloseCommand msg, ChannelPromise promise) throws Exception { // close() already called by NettyClientTransport, so just need to clean up streams connection().forEachActiveStream(new Http2StreamVisitor() { @Override public boolean visit(Http2Stream stream) throws Http2Exception { NettyClientStream.TransportState clientStream = clientStream(stream); Tag tag = clientStream != null ? clientStream.tag() : PerfMark.createTag(); PerfMark.startTask("NettyClientHandler.forcefulClose", tag); PerfMark.linkIn(msg.getLink()); try { if (clientStream != null) { clientStream.transportReportStatus(msg.getStatus(), true, new Metadata()); resetStream(ctx, stream.id(), Http2Error.CANCEL.code(), ctx.newPromise()); } stream.close(); return true; } finally { PerfMark.stopTask("NettyClientHandler.forcefulClose", tag); } } }); promise.setSuccess(); }
Example #6
Source File: NettyServerHandler.java From grpc-nebula-java with Apache License 2.0 | 5 votes |
/** * Handler for the Channel shutting down. */ @Override public void channelInactive(ChannelHandlerContext ctx) throws Exception { try { if (keepAliveManager != null) { keepAliveManager.onTransportTermination(); } if (maxConnectionIdleManager != null) { maxConnectionIdleManager.onTransportTermination(); } if (maxConnectionAgeMonitor != null) { maxConnectionAgeMonitor.cancel(false); } final Status status = Status.UNAVAILABLE.withDescription("connection terminated for unknown reason"); // Any streams that are still active must be closed connection().forEachActiveStream(new Http2StreamVisitor() { @Override public boolean visit(Http2Stream stream) throws Http2Exception { NettyServerStream.TransportState serverStream = serverStream(stream); if (serverStream != null) { serverStream.transportReportStatus(status); } return true; } }); } finally { super.channelInactive(ctx); } }
Example #7
Source File: NettyClientHandler.java From grpc-nebula-java with Apache License 2.0 | 5 votes |
/** * Handler for the Channel shutting down. */ @Override public void channelInactive(ChannelHandlerContext ctx) throws Exception { try { logger.fine("Network channel is closed"); Status status = Status.UNAVAILABLE.withDescription("Network closed for unknown reason"); lifecycleManager.notifyShutdown(status); try { cancelPing(lifecycleManager.getShutdownThrowable()); // Report status to the application layer for any open streams connection().forEachActiveStream(new Http2StreamVisitor() { @Override public boolean visit(Http2Stream stream) throws Http2Exception { NettyClientStream.TransportState clientStream = clientStream(stream); if (clientStream != null) { clientStream.transportReportStatus( lifecycleManager.getShutdownStatus(), false, new Metadata()); } return true; } }); } finally { lifecycleManager.notifyTerminated(status); } } finally { // Close any open streams super.channelInactive(ctx); if (keepAliveManager != null) { keepAliveManager.onTransportTermination(); } } }
Example #8
Source File: NettyServerHandler.java From grpc-java with Apache License 2.0 | 5 votes |
/** * Handler for the Channel shutting down. */ @Override public void channelInactive(ChannelHandlerContext ctx) throws Exception { try { if (keepAliveManager != null) { keepAliveManager.onTransportTermination(); } if (maxConnectionIdleManager != null) { maxConnectionIdleManager.onTransportTermination(); } if (maxConnectionAgeMonitor != null) { maxConnectionAgeMonitor.cancel(false); } final Status status = Status.UNAVAILABLE.withDescription("connection terminated for unknown reason"); // Any streams that are still active must be closed connection().forEachActiveStream(new Http2StreamVisitor() { @Override public boolean visit(Http2Stream stream) throws Http2Exception { NettyServerStream.TransportState serverStream = serverStream(stream); if (serverStream != null) { serverStream.transportReportStatus(status); } return true; } }); } finally { super.channelInactive(ctx); } }
Example #9
Source File: NettyClientHandler.java From grpc-java with Apache License 2.0 | 5 votes |
/** * Handler for the Channel shutting down. */ @Override public void channelInactive(ChannelHandlerContext ctx) throws Exception { try { logger.fine("Network channel is closed"); Status status = Status.UNAVAILABLE.withDescription("Network closed for unknown reason"); lifecycleManager.notifyShutdown(status); try { cancelPing(lifecycleManager.getShutdownThrowable()); // Report status to the application layer for any open streams connection().forEachActiveStream(new Http2StreamVisitor() { @Override public boolean visit(Http2Stream stream) throws Http2Exception { NettyClientStream.TransportState clientStream = clientStream(stream); if (clientStream != null) { clientStream.transportReportStatus( lifecycleManager.getShutdownStatus(), false, new Metadata()); } return true; } }); } finally { lifecycleManager.notifyTerminated(status); } } finally { // Close any open streams super.channelInactive(ctx); if (keepAliveManager != null) { keepAliveManager.onTransportTermination(); } } }
Example #10
Source File: NettyClientHandler.java From grpc-java with Apache License 2.0 | 5 votes |
/** * Handler for a GOAWAY being received. Fails any streams created after the * last known stream. May only be called during a read. */ private void goingAway(Status status) { lifecycleManager.notifyGracefulShutdown(status); // Try to allocate as many in-flight streams as possible, to reduce race window of // https://github.com/grpc/grpc-java/issues/2562 . To be of any help, the server has to // gracefully shut down the connection with two GOAWAYs. gRPC servers generally send a PING // after the first GOAWAY, so they can very precisely detect when the GOAWAY has been // processed and thus this processing must be in-line before processing additional reads. // This can cause reentrancy, but should be minor since it is normal to handle writes in // response to a read. Also, the call stack is rather shallow at this point clientWriteQueue.drainNow(); lifecycleManager.notifyShutdown(status); final Status goAwayStatus = lifecycleManager.getShutdownStatus(); final int lastKnownStream = connection().local().lastStreamKnownByPeer(); try { connection().forEachActiveStream(new Http2StreamVisitor() { @Override public boolean visit(Http2Stream stream) throws Http2Exception { if (stream.id() > lastKnownStream) { NettyClientStream.TransportState clientStream = clientStream(stream); if (clientStream != null) { clientStream.transportReportStatus( goAwayStatus, RpcProgress.REFUSED, false, new Metadata()); } stream.close(); } return true; } }); } catch (Http2Exception e) { throw new RuntimeException(e); } }