Package io.grpc.netty
Class WriteBufferingAndExceptionHandler
java.lang.Object
io.netty.channel.ChannelHandlerAdapter
io.netty.channel.ChannelInboundHandlerAdapter
io.netty.channel.ChannelDuplexHandler
io.grpc.netty.WriteBufferingAndExceptionHandler
- All Implemented Interfaces:
io.netty.channel.ChannelHandler
,io.netty.channel.ChannelInboundHandler
,io.netty.channel.ChannelOutboundHandler
final class WriteBufferingAndExceptionHandler
extends io.netty.channel.ChannelDuplexHandler
Buffers all writes until either
writeBufferedAndRemove(ChannelHandlerContext)
or
failWrites(Throwable)
is called. This handler allows us to
write to a Channel
before we are allowed to write to it officially
i.e. before it's active or the TLS Handshake is complete.-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate static final class
Nested classes/interfaces inherited from interface io.netty.channel.ChannelHandler
io.netty.channel.ChannelHandler.Sharable
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final Queue
<WriteBufferingAndExceptionHandler.ChannelWrite> private Throwable
private boolean
private static final Logger
private final io.netty.channel.ChannelHandler
private boolean
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
channelInactive
(io.netty.channel.ChannelHandlerContext ctx) If this channel becomes inactive, then notify all buffered writes that we failed.void
channelRead
(io.netty.channel.ChannelHandlerContext ctx, Object msg) void
close
(io.netty.channel.ChannelHandlerContext ctx, io.netty.channel.ChannelPromise future) If we are still performing protocol negotiation, then this will propagate failures to all buffered writes.void
connect
(io.netty.channel.ChannelHandlerContext ctx, SocketAddress remoteAddress, SocketAddress localAddress, io.netty.channel.ChannelPromise promise) Connect failures do not show up aschannelInactive(io.netty.channel.ChannelHandlerContext)
orexceptionCaught(io.netty.channel.ChannelHandlerContext, java.lang.Throwable)
, so it needs to be watched.void
exceptionCaught
(io.netty.channel.ChannelHandlerContext ctx, Throwable cause) private void
failWrites
(Throwable cause) Propagate failures to all buffered writes.void
flush
(io.netty.channel.ChannelHandlerContext ctx) Calls to this method will not trigger an immediate flush.void
handlerAdded
(io.netty.channel.ChannelHandlerContext ctx) void
handlerRemoved
(io.netty.channel.ChannelHandlerContext ctx) void
write
(io.netty.channel.ChannelHandlerContext ctx, Object msg, io.netty.channel.ChannelPromise promise) Buffers the write until eitherwriteBufferedAndRemove(ChannelHandlerContext)
is called, or we have somehow failed.(package private) final void
writeBufferedAndRemove
(io.netty.channel.ChannelHandlerContext ctx) Methods inherited from class io.netty.channel.ChannelDuplexHandler
bind, deregister, disconnect, read
Methods inherited from class io.netty.channel.ChannelInboundHandlerAdapter
channelActive, channelReadComplete, channelRegistered, channelUnregistered, channelWritabilityChanged, userEventTriggered
Methods inherited from class io.netty.channel.ChannelHandlerAdapter
ensureNotSharable, isSharable
-
Field Details
-
logger
-
bufferedWrites
-
next
private final io.netty.channel.ChannelHandler next -
writing
private boolean writing -
flushRequested
private boolean flushRequested -
failCause
-
-
Constructor Details
-
WriteBufferingAndExceptionHandler
WriteBufferingAndExceptionHandler(io.netty.channel.ChannelHandler next)
-
-
Method Details
-
handlerAdded
- Specified by:
handlerAdded
in interfaceio.netty.channel.ChannelHandler
- Overrides:
handlerAdded
in classio.netty.channel.ChannelHandlerAdapter
- Throws:
Exception
-
handlerRemoved
- Specified by:
handlerRemoved
in interfaceio.netty.channel.ChannelHandler
- Overrides:
handlerRemoved
in classio.netty.channel.ChannelHandlerAdapter
- Throws:
Exception
-
channelInactive
public void channelInactive(io.netty.channel.ChannelHandlerContext ctx) If this channel becomes inactive, then notify all buffered writes that we failed.- Specified by:
channelInactive
in interfaceio.netty.channel.ChannelInboundHandler
- Overrides:
channelInactive
in classio.netty.channel.ChannelInboundHandlerAdapter
-
exceptionCaught
- Specified by:
exceptionCaught
in interfaceio.netty.channel.ChannelHandler
- Specified by:
exceptionCaught
in interfaceio.netty.channel.ChannelInboundHandler
- Overrides:
exceptionCaught
in classio.netty.channel.ChannelInboundHandlerAdapter
-
write
public void write(io.netty.channel.ChannelHandlerContext ctx, Object msg, io.netty.channel.ChannelPromise promise) Buffers the write until eitherwriteBufferedAndRemove(ChannelHandlerContext)
is called, or we have somehow failed. If we have already failed in the past, then the write will fail immediately.- Specified by:
write
in interfaceio.netty.channel.ChannelOutboundHandler
- Overrides:
write
in classio.netty.channel.ChannelDuplexHandler
-
connect
public void connect(io.netty.channel.ChannelHandlerContext ctx, SocketAddress remoteAddress, SocketAddress localAddress, io.netty.channel.ChannelPromise promise) throws Exception Connect failures do not show up aschannelInactive(io.netty.channel.ChannelHandlerContext)
orexceptionCaught(io.netty.channel.ChannelHandlerContext, java.lang.Throwable)
, so it needs to be watched.- Specified by:
connect
in interfaceio.netty.channel.ChannelOutboundHandler
- Overrides:
connect
in classio.netty.channel.ChannelDuplexHandler
- Throws:
Exception
-
channelRead
- Specified by:
channelRead
in interfaceio.netty.channel.ChannelInboundHandler
- Overrides:
channelRead
in classio.netty.channel.ChannelInboundHandlerAdapter
-
flush
public void flush(io.netty.channel.ChannelHandlerContext ctx) Calls to this method will not trigger an immediate flush. The flush will be deferred untilwriteBufferedAndRemove(ChannelHandlerContext)
.- Specified by:
flush
in interfaceio.netty.channel.ChannelOutboundHandler
- Overrides:
flush
in classio.netty.channel.ChannelDuplexHandler
-
close
public void close(io.netty.channel.ChannelHandlerContext ctx, io.netty.channel.ChannelPromise future) throws Exception If we are still performing protocol negotiation, then this will propagate failures to all buffered writes.- Specified by:
close
in interfaceio.netty.channel.ChannelOutboundHandler
- Overrides:
close
in classio.netty.channel.ChannelDuplexHandler
- Throws:
Exception
-
writeBufferedAndRemove
final void writeBufferedAndRemove(io.netty.channel.ChannelHandlerContext ctx) -
failWrites
Propagate failures to all buffered writes.
-