private void registerReader(ChannelHandlerContext ctx, String id, byte[] tokenBytes) {
      if (sm != null) {
        try {
          sm.verifyToken(tokenBytes);
        } catch (SecurityException | IOException ex) {
          failChannel(ctx, id, ex.getMessage());
          return;
        }
      }
      LOG.debug("registering socket for: " + id);
      int maxPendingWrites = HiveConf.getIntVar(conf,
          HiveConf.ConfVars.LLAP_DAEMON_OUTPUT_SERVICE_MAX_PENDING_WRITES);
      @SuppressWarnings("rawtypes")
      RecordWriter writer = new LlapRecordWriter(id,
          new ChunkedOutputStream(
              new ChannelOutputStream(ctx, id, sendBufferSize, maxPendingWrites), sendBufferSize, id));
      boolean isFailed = true;
      synchronized (lock) {
        if (!writers.containsKey(id)) {
          isFailed = false;
          writers.put(id, writer);
          // Add listener to handle any cleanup for when the connection is closed
          ctx.channel().closeFuture().addListener(new LlapOutputFormatChannelCloseListener(id));
          lock.notifyAll();
        }
      }
      if (isFailed) {
        failChannel(ctx, id, "Writer already registered for " + id);
      }
    }
Responsible for sending back result set data to the connections
made by external clients via the LLAP input format.
ql/src/java/org/apache/hadoop/hive/llap/LlapOutputFormatService.java