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.ChannelDuplexHandlerBuffers all writes until eitherwriteBufferedAndRemove(ChannelHandlerContext)orfailWrites(Throwable)is called. This handler allows us to write to aChannelbefore we are allowed to write to it officially i.e. before it's active or the TLS Handshake is complete.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private static classWriteBufferingAndExceptionHandler.ChannelWrite
-
Field Summary
Fields Modifier and Type Field Description private java.util.Queue<WriteBufferingAndExceptionHandler.ChannelWrite>bufferedWritesprivate java.lang.ThrowablefailCauseprivate booleanflushRequestedprivate static java.util.logging.Loggerloggerprivate io.netty.channel.ChannelHandlernextprivate booleanwriting
-
Constructor Summary
Constructors Constructor Description WriteBufferingAndExceptionHandler(io.netty.channel.ChannelHandler next)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidchannelInactive(io.netty.channel.ChannelHandlerContext ctx)If this channel becomes inactive, then notify all buffered writes that we failed.voidchannelRead(io.netty.channel.ChannelHandlerContext ctx, java.lang.Object msg)voidclose(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.voidconnect(io.netty.channel.ChannelHandlerContext ctx, java.net.SocketAddress remoteAddress, java.net.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.voidexceptionCaught(io.netty.channel.ChannelHandlerContext ctx, java.lang.Throwable cause)private voidfailWrites(java.lang.Throwable cause)Propagate failures to all buffered writes.voidflush(io.netty.channel.ChannelHandlerContext ctx)Calls to this method will not trigger an immediate flush.voidhandlerAdded(io.netty.channel.ChannelHandlerContext ctx)voidhandlerRemoved(io.netty.channel.ChannelHandlerContext ctx)voidwrite(io.netty.channel.ChannelHandlerContext ctx, java.lang.Object msg, io.netty.channel.ChannelPromise promise)Buffers the write until eitherwriteBufferedAndRemove(ChannelHandlerContext)is called, or we have somehow failed.(package private) voidwriteBufferedAndRemove(io.netty.channel.ChannelHandlerContext ctx)-
Methods inherited from class io.netty.channel.ChannelDuplexHandler
bind, deregister, disconnect, read
-
-
-
-
Field Detail
-
logger
private static final java.util.logging.Logger logger
-
bufferedWrites
private final java.util.Queue<WriteBufferingAndExceptionHandler.ChannelWrite> bufferedWrites
-
next
private final io.netty.channel.ChannelHandler next
-
writing
private boolean writing
-
flushRequested
private boolean flushRequested
-
failCause
private java.lang.Throwable failCause
-
-
Method Detail
-
handlerAdded
public void handlerAdded(io.netty.channel.ChannelHandlerContext ctx) throws java.lang.Exception- Specified by:
handlerAddedin interfaceio.netty.channel.ChannelHandler- Overrides:
handlerAddedin classio.netty.channel.ChannelHandlerAdapter- Throws:
java.lang.Exception
-
handlerRemoved
public void handlerRemoved(io.netty.channel.ChannelHandlerContext ctx) throws java.lang.Exception- Specified by:
handlerRemovedin interfaceio.netty.channel.ChannelHandler- Overrides:
handlerRemovedin classio.netty.channel.ChannelHandlerAdapter- Throws:
java.lang.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:
channelInactivein interfaceio.netty.channel.ChannelInboundHandler- Overrides:
channelInactivein classio.netty.channel.ChannelInboundHandlerAdapter
-
exceptionCaught
public void exceptionCaught(io.netty.channel.ChannelHandlerContext ctx, java.lang.Throwable cause)- Specified by:
exceptionCaughtin interfaceio.netty.channel.ChannelHandler- Specified by:
exceptionCaughtin interfaceio.netty.channel.ChannelInboundHandler- Overrides:
exceptionCaughtin classio.netty.channel.ChannelInboundHandlerAdapter
-
write
public void write(io.netty.channel.ChannelHandlerContext ctx, java.lang.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:
writein interfaceio.netty.channel.ChannelOutboundHandler- Overrides:
writein classio.netty.channel.ChannelDuplexHandler
-
connect
public void connect(io.netty.channel.ChannelHandlerContext ctx, java.net.SocketAddress remoteAddress, java.net.SocketAddress localAddress, io.netty.channel.ChannelPromise promise) throws java.lang.ExceptionConnect 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:
connectin interfaceio.netty.channel.ChannelOutboundHandler- Overrides:
connectin classio.netty.channel.ChannelDuplexHandler- Throws:
java.lang.Exception
-
channelRead
public void channelRead(io.netty.channel.ChannelHandlerContext ctx, java.lang.Object msg)- Specified by:
channelReadin interfaceio.netty.channel.ChannelInboundHandler- Overrides:
channelReadin 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:
flushin interfaceio.netty.channel.ChannelOutboundHandler- Overrides:
flushin classio.netty.channel.ChannelDuplexHandler
-
close
public void close(io.netty.channel.ChannelHandlerContext ctx, io.netty.channel.ChannelPromise future) throws java.lang.ExceptionIf we are still performing protocol negotiation, then this will propagate failures to all buffered writes.- Specified by:
closein interfaceio.netty.channel.ChannelOutboundHandler- Overrides:
closein classio.netty.channel.ChannelDuplexHandler- Throws:
java.lang.Exception
-
writeBufferedAndRemove
final void writeBufferedAndRemove(io.netty.channel.ChannelHandlerContext ctx)
-
failWrites
private void failWrites(java.lang.Throwable cause)
Propagate failures to all buffered writes.
-
-