private void startListeningForQueries() {
    PathChildrenCacheListener listener = (client, pathChildrenCacheEvent) -> {
      if (pathChildrenCacheEvent.getType() == PathChildrenCacheEvent.Type.CHILD_ADDED) {
        KillQueryZookeeperBarrier barrier = new KillQueryZookeeperBarrier(zooKeeperClient, "/" + zkNameSpace,
            ZKPaths.getNodeFromPath(pathChildrenCacheEvent.getData().getPath()));
        Optional<KillQueryZookeeperData> data = barrier.getKillQueryData();
        if (!data.isPresent()) {
          return;
        }
        KillQueryZookeeperData killQuery = data.get();
        LOG.debug("Kill query request with id {}", killQuery.getQueryId());
        if (getServerHost().equals(killQuery.getRequestingServer())) {
          // The listener was called for the server who posted the request
          return;
        }
        if (localKillQueryImpl.isLocalQuery(killQuery.getQueryId())) {
          LOG.info("Killing query with id {}", killQuery.getQueryId());
          barrier.confirmProgress(getServerHost());
          try {
            localKillQueryImpl
                .killLocalQuery(killQuery.getQueryId(), conf, killQuery.getDoAs(), killQuery.isDoAsAdmin());
            barrier.confirmDone(getServerHost());
          } catch (Exception e) {
            LOG.error("Unable to kill local query", e);
            barrier.confirmFailed(getServerHost());
          }
        } else {
          LOG.debug("Confirm unknown kill query request with id {}", killQuery.getQueryId());
          barrier.confirmNo(getServerHost());
        }
      }
    };
    LOG.info("Start to listen for kill query requests.");
    killQueryListener.getListenable().addListener(listener);
  }
Kill query coordination service.
When service discovery is enabled a local kill query can request a kill
on every other HS2 server with the queryId or queryTag and wait for confirmation on denial.
The communication is done through Zookeeper.
service/src/java/org/apache/hive/service/server/KillQueryZookeeperManager.java