@Override
  public void channelRead(ChannelHandlerContext ctx, Object obj) throws Exception {
    logger.trace("Reading on channel {}", ctx.channel());
    boolean forwardObj = false;
    if (obj instanceof HttpRequest) {
      if (request == null && ((HttpRequest) obj).uri().equals(healthCheckUri)) {
        nettyMetrics.healthCheckRequestRate.mark();
        startTimeInMs = System.currentTimeMillis();
        logger.trace("Handling health check request while in state {}", restServerState.isServiceUp());
        request = (HttpRequest) obj;
        if (restServerState.isServiceUp()) {
          response =
              new DefaultFullHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.OK, Unpooled.wrappedBuffer(GOOD));
          HttpUtil.setKeepAlive(response, HttpUtil.isKeepAlive(request));
          HttpUtil.setContentLength(response, GOOD.length);
        } else {
          response = new DefaultFullHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.SERVICE_UNAVAILABLE,
              Unpooled.wrappedBuffer(BAD));
          HttpUtil.setKeepAlive(response, false);
          HttpUtil.setContentLength(response, BAD.length);
        }
        nettyMetrics.healthCheckRequestProcessingTimeInMs.update(System.currentTimeMillis() - startTimeInMs);
      } else {
        // Rest server could be down even if not for health check request. We intentionally don't take any action in this
        // handler for such cases and leave it to the downstream handlers to handle it
        forwardObj = true;
      }
    }
    if (obj instanceof LastHttpContent) {
      if (response != null) {
        // response was created when we received the request with health check uri
        ChannelFuture future = ctx.writeAndFlush(response);
        if (!HttpUtil.isKeepAlive(response)) {
          future.addListener(ChannelFutureListener.CLOSE);
        }
        request = null;
        response = null;
        nettyMetrics.healthCheckRequestRoundTripTimeInMs.update(System.currentTimeMillis() - startTimeInMs);
      } else {
        // request was not for health check uri
        forwardObj = true;
      }
    } else if (request == null) {
      // http Content which is not LastHttpContent is not intended for this handler
      forwardObj = true;
    }
    if (forwardObj) {
      super.channelRead(ctx, obj);
    } else {
      ReferenceCountUtil.release(obj);
    }
  }
Responsible for responding to health check requests
{@link RestServerState} assists in knowing the state of the system at any point in time
ambry-rest/src/main/java/com/github/ambry/rest/HealthCheckHandler.java