Package io.grpc.netty

Class 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 Classes 
      Modifier and Type Class Description
      private static class  WriteBufferingAndExceptionHandler.ChannelWrite  
      • Nested classes/interfaces inherited from interface io.netty.channel.ChannelHandler

        io.netty.channel.ChannelHandler.Sharable
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void 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, java.lang.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, java.net.SocketAddress remoteAddress, java.net.SocketAddress localAddress, io.netty.channel.ChannelPromise promise)
      void exceptionCaught​(io.netty.channel.ChannelHandlerContext ctx, java.lang.Throwable cause)  
      private void failWrites​(java.lang.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, java.lang.Object msg, io.netty.channel.ChannelPromise promise)
      Buffers the write until either writeBufferedAndRemove(ChannelHandlerContext) is called, or we have somehow failed.
      (package private) 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
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • logger

        private static final java.util.logging.Logger logger
      • next

        private final io.netty.channel.ChannelHandler next
      • writing

        private boolean writing
      • flushRequested

        private boolean flushRequested
      • failCause

        private java.lang.Throwable failCause
    • Constructor Detail

      • WriteBufferingAndExceptionHandler

        WriteBufferingAndExceptionHandler​(io.netty.channel.ChannelHandler next)
    • Method Detail

      • handlerAdded

        public void handlerAdded​(io.netty.channel.ChannelHandlerContext ctx)
                          throws java.lang.Exception
        Specified by:
        handlerAdded in interface io.netty.channel.ChannelHandler
        Overrides:
        handlerAdded in class io.netty.channel.ChannelHandlerAdapter
        Throws:
        java.lang.Exception
      • handlerRemoved

        public void handlerRemoved​(io.netty.channel.ChannelHandlerContext ctx)
                            throws java.lang.Exception
        Specified by:
        handlerRemoved in interface io.netty.channel.ChannelHandler
        Overrides:
        handlerRemoved in class io.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:
        channelInactive in interface io.netty.channel.ChannelInboundHandler
        Overrides:
        channelInactive in class io.netty.channel.ChannelInboundHandlerAdapter
      • exceptionCaught

        public void exceptionCaught​(io.netty.channel.ChannelHandlerContext ctx,
                                    java.lang.Throwable cause)
        Specified by:
        exceptionCaught in interface io.netty.channel.ChannelHandler
        Specified by:
        exceptionCaught in interface io.netty.channel.ChannelInboundHandler
        Overrides:
        exceptionCaught in class io.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 either writeBufferedAndRemove(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 interface io.netty.channel.ChannelOutboundHandler
        Overrides:
        write in class io.netty.channel.ChannelDuplexHandler
      • channelRead

        public void channelRead​(io.netty.channel.ChannelHandlerContext ctx,
                                java.lang.Object msg)
        Specified by:
        channelRead in interface io.netty.channel.ChannelInboundHandler
        Overrides:
        channelRead in class io.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 until writeBufferedAndRemove(ChannelHandlerContext).
        Specified by:
        flush in interface io.netty.channel.ChannelOutboundHandler
        Overrides:
        flush in class io.netty.channel.ChannelDuplexHandler
      • close

        public void close​(io.netty.channel.ChannelHandlerContext ctx,
                          io.netty.channel.ChannelPromise future)
                   throws java.lang.Exception
        If we are still performing protocol negotiation, then this will propagate failures to all buffered writes.
        Specified by:
        close in interface io.netty.channel.ChannelOutboundHandler
        Overrides:
        close in class io.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.