Class NettyClientHandler
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.NettyClientHandler
- All Implemented Interfaces:
io.netty.channel.ChannelHandler, io.netty.channel.ChannelInboundHandler, io.netty.channel.ChannelOutboundHandler, io.netty.handler.codec.http2.Http2LifecycleManager
Client-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 static classNested classes/interfaces inherited from class 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 Statusprivate Attributesprivate final Stringprivate Statusprivate WriteQueueprivate final Attributesprivate static final StatusStatus used when the transport has exhausted the number of streams.private final InUseStateAggregator<io.netty.handler.codec.http2.Http2Stream> private final KeepAliveManagerprivate final ClientTransportLifecycleManagerprivate static final Logger(package private) static final ObjectA message that simply passes through the channel without any real processing.private Http2Pingprivate InternalChannelz.Securityprivate final com.google.common.base.Supplier<com.google.common.base.Stopwatch> private final io.netty.handler.codec.http2.Http2Connection.PropertyKeyprivate final TransportTracerprivate static final longFields inherited from class GrpcHttp2ConnectionHandler
ADAPTIVE_CUMULATOR, ADAPTIVE_CUMULATOR_COMPOSE_MIN_SIZE_DEFAULT, channelUnusedFields inherited from class io.netty.handler.codec.ByteToMessageDecoder
COMPOSITE_CUMULATOR, MERGE_CUMULATOR -
Constructor Summary
ConstructorsModifierConstructorDescriptionprivateNettyClientHandler(io.netty.handler.codec.http2.Http2ConnectionDecoder decoder, io.netty.handler.codec.http2.Http2ConnectionEncoder encoder, io.netty.handler.codec.http2.Http2Settings settings, ChannelLogger negotiationLogger, ClientTransportLifecycleManager lifecycleManager, KeepAliveManager keepAliveManager, com.google.common.base.Supplier<com.google.common.base.Stopwatch> stopwatchFactory, Runnable tooManyPingsRunnable, TransportTracer transportTracer, Attributes eagAttributes, String authority, boolean autoFlowControl, AbstractNettyHandler.PingLimiter pingLimiter, com.google.common.base.Ticker ticker) -
Method Summary
Modifier and TypeMethodDescriptionprivate voidprivate voidcancelStream(io.netty.channel.ChannelHandlerContext ctx, CancelClientStreamCommand cmd, io.netty.channel.ChannelPromise promise) Cancels this stream.voidchannelInactive(io.netty.channel.ChannelHandlerContext ctx) Handler for the Channel shutting down.private NettyClientStream.TransportStateclientStream(io.netty.handler.codec.http2.Http2Stream stream) Gets the client stream associated to the given HTTP/2 stream object.voidclose(io.netty.channel.ChannelHandlerContext ctx, io.netty.channel.ChannelPromise promise) private voidcreateStream(CreateStreamCommand command, io.netty.channel.ChannelPromise promise) Attempts to create a new stream from the given command.private voidcreateStreamTraced(int streamId, NettyClientStream.TransportState stream, io.netty.handler.codec.http2.Http2Headers headers, boolean isGet, boolean shouldBeCountedForInUse, io.netty.channel.ChannelPromise promise) private voidforcefulClose(io.netty.channel.ChannelHandlerContext ctx, ForcefulCloseCommand msg, io.netty.channel.ChannelPromise promise) (package private) AttributesThe protocol negotiation attributes, available once the protocol negotiation completes; otherwise returnsAttributes.EMPTY.Returns the authority of the server.Get the attributes of the EquivalentAddressGroup used to create this transport.(package private) ClientTransportLifecycleManager(package private) InternalChannelz.Security(package private) WriteQueueprivate voidgoingAway(long errorCode, byte[] debugData) Handler for a GOAWAY being received.private voidgracefulClose(io.netty.channel.ChannelHandlerContext ctx, GracefulCloseCommand msg, io.netty.channel.ChannelPromise promise) voidhandleProtocolNegotiationCompleted(Attributes attributes, InternalChannelz.Security securityInfo) Triggered on protocol negotiation completion.private intprotected boolean(package private) static NettyClientHandlernewHandler(ClientTransportLifecycleManager lifecycleManager, KeepAliveManager keepAliveManager, boolean autoFlowControl, int flowControlWindow, int maxHeaderListSize, com.google.common.base.Supplier<com.google.common.base.Stopwatch> stopwatchFactory, Runnable tooManyPingsRunnable, TransportTracer transportTracer, Attributes eagAttributes, String authority, ChannelLogger negotiationLogger, com.google.common.base.Ticker ticker) (package private) static NettyClientHandlernewHandler(io.netty.handler.codec.http2.Http2Connection connection, io.netty.handler.codec.http2.Http2FrameReader frameReader, io.netty.handler.codec.http2.Http2FrameWriter frameWriter, ClientTransportLifecycleManager lifecycleManager, KeepAliveManager keepAliveManager, boolean autoFlowControl, int flowControlWindow, int maxHeaderListSize, com.google.common.base.Supplier<com.google.common.base.Stopwatch> stopwatchFactory, Runnable tooManyPingsRunnable, TransportTracer transportTracer, Attributes eagAttributes, String authority, ChannelLogger negotiationLogger, com.google.common.base.Ticker ticker) 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) Handler for an inbound HTTP/2 DATA frame.private voidonHeadersRead(int streamId, io.netty.handler.codec.http2.Http2Headers headers, boolean endStream) private voidonRstStreamRead(int streamId, long errorCode) Handler for an inbound HTTP/2 RST_STREAM frame, terminating a stream.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) (package private) voidreturnProcessedBytes(io.netty.handler.codec.http2.Http2Stream stream, 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 for the stream.private voidsendPingFrame(io.netty.channel.ChannelHandlerContext ctx, SendPingCommand msg, io.netty.channel.ChannelPromise promise) private voidsendPingFrameTraced(io.netty.channel.ChannelHandlerContext ctx, SendPingCommand msg, io.netty.channel.ChannelPromise promise) Sends a PING frame.(package private) voidstartWriteQueue(io.netty.channel.Channel channel) private StatusstatusFromH2Error(Status.Code statusCode, String context, long errorCode, byte[] debugData) IfstatusCodeis non-null, it will be used instead of the http2 error code mapping.voidwrite(io.netty.channel.ChannelHandlerContext ctx, Object msg, io.netty.channel.ChannelPromise promise) Handler for commands sent from the stream.(package private) static voidwriteBufferingAndRemove(io.netty.channel.Channel channel) Methods inherited from class AbstractNettyHandler
channelActive, ctx, exceptionCaught, flowControlPing, handlerAdded, setAutoTuneFlowControlMethods inherited from class GrpcHttp2ConnectionHandler
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, 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 Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface io.netty.channel.ChannelHandler
handlerRemoved
-
Field Details
-
logger
-
NOOP_MESSAGE
A message that simply passes through the channel without any real processing. It is useful to check if buffers have been drained and test the health of the channel in a single operation. -
EXHAUSTED_STREAMS_STATUS
Status used when the transport has exhausted the number of streams. -
USER_PING_PAYLOAD
private static final long USER_PING_PAYLOAD- See Also:
-
streamKey
private final io.netty.handler.codec.http2.Http2Connection.PropertyKey streamKey -
lifecycleManager
-
keepAliveManager
-
stopwatchFactory
private final com.google.common.base.Supplier<com.google.common.base.Stopwatch> stopwatchFactory -
transportTracer
-
eagAttributes
-
authority
-
inUseState
-
clientWriteQueue
-
ping
-
attributes
-
securityInfo
-
abruptGoAwayStatus
-
channelInactiveReason
-
-
Constructor Details
-
NettyClientHandler
private NettyClientHandler(io.netty.handler.codec.http2.Http2ConnectionDecoder decoder, io.netty.handler.codec.http2.Http2ConnectionEncoder encoder, io.netty.handler.codec.http2.Http2Settings settings, ChannelLogger negotiationLogger, ClientTransportLifecycleManager lifecycleManager, KeepAliveManager keepAliveManager, com.google.common.base.Supplier<com.google.common.base.Stopwatch> stopwatchFactory, Runnable tooManyPingsRunnable, TransportTracer transportTracer, Attributes eagAttributes, String authority, boolean autoFlowControl, AbstractNettyHandler.PingLimiter pingLimiter, com.google.common.base.Ticker ticker)
-
-
Method Details
-
newHandler
static NettyClientHandler newHandler(ClientTransportLifecycleManager lifecycleManager, @Nullable KeepAliveManager keepAliveManager, boolean autoFlowControl, int flowControlWindow, int maxHeaderListSize, com.google.common.base.Supplier<com.google.common.base.Stopwatch> stopwatchFactory, Runnable tooManyPingsRunnable, TransportTracer transportTracer, Attributes eagAttributes, String authority, ChannelLogger negotiationLogger, com.google.common.base.Ticker ticker) -
newHandler
static NettyClientHandler newHandler(io.netty.handler.codec.http2.Http2Connection connection, io.netty.handler.codec.http2.Http2FrameReader frameReader, io.netty.handler.codec.http2.Http2FrameWriter frameWriter, ClientTransportLifecycleManager lifecycleManager, KeepAliveManager keepAliveManager, boolean autoFlowControl, int flowControlWindow, int maxHeaderListSize, com.google.common.base.Supplier<com.google.common.base.Stopwatch> stopwatchFactory, Runnable tooManyPingsRunnable, TransportTracer transportTracer, Attributes eagAttributes, String authority, ChannelLogger negotiationLogger, com.google.common.base.Ticker ticker) -
getAttributes
Attributes getAttributes()The protocol negotiation attributes, available once the protocol negotiation completes; otherwise returnsAttributes.EMPTY. -
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
-
startWriteQueue
void startWriteQueue(io.netty.channel.Channel channel) -
getWriteQueue
WriteQueue getWriteQueue() -
getLifecycleManager
ClientTransportLifecycleManager getLifecycleManager() -
returnProcessedBytes
void returnProcessedBytes(io.netty.handler.codec.http2.Http2Stream stream, int bytes) Returns the given processed bytes back to inbound flow control. -
onHeadersRead
private void onHeadersRead(int streamId, io.netty.handler.codec.http2.Http2Headers headers, boolean endStream) -
onDataRead
private void onDataRead(int streamId, io.netty.buffer.ByteBuf data, int padding, boolean endOfStream) Handler for an inbound HTTP/2 DATA frame. -
onRstStreamRead
private void onRstStreamRead(int streamId, long errorCode) Handler for an inbound HTTP/2 RST_STREAM frame, terminating a stream. -
close
-
channelInactive
Handler for the Channel shutting down.- Specified by:
channelInactivein interfaceio.netty.channel.ChannelInboundHandler- Overrides:
channelInactivein classio.netty.handler.codec.http2.Http2ConnectionHandler- Throws:
Exception
-
handleProtocolNegotiationCompleted
public void handleProtocolNegotiationCompleted(Attributes attributes, 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:
attributes- arbitrary attributes passed after protocol negotiation (eg. SSLSession).securityInfo- informs channelz about the security protocol.
-
writeBufferingAndRemove
static void writeBufferingAndRemove(io.netty.channel.Channel channel) -
getEagAttributes
Description copied from class:GrpcHttp2ConnectionHandlerGet the attributes of the EquivalentAddressGroup used to create this transport.- Overrides:
getEagAttributesin classGrpcHttp2ConnectionHandler
-
getAuthority
Description copied from class:GrpcHttp2ConnectionHandlerReturns the authority of the server. Only available on the client-side.- Overrides:
getAuthorityin classGrpcHttp2ConnectionHandler
-
getSecurityInfo
InternalChannelz.Security getSecurityInfo() -
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
-
isGracefulShutdownComplete
protected boolean isGracefulShutdownComplete()- Overrides:
isGracefulShutdownCompletein classio.netty.handler.codec.http2.Http2ConnectionHandler
-
createStream
private void createStream(CreateStreamCommand command, io.netty.channel.ChannelPromise promise) throws Exception Attempts to create a new stream from the given command. If there are too many active streams, the creation request is queued.- Throws:
Exception
-
createStreamTraced
private void createStreamTraced(int streamId, NettyClientStream.TransportState stream, io.netty.handler.codec.http2.Http2Headers headers, boolean isGet, boolean shouldBeCountedForInUse, io.netty.channel.ChannelPromise promise) -
cancelStream
private void cancelStream(io.netty.channel.ChannelHandlerContext ctx, CancelClientStreamCommand cmd, io.netty.channel.ChannelPromise promise) Cancels this stream. -
sendGrpcFrame
private void sendGrpcFrame(io.netty.channel.ChannelHandlerContext ctx, SendGrpcFrameCommand cmd, io.netty.channel.ChannelPromise promise) Sends the given GRPC frame for the stream. -
sendPingFrame
private void sendPingFrame(io.netty.channel.ChannelHandlerContext ctx, SendPingCommand msg, io.netty.channel.ChannelPromise promise) -
sendPingFrameTraced
private void sendPingFrameTraced(io.netty.channel.ChannelHandlerContext ctx, SendPingCommand msg, io.netty.channel.ChannelPromise promise) Sends a PING frame. If a ping operation is already outstanding, the callback in the message is registered to be called when the existing operation completes, and no new frame is sent. -
gracefulClose
private void gracefulClose(io.netty.channel.ChannelHandlerContext ctx, GracefulCloseCommand 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
-
goingAway
private void goingAway(long errorCode, byte[] debugData) Handler for a GOAWAY being received. Fails any streams created after the last known stream. May only be called during a read. -
cancelPing
-
statusFromH2Error
private Status statusFromH2Error(Status.Code statusCode, String context, long errorCode, byte[] debugData) IfstatusCodeis non-null, it will be used instead of the http2 error code mapping. -
clientStream
private NettyClientStream.TransportState clientStream(io.netty.handler.codec.http2.Http2Stream stream) Gets the client stream associated to the given HTTP/2 stream object. -
incrementAndGetNextStreamId
- Throws:
StatusException
-
requireHttp2Stream
private io.netty.handler.codec.http2.Http2Stream requireHttp2Stream(int streamId)
-