@Override
 public void handlerAdded(ChannelHandlerContext ctx) throws Exception {
   // Initialize the encoder, decoder, flow controllers, and internal state.
   encoder.lifecycleManager(this);
   decoder.lifecycleManager(this);
   encoder.flowController().channelHandlerContext(ctx);
   decoder.flowController().channelHandlerContext(ctx);
   byteDecoder = new PrefaceDecoder(ctx);
 }
 @Override
 public void channelInactive(ChannelHandlerContext ctx) throws Exception {
   if (byteDecoder != null) {
     encoder.flowController().channelHandlerContext(null);
     decoder.flowController().channelHandlerContext(null);
     byteDecoder.channelInactive(ctx);
     super.channelInactive(ctx);
     byteDecoder = null;
   }
 }
 @Override
 public void flush(ChannelHandlerContext ctx) throws Http2Exception {
   // Trigger pending writes in the remote flow controller.
   encoder.flowController().writePendingBytes();
   try {
     super.flush(ctx);
   } catch (Throwable t) {
     throw new Http2Exception(INTERNAL_ERROR, "Error flushing", t);
   }
 }