/** * Called by the graceful shutdown logic to determine when it is safe to close the connection. Returns {@code true} * if the graceful shutdown has completed and the connection can be safely closed. This implementation just * guarantees that there are no active streams. Subclasses may override to provide additional checks. */ protected boolean isGracefulShutdownComplete() { return connection().numActiveStreams() == 0; }
private void checkShutdownHandler() { Handler<Void> shutdownHandler; synchronized (this) { if (shutdown) { return; } Http2Connection conn = handler.connection(); if ((!conn.goAwayReceived() && !conn.goAwaySent()) || conn.numActiveStreams() > 0) { return; } shutdown = true; shutdownHandler = this.shutdownHandler; } if (shutdownHandler != null) { context.executeFromIO(shutdownHandler); } } }
private void checkShutdownHandler() { Handler<Void> shutdownHandler; synchronized (this) { if (shutdown) { return; } Http2Connection conn = handler.connection(); if ((!conn.goAwayReceived() && !conn.goAwaySent()) || conn.numActiveStreams() > 0) { return; } shutdown = true; shutdownHandler = this.shutdownHandler; } if (shutdownHandler != null) { context.executeFromIO(shutdownHandler); } } }
/** * Called by the graceful shutdown logic to determine when it is safe to close the connection. Returns {@code true} * if the graceful shutdown has completed and the connection can be safely closed. This implementation just * guarantees that there are no active streams. Subclasses may override to provide additional checks. */ protected boolean isGracefulShutdownComplete() { return connection().numActiveStreams() == 0; }
/** * Called by the graceful shutdown logic to determine when it is safe to close the connection. Returns {@code true} * if the graceful shutdown has completed and the connection can be safely closed. This implementation just * guarantees that there are no active streams. Subclasses may override to provide additional checks. */ protected boolean isGracefulShutdownComplete() { return connection().numActiveStreams() == 0; }
@Override protected void onConnectionError(ChannelHandlerContext ctx, Throwable cause, Http2Exception connectionError) { // Logs the full exception here final String message = String.format( "HTTP/2 connection encountered an exception, streamCount=%d, remote=%s, channel=%s", connection().numActiveStreams(), ctx.channel().remoteAddress(), ctx.channel().id()); LOG.error(message, cause); try { connection().forEachActiveStream(stream -> { resetStream(ctx, stream.id(), Http2Error.CANCEL.code(), ctx.newPromise()); doOnStreamError(ctx, stream.id(), cause); return true; }); ctx.flush(); } catch (Http2Exception e) { LOG.error("Encountered exception while invoking request callbacks with errors", e); } finally { super.onConnectionError(ctx, cause, connectionError); } }