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
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 ClassesModifier and TypeClassDescriptionprivate classprivate final classprivate final classprivate static classprivate static classNested classes/interfaces inherited from class io.grpc.netty.AbstractNettyHandler
AbstractNettyHandler.FlowControlPinger, AbstractNettyHandler.PingLimiterNested classes/interfaces inherited from class io.netty.handler.codec.ByteToMessageDecoder
io.netty.handler.codec.ByteToMessageDecoder.CumulatorNested classes/interfaces inherited from interface io.netty.channel.ChannelHandler
io.netty.channel.ChannelHandler.Sharable -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate AttributesCompleted attributes produced by transportReady.private Throwableprivate static final booleanTemporary workaround for #8674.private final Attributes(package private) static final longprivate static final longprivate static final longprivate final KeepAliveEnforcerprivate KeepAliveManagerprivate final longprivate final longprivate io.netty.util.AsciiStringprivate longprivate static final Loggerprivate final longprivate final longprivate ScheduledFuture<?> private MaxConnectionIdleManagerprivate final intprivate final intprivate final longprivate AttributesIncomplete attributes produced by negotiator.private intprivate InternalChannelz.Securityprivate WriteQueueprivate final io.netty.handler.codec.http2.Http2Connection.PropertyKeyprivate final List<? extends ServerStreamTracer.Factory> private booleanprivate final com.google.common.base.Tickerprivate final ServerTransportListenerprivate final TransportTracerFields inherited from class io.grpc.netty.GrpcHttp2ConnectionHandler
ADAPTIVE_CUMULATOR, ADAPTIVE_CUMULATOR_COMPOSE_MIN_SIZE_DEFAULT, channelUnusedFields inherited from class io.netty.handler.codec.ByteToMessageDecoder
COMPOSITE_CUMULATOR, MERGE_CUMULATOR -
Constructor Summary
ConstructorsModifierConstructorDescriptionprivateNettyServerHandler(io.netty.channel.ChannelPromise channelUnused, io.netty.handler.codec.http2.Http2Connection connection, ServerTransportListener transportListener, 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
Modifier and TypeMethodDescriptionprivate voidcancelStream(io.netty.channel.ChannelHandlerContext ctx, CancelServerStreamCommand cmd, io.netty.channel.ChannelPromise promise) voidchannelInactive(io.netty.channel.ChannelHandlerContext ctx) Handler for the Channel shutting down.voidclose(io.netty.channel.ChannelHandlerContext ctx, io.netty.channel.ChannelPromise promise) private voidcloseStreamWhenDone(io.netty.channel.ChannelPromise promise, io.netty.handler.codec.http2.Http2Stream stream) (package private) Throwableprivate voidforcefulClose(io.netty.channel.ChannelHandlerContext ctx, ForcefulCloseCommand msg, io.netty.channel.ChannelPromise promise) Get the attributes of the EquivalentAddressGroup used to create this transport.(package private) KeepAliveManagerprivate StringgetOrUpdateAuthority(io.netty.util.AsciiString authority) (package private) InternalChannelz.Security(package private) WriteQueueprivate voidgracefulClose(io.netty.channel.ChannelHandlerContext ctx, GracefulServerCloseCommand msg, io.netty.channel.ChannelPromise promise) voidhandleProtocolNegotiationCompleted(Attributes attrs, InternalChannelz.Security securityInfo) Triggered on protocol negotiation completion.voidhandlerAdded(io.netty.channel.ChannelHandlerContext ctx) (package private) static NettyServerHandlernewHandler(ServerTransportListener transportListener, io.netty.channel.ChannelPromise channelUnused, 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 NettyServerHandlernewHandler(io.netty.channel.ChannelPromise channelUnused, io.netty.handler.codec.http2.Http2FrameReader frameReader, io.netty.handler.codec.http2.Http2FrameWriter frameWriter, ServerTransportListener transportListener, 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.Http2ExceptionnewStreamException(int streamId, Throwable cause) protected voidonConnectionError(io.netty.channel.ChannelHandlerContext ctx, boolean outbound, Throwable cause, io.netty.handler.codec.http2.Http2Exception http2Ex) private voidonDataRead(int streamId, io.netty.buffer.ByteBuf data, int padding, boolean endOfStream) private voidonHeadersRead(io.netty.channel.ChannelHandlerContext ctx, int streamId, io.netty.handler.codec.http2.Http2Headers headers) private voidonRstStreamRead(int streamId, long errorCode) protected voidonStreamError(io.netty.channel.ChannelHandlerContext ctx, boolean outbound, Throwable cause, io.netty.handler.codec.http2.Http2Exception.StreamException http2Ex) private io.netty.handler.codec.http2.Http2StreamrequireHttp2Stream(int streamId) private voidrespondWithHttpError(io.netty.channel.ChannelHandlerContext ctx, int streamId, int code, Status.Code statusCode, String msg) (package private) voidreturnProcessedBytes(io.netty.handler.codec.http2.Http2Stream http2Stream, int bytes) Returns the given processed bytes back to inbound flow control.private voidsendGrpcFrame(io.netty.channel.ChannelHandlerContext ctx, SendGrpcFrameCommand cmd, io.netty.channel.ChannelPromise promise) Sends the given gRPC frame to the client.private voidsendResponseHeaders(io.netty.channel.ChannelHandlerContext ctx, SendResponseHeadersCommand cmd, io.netty.channel.ChannelPromise promise) Sends the response headers to the client.private NettyServerStream.TransportStateserverStream(io.netty.handler.codec.http2.Http2Stream stream) Returns the server stream associated to the given HTTP/2 stream object.(package private) voidsetKeepAliveManagerForTest(KeepAliveManager keepAliveManager) private static booleanshouldCloseStreamWithHeaders(CancelServerStreamCommand cmd, io.netty.handler.codec.http2.Http2Connection conn) private static voidstreamGone(int streamId, io.netty.channel.ChannelPromise promise) private static Levelvoidwrite(io.netty.channel.ChannelHandlerContext ctx, 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, setAutoTuneFlowControlMethods inherited from class io.grpc.netty.GrpcHttp2ConnectionHandler
getAuthority, getNegotiationLogger, handleProtocolNegotiationCompleted, notifyUnused, usingPre4_1_111_NettyMethods 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, resetStreamMethods inherited from class io.netty.handler.codec.ByteToMessageDecoder
actualReadableBytes, callDecode, channelRead, decodeLast, discardSomeReadBytes, handlerRemoved, internalBuffer, isSingleDecode, setCumulator, setDiscardAfterReads, setSingleDecode, userEventTriggeredMethods inherited from class io.netty.channel.ChannelInboundHandlerAdapter
channelRegistered, channelUnregisteredMethods inherited from class io.netty.channel.ChannelHandlerAdapter
ensureNotSharable, isSharableMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface io.netty.channel.ChannelHandler
handlerRemoved
-
Field Details
-
logger
-
KEEPALIVE_PING
private static final long KEEPALIVE_PING- See Also:
-
GRACEFUL_SHUTDOWN_PING
static final long GRACEFUL_SHUTDOWN_PING- See Also:
-
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_CHECKTemporary 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
-
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
-
transportTracer
-
keepAliveEnforcer
-
eagAttributes
-
ticker
private final com.google.common.base.Ticker ticker -
negotiationAttributes
Incomplete attributes produced by negotiator. -
securityInfo
-
attributes
Completed attributes produced by transportReady. -
connectionError
-
teWarningLogged
private boolean teWarningLogged -
serverWriteQueue
-
lastKnownAuthority
private io.netty.util.AsciiString lastKnownAuthority -
keepAliveManager
-
maxConnectionIdleManager
-
maxConnectionAgeMonitor
-
gracefulShutdown
-
rstCount
private int rstCount -
lastRstNanoTime
private long lastRstNanoTime
-
-
Constructor Details
-
NettyServerHandler
private NettyServerHandler(io.netty.channel.ChannelPromise channelUnused, io.netty.handler.codec.http2.Http2Connection connection, ServerTransportListener transportListener, 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 Details
-
newHandler
static NettyServerHandler newHandler(ServerTransportListener transportListener, io.netty.channel.ChannelPromise channelUnused, 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, 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
-
handlerAdded
- Specified by:
handlerAddedin interfaceio.netty.channel.ChannelHandler- Overrides:
handlerAddedin classAbstractNettyHandler- Throws:
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
-
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, Throwable cause, io.netty.handler.codec.http2.Http2Exception http2Ex) - Overrides:
onConnectionErrorin classio.netty.handler.codec.http2.Http2ConnectionHandler
-
onStreamError
protected void onStreamError(io.netty.channel.ChannelHandlerContext ctx, boolean outbound, Throwable cause, io.netty.handler.codec.http2.Http2Exception.StreamException http2Ex) - Overrides:
onStreamErrorin classio.netty.handler.codec.http2.Http2ConnectionHandler
-
handleProtocolNegotiationCompleted
public void handleProtocolNegotiationCompleted(Attributes attrs, InternalChannelz.Security securityInfo) Description copied from class:GrpcHttp2ConnectionHandlerTriggered on protocol negotiation completion.It must me called after negotiation is completed but before given handler is added to the channel.
- Overrides:
handleProtocolNegotiationCompletedin classGrpcHttp2ConnectionHandler- Parameters:
attrs- arbitrary attributes passed after protocol negotiation (eg. SSLSession).securityInfo- informs channelz about the security protocol.
-
getEagAttributes
Description copied from class:GrpcHttp2ConnectionHandlerGet the attributes of the EquivalentAddressGroup used to create this transport.- Overrides:
getEagAttributesin classGrpcHttp2ConnectionHandler
-
getSecurityInfo
InternalChannelz.Security getSecurityInfo() -
getKeepAliveManagerForTest
KeepAliveManager getKeepAliveManagerForTest() -
setKeepAliveManagerForTest
-
channelInactive
Handler for the Channel shutting down.- Specified by:
channelInactivein interfaceio.netty.channel.ChannelInboundHandler- Overrides:
channelInactivein classio.netty.handler.codec.http2.Http2ConnectionHandler- Throws:
Exception
-
getWriteQueue
WriteQueue getWriteQueue() -
write
public void write(io.netty.channel.ChannelHandlerContext ctx, Object msg, io.netty.channel.ChannelPromise promise) throws Exception Handler for commands sent from the stream.- Specified by:
writein interfaceio.netty.channel.ChannelOutboundHandler- Overrides:
writein classio.netty.handler.codec.http2.Http2ConnectionHandler- Throws:
Exception
-
close
public void close(io.netty.channel.ChannelHandlerContext ctx, io.netty.channel.ChannelPromise promise) throws Exception - Specified by:
closein interfaceio.netty.channel.ChannelOutboundHandler- Overrides:
closein classio.netty.handler.codec.http2.Http2ConnectionHandler- Throws:
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 Exception - Throws:
Exception
-
forcefulClose
private void forcefulClose(io.netty.channel.ChannelHandlerContext ctx, ForcefulCloseCommand msg, io.netty.channel.ChannelPromise promise) throws Exception - Throws:
Exception
-
respondWithHttpError
private void respondWithHttpError(io.netty.channel.ChannelHandlerContext ctx, int streamId, int code, Status.Code statusCode, 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, Throwable cause) -
toJavaLogLevel
-