Package io.grpc.netty
Class NettyServerHandler
- java.lang.Object
-
- io.netty.channel.ChannelHandlerAdapter
-
- io.netty.channel.ChannelInboundHandlerAdapter
-
- io.netty.handler.codec.ByteToMessageDecoder
-
- io.netty.handler.codec.http2.Http2ConnectionHandler
-
- io.grpc.netty.GrpcHttp2ConnectionHandler
-
- io.grpc.netty.AbstractNettyHandler
-
- io.grpc.netty.NettyServerHandler
-
- All Implemented Interfaces:
io.netty.channel.ChannelHandler
,io.netty.channel.ChannelInboundHandler
,io.netty.channel.ChannelOutboundHandler
,io.netty.handler.codec.http2.Http2LifecycleManager
class NettyServerHandler extends AbstractNettyHandler
Server-side Netty handler for GRPC processing. All event handlers are executed entirely within the context of the Netty Channel thread.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private class
NettyServerHandler.FrameListener
private class
NettyServerHandler.GracefulShutdown
private class
NettyServerHandler.KeepAlivePinger
private static class
NettyServerHandler.ServerChannelLogger
private static class
NettyServerHandler.WriteMonitoringFrameWriter
-
Nested classes/interfaces inherited from class io.grpc.netty.AbstractNettyHandler
AbstractNettyHandler.FlowControlPinger, AbstractNettyHandler.PingLimiter
-
-
Field Summary
Fields Modifier and Type Field Description private Attributes
attributes
Completed attributes produced by transportReady.private java.lang.Throwable
connectionError
private static boolean
DISABLE_CONNECTION_HEADER_CHECK
Temporary workaround for #8674.private Attributes
eagAttributes
(package private) static long
GRACEFUL_SHUTDOWN_PING
private static long
GRACEFUL_SHUTDOWN_PING_TIMEOUT_NANOS
private NettyServerHandler.GracefulShutdown
gracefulShutdown
private static long
KEEPALIVE_PING
private KeepAliveEnforcer
keepAliveEnforcer
private KeepAliveManager
keepAliveManager
private long
keepAliveTimeInNanos
private long
keepAliveTimeoutInNanos
private io.netty.util.AsciiString
lastKnownAuthority
private long
lastRstNanoTime
private static java.util.logging.Logger
logger
private long
maxConnectionAgeGraceInNanos
private long
maxConnectionAgeInNanos
private java.util.concurrent.ScheduledFuture<?>
maxConnectionAgeMonitor
private MaxConnectionIdleManager
maxConnectionIdleManager
private int
maxMessageSize
private int
maxRstCount
private long
maxRstPeriodNanos
private Attributes
negotiationAttributes
Incomplete attributes produced by negotiator.private int
rstCount
private InternalChannelz.Security
securityInfo
private WriteQueue
serverWriteQueue
private io.netty.handler.codec.http2.Http2Connection.PropertyKey
streamKey
private java.util.List<? extends ServerStreamTracer.Factory>
streamTracerFactories
private boolean
teWarningLogged
private com.google.common.base.Ticker
ticker
private ServerTransportListener
transportListener
private TransportTracer
transportTracer
-
Fields inherited from class io.grpc.netty.GrpcHttp2ConnectionHandler
ADAPTIVE_CUMULATOR, ADAPTIVE_CUMULATOR_COMPOSE_MIN_SIZE_DEFAULT, channelUnused
-
-
Constructor Summary
Constructors Modifier Constructor Description private
NettyServerHandler(io.netty.channel.ChannelPromise channelUnused, io.netty.handler.codec.http2.Http2Connection connection, ServerTransportListener transportListener, java.util.List<? extends ServerStreamTracer.Factory> streamTracerFactories, TransportTracer transportTracer, io.netty.handler.codec.http2.Http2ConnectionDecoder decoder, io.netty.handler.codec.http2.Http2ConnectionEncoder encoder, io.netty.handler.codec.http2.Http2Settings settings, int maxMessageSize, long keepAliveTimeInNanos, long keepAliveTimeoutInNanos, long maxConnectionIdleInNanos, long maxConnectionAgeInNanos, long maxConnectionAgeGraceInNanos, KeepAliveEnforcer keepAliveEnforcer, boolean autoFlowControl, int maxRstCount, long maxRstPeriodNanos, Attributes eagAttributes, com.google.common.base.Ticker ticker)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description private void
cancelStream(io.netty.channel.ChannelHandlerContext ctx, CancelServerStreamCommand cmd, io.netty.channel.ChannelPromise promise)
void
channelInactive(io.netty.channel.ChannelHandlerContext ctx)
Handler for the Channel shutting down.void
close(io.netty.channel.ChannelHandlerContext ctx, io.netty.channel.ChannelPromise promise)
private void
closeStreamWhenDone(io.netty.channel.ChannelPromise promise, io.netty.handler.codec.http2.Http2Stream stream)
(package private) java.lang.Throwable
connectionError()
private void
forcefulClose(io.netty.channel.ChannelHandlerContext ctx, ForcefulCloseCommand msg, io.netty.channel.ChannelPromise promise)
Attributes
getEagAttributes()
Get the attributes of the EquivalentAddressGroup used to create this transport.(package private) KeepAliveManager
getKeepAliveManagerForTest()
private java.lang.String
getOrUpdateAuthority(io.netty.util.AsciiString authority)
(package private) InternalChannelz.Security
getSecurityInfo()
(package private) WriteQueue
getWriteQueue()
private void
gracefulClose(io.netty.channel.ChannelHandlerContext ctx, GracefulServerCloseCommand msg, io.netty.channel.ChannelPromise promise)
void
handleProtocolNegotiationCompleted(Attributes attrs, InternalChannelz.Security securityInfo)
Triggered on protocol negotiation completion.void
handlerAdded(io.netty.channel.ChannelHandlerContext ctx)
(package private) static NettyServerHandler
newHandler(ServerTransportListener transportListener, io.netty.channel.ChannelPromise channelUnused, java.util.List<? extends ServerStreamTracer.Factory> streamTracerFactories, TransportTracer transportTracer, int maxStreams, boolean autoFlowControl, int flowControlWindow, int maxHeaderListSize, int maxMessageSize, long keepAliveTimeInNanos, long keepAliveTimeoutInNanos, long maxConnectionIdleInNanos, long maxConnectionAgeInNanos, long maxConnectionAgeGraceInNanos, boolean permitKeepAliveWithoutCalls, long permitKeepAliveTimeInNanos, int maxRstCount, long maxRstPeriodNanos, Attributes eagAttributes)
(package private) static NettyServerHandler
newHandler(io.netty.channel.ChannelPromise channelUnused, io.netty.handler.codec.http2.Http2FrameReader frameReader, io.netty.handler.codec.http2.Http2FrameWriter frameWriter, ServerTransportListener transportListener, java.util.List<? extends ServerStreamTracer.Factory> streamTracerFactories, TransportTracer transportTracer, int maxStreams, boolean autoFlowControl, int flowControlWindow, int maxHeaderListSize, int maxMessageSize, long keepAliveTimeInNanos, long keepAliveTimeoutInNanos, long maxConnectionIdleInNanos, long maxConnectionAgeInNanos, long maxConnectionAgeGraceInNanos, boolean permitKeepAliveWithoutCalls, long permitKeepAliveTimeInNanos, int maxRstCount, long maxRstPeriodNanos, Attributes eagAttributes, com.google.common.base.Ticker ticker)
private io.netty.handler.codec.http2.Http2Exception
newStreamException(int streamId, java.lang.Throwable cause)
protected void
onConnectionError(io.netty.channel.ChannelHandlerContext ctx, boolean outbound, java.lang.Throwable cause, io.netty.handler.codec.http2.Http2Exception http2Ex)
private void
onDataRead(int streamId, io.netty.buffer.ByteBuf data, int padding, boolean endOfStream)
private void
onHeadersRead(io.netty.channel.ChannelHandlerContext ctx, int streamId, io.netty.handler.codec.http2.Http2Headers headers)
private void
onRstStreamRead(int streamId, long errorCode)
protected void
onStreamError(io.netty.channel.ChannelHandlerContext ctx, boolean outbound, java.lang.Throwable cause, io.netty.handler.codec.http2.Http2Exception.StreamException http2Ex)
private io.netty.handler.codec.http2.Http2Stream
requireHttp2Stream(int streamId)
private void
respondWithHttpError(io.netty.channel.ChannelHandlerContext ctx, int streamId, int code, Status.Code statusCode, java.lang.String msg)
(package private) void
returnProcessedBytes(io.netty.handler.codec.http2.Http2Stream http2Stream, int bytes)
Returns the given processed bytes back to inbound flow control.private void
sendGrpcFrame(io.netty.channel.ChannelHandlerContext ctx, SendGrpcFrameCommand cmd, io.netty.channel.ChannelPromise promise)
Sends the given gRPC frame to the client.private void
sendResponseHeaders(io.netty.channel.ChannelHandlerContext ctx, SendResponseHeadersCommand cmd, io.netty.channel.ChannelPromise promise)
Sends the response headers to the client.private NettyServerStream.TransportState
serverStream(io.netty.handler.codec.http2.Http2Stream stream)
Returns the server stream associated to the given HTTP/2 stream object.(package private) void
setKeepAliveManagerForTest(KeepAliveManager keepAliveManager)
private static boolean
shouldCloseStreamWithHeaders(CancelServerStreamCommand cmd, io.netty.handler.codec.http2.Http2Connection conn)
private static void
streamGone(int streamId, io.netty.channel.ChannelPromise promise)
private static java.util.logging.Level
toJavaLogLevel(ChannelLogger.ChannelLogLevel level)
void
write(io.netty.channel.ChannelHandlerContext ctx, java.lang.Object msg, io.netty.channel.ChannelPromise promise)
Handler for commands sent from the stream.-
Methods inherited from class io.grpc.netty.AbstractNettyHandler
channelActive, ctx, exceptionCaught, flowControlPing, setAutoTuneFlowControl
-
Methods inherited from class io.grpc.netty.GrpcHttp2ConnectionHandler
getAuthority, getNegotiationLogger, handleProtocolNegotiationCompleted, notifyUnused, usingPre4_1_111_Netty
-
Methods inherited from class io.netty.handler.codec.http2.Http2ConnectionHandler
bind, channelReadComplete, channelWritabilityChanged, closeStream, closeStreamLocal, closeStreamRemote, connect, connection, decode, decoder, deregister, disconnect, encoder, flush, frameWriter, goAway, gracefulShutdownTimeoutMillis, gracefulShutdownTimeoutMillis, handlerRemoved0, handleServerHeaderDecodeSizeError, isGracefulShutdownComplete, onError, onHttpClientUpgrade, onHttpServerUpgrade, read, resetStream
-
Methods inherited from class io.netty.handler.codec.ByteToMessageDecoder
actualReadableBytes, callDecode, channelRead, decodeLast, discardSomeReadBytes, handlerRemoved, internalBuffer, isSingleDecode, setCumulator, setDiscardAfterReads, setSingleDecode, userEventTriggered
-
Methods inherited from class io.netty.channel.ChannelInboundHandlerAdapter
channelRegistered, channelUnregistered
-
-
-
-
Field Detail
-
logger
private static final java.util.logging.Logger logger
-
KEEPALIVE_PING
private static final long KEEPALIVE_PING
- See Also:
- Constant Field Values
-
GRACEFUL_SHUTDOWN_PING
static final long GRACEFUL_SHUTDOWN_PING
- See Also:
- Constant Field Values
-
GRACEFUL_SHUTDOWN_PING_TIMEOUT_NANOS
private static final long GRACEFUL_SHUTDOWN_PING_TIMEOUT_NANOS
-
DISABLE_CONNECTION_HEADER_CHECK
private static final boolean DISABLE_CONNECTION_HEADER_CHECK
Temporary workaround for #8674. Fine to delete after v1.45 release, and maybe earlier.
-
streamKey
private final io.netty.handler.codec.http2.Http2Connection.PropertyKey streamKey
-
transportListener
private final ServerTransportListener transportListener
-
maxMessageSize
private final int maxMessageSize
-
keepAliveTimeInNanos
private final long keepAliveTimeInNanos
-
keepAliveTimeoutInNanos
private final long keepAliveTimeoutInNanos
-
maxConnectionAgeInNanos
private final long maxConnectionAgeInNanos
-
maxConnectionAgeGraceInNanos
private final long maxConnectionAgeGraceInNanos
-
maxRstCount
private final int maxRstCount
-
maxRstPeriodNanos
private final long maxRstPeriodNanos
-
streamTracerFactories
private final java.util.List<? extends ServerStreamTracer.Factory> streamTracerFactories
-
transportTracer
private final TransportTracer transportTracer
-
keepAliveEnforcer
private final KeepAliveEnforcer keepAliveEnforcer
-
eagAttributes
private final Attributes eagAttributes
-
ticker
private final com.google.common.base.Ticker ticker
-
negotiationAttributes
private Attributes negotiationAttributes
Incomplete attributes produced by negotiator.
-
securityInfo
private InternalChannelz.Security securityInfo
-
attributes
private Attributes attributes
Completed attributes produced by transportReady.
-
connectionError
private java.lang.Throwable connectionError
-
teWarningLogged
private boolean teWarningLogged
-
serverWriteQueue
private WriteQueue serverWriteQueue
-
lastKnownAuthority
private io.netty.util.AsciiString lastKnownAuthority
-
keepAliveManager
@CheckForNull private KeepAliveManager keepAliveManager
-
maxConnectionIdleManager
@CheckForNull private MaxConnectionIdleManager maxConnectionIdleManager
-
maxConnectionAgeMonitor
@CheckForNull private java.util.concurrent.ScheduledFuture<?> maxConnectionAgeMonitor
-
gracefulShutdown
@CheckForNull private NettyServerHandler.GracefulShutdown gracefulShutdown
-
rstCount
private int rstCount
-
lastRstNanoTime
private long lastRstNanoTime
-
-
Constructor Detail
-
NettyServerHandler
private NettyServerHandler(io.netty.channel.ChannelPromise channelUnused, io.netty.handler.codec.http2.Http2Connection connection, ServerTransportListener transportListener, java.util.List<? extends ServerStreamTracer.Factory> streamTracerFactories, TransportTracer transportTracer, io.netty.handler.codec.http2.Http2ConnectionDecoder decoder, io.netty.handler.codec.http2.Http2ConnectionEncoder encoder, io.netty.handler.codec.http2.Http2Settings settings, int maxMessageSize, long keepAliveTimeInNanos, long keepAliveTimeoutInNanos, long maxConnectionIdleInNanos, long maxConnectionAgeInNanos, long maxConnectionAgeGraceInNanos, KeepAliveEnforcer keepAliveEnforcer, boolean autoFlowControl, int maxRstCount, long maxRstPeriodNanos, Attributes eagAttributes, com.google.common.base.Ticker ticker)
-
-
Method Detail
-
newHandler
static NettyServerHandler newHandler(ServerTransportListener transportListener, io.netty.channel.ChannelPromise channelUnused, java.util.List<? extends ServerStreamTracer.Factory> streamTracerFactories, TransportTracer transportTracer, int maxStreams, boolean autoFlowControl, int flowControlWindow, int maxHeaderListSize, int maxMessageSize, long keepAliveTimeInNanos, long keepAliveTimeoutInNanos, long maxConnectionIdleInNanos, long maxConnectionAgeInNanos, long maxConnectionAgeGraceInNanos, boolean permitKeepAliveWithoutCalls, long permitKeepAliveTimeInNanos, int maxRstCount, long maxRstPeriodNanos, Attributes eagAttributes)
-
newHandler
static NettyServerHandler newHandler(io.netty.channel.ChannelPromise channelUnused, io.netty.handler.codec.http2.Http2FrameReader frameReader, io.netty.handler.codec.http2.Http2FrameWriter frameWriter, ServerTransportListener transportListener, java.util.List<? extends ServerStreamTracer.Factory> streamTracerFactories, TransportTracer transportTracer, int maxStreams, boolean autoFlowControl, int flowControlWindow, int maxHeaderListSize, int maxMessageSize, long keepAliveTimeInNanos, long keepAliveTimeoutInNanos, long maxConnectionIdleInNanos, long maxConnectionAgeInNanos, long maxConnectionAgeGraceInNanos, boolean permitKeepAliveWithoutCalls, long permitKeepAliveTimeInNanos, int maxRstCount, long maxRstPeriodNanos, Attributes eagAttributes, com.google.common.base.Ticker ticker)
-
connectionError
@Nullable java.lang.Throwable connectionError()
-
handlerAdded
public void handlerAdded(io.netty.channel.ChannelHandlerContext ctx) throws java.lang.Exception
- Specified by:
handlerAdded
in interfaceio.netty.channel.ChannelHandler
- Overrides:
handlerAdded
in classAbstractNettyHandler
- Throws:
java.lang.Exception
-
onHeadersRead
private void onHeadersRead(io.netty.channel.ChannelHandlerContext ctx, int streamId, io.netty.handler.codec.http2.Http2Headers headers) throws io.netty.handler.codec.http2.Http2Exception
- Throws:
io.netty.handler.codec.http2.Http2Exception
-
getOrUpdateAuthority
private java.lang.String getOrUpdateAuthority(io.netty.util.AsciiString authority)
-
onDataRead
private void onDataRead(int streamId, io.netty.buffer.ByteBuf data, int padding, boolean endOfStream) throws io.netty.handler.codec.http2.Http2Exception
- Throws:
io.netty.handler.codec.http2.Http2Exception
-
onRstStreamRead
private void onRstStreamRead(int streamId, long errorCode) throws io.netty.handler.codec.http2.Http2Exception
- Throws:
io.netty.handler.codec.http2.Http2Exception
-
onConnectionError
protected void onConnectionError(io.netty.channel.ChannelHandlerContext ctx, boolean outbound, java.lang.Throwable cause, io.netty.handler.codec.http2.Http2Exception http2Ex)
- Overrides:
onConnectionError
in classio.netty.handler.codec.http2.Http2ConnectionHandler
-
onStreamError
protected void onStreamError(io.netty.channel.ChannelHandlerContext ctx, boolean outbound, java.lang.Throwable cause, io.netty.handler.codec.http2.Http2Exception.StreamException http2Ex)
- Overrides:
onStreamError
in classio.netty.handler.codec.http2.Http2ConnectionHandler
-
handleProtocolNegotiationCompleted
public void handleProtocolNegotiationCompleted(Attributes attrs, InternalChannelz.Security securityInfo)
Description copied from class:GrpcHttp2ConnectionHandler
Triggered on protocol negotiation completion.It must me called after negotiation is completed but before given handler is added to the channel.
- Overrides:
handleProtocolNegotiationCompleted
in classGrpcHttp2ConnectionHandler
- Parameters:
attrs
- arbitrary attributes passed after protocol negotiation (eg. SSLSession).securityInfo
- informs channelz about the security protocol.
-
getEagAttributes
public Attributes getEagAttributes()
Description copied from class:GrpcHttp2ConnectionHandler
Get the attributes of the EquivalentAddressGroup used to create this transport.- Overrides:
getEagAttributes
in classGrpcHttp2ConnectionHandler
-
getSecurityInfo
InternalChannelz.Security getSecurityInfo()
-
getKeepAliveManagerForTest
KeepAliveManager getKeepAliveManagerForTest()
-
setKeepAliveManagerForTest
void setKeepAliveManagerForTest(KeepAliveManager keepAliveManager)
-
channelInactive
public void channelInactive(io.netty.channel.ChannelHandlerContext ctx) throws java.lang.Exception
Handler for the Channel shutting down.- Specified by:
channelInactive
in interfaceio.netty.channel.ChannelInboundHandler
- Overrides:
channelInactive
in classio.netty.handler.codec.http2.Http2ConnectionHandler
- Throws:
java.lang.Exception
-
getWriteQueue
WriteQueue getWriteQueue()
-
write
public void write(io.netty.channel.ChannelHandlerContext ctx, java.lang.Object msg, io.netty.channel.ChannelPromise promise) throws java.lang.Exception
Handler for commands sent from the stream.- Specified by:
write
in interfaceio.netty.channel.ChannelOutboundHandler
- Overrides:
write
in classio.netty.handler.codec.http2.Http2ConnectionHandler
- Throws:
java.lang.Exception
-
close
public void close(io.netty.channel.ChannelHandlerContext ctx, io.netty.channel.ChannelPromise promise) throws java.lang.Exception
- Specified by:
close
in interfaceio.netty.channel.ChannelOutboundHandler
- Overrides:
close
in classio.netty.handler.codec.http2.Http2ConnectionHandler
- Throws:
java.lang.Exception
-
returnProcessedBytes
void returnProcessedBytes(io.netty.handler.codec.http2.Http2Stream http2Stream, int bytes)
Returns the given processed bytes back to inbound flow control.
-
closeStreamWhenDone
private void closeStreamWhenDone(io.netty.channel.ChannelPromise promise, io.netty.handler.codec.http2.Http2Stream stream)
-
streamGone
private static void streamGone(int streamId, io.netty.channel.ChannelPromise promise)
-
sendGrpcFrame
private void sendGrpcFrame(io.netty.channel.ChannelHandlerContext ctx, SendGrpcFrameCommand cmd, io.netty.channel.ChannelPromise promise) throws io.netty.handler.codec.http2.Http2Exception
Sends the given gRPC frame to the client.- Throws:
io.netty.handler.codec.http2.Http2Exception
-
sendResponseHeaders
private void sendResponseHeaders(io.netty.channel.ChannelHandlerContext ctx, SendResponseHeadersCommand cmd, io.netty.channel.ChannelPromise promise) throws io.netty.handler.codec.http2.Http2Exception
Sends the response headers to the client.- Throws:
io.netty.handler.codec.http2.Http2Exception
-
cancelStream
private void cancelStream(io.netty.channel.ChannelHandlerContext ctx, CancelServerStreamCommand cmd, io.netty.channel.ChannelPromise promise)
-
shouldCloseStreamWithHeaders
private static boolean shouldCloseStreamWithHeaders(CancelServerStreamCommand cmd, io.netty.handler.codec.http2.Http2Connection conn)
-
gracefulClose
private void gracefulClose(io.netty.channel.ChannelHandlerContext ctx, GracefulServerCloseCommand msg, io.netty.channel.ChannelPromise promise) throws java.lang.Exception
- Throws:
java.lang.Exception
-
forcefulClose
private void forcefulClose(io.netty.channel.ChannelHandlerContext ctx, ForcefulCloseCommand msg, io.netty.channel.ChannelPromise promise) throws java.lang.Exception
- Throws:
java.lang.Exception
-
respondWithHttpError
private void respondWithHttpError(io.netty.channel.ChannelHandlerContext ctx, int streamId, int code, Status.Code statusCode, java.lang.String msg)
-
requireHttp2Stream
private io.netty.handler.codec.http2.Http2Stream requireHttp2Stream(int streamId)
-
serverStream
private NettyServerStream.TransportState serverStream(io.netty.handler.codec.http2.Http2Stream stream)
Returns the server stream associated to the given HTTP/2 stream object.
-
newStreamException
private io.netty.handler.codec.http2.Http2Exception newStreamException(int streamId, java.lang.Throwable cause)
-
toJavaLogLevel
private static java.util.logging.Level toJavaLogLevel(ChannelLogger.ChannelLogLevel level)
-
-