@Override
    public void process(WatchedEvent event) {
      super.process(event);
      if (event.getType().equals(Watcher.Event.EventType.NodeDeleted)) {
        // If there are no more active client sessions, stop the server
        if (cliService.getSessionManager().getOpenSessionCount() == 0) {
          LOG.warn("This instance of HiveServer2 has been removed from the list of server "
                  + "instances available for dynamic service discovery. "
                  + "The last client session has ended - will shutdown now.");
          HiveServer2.this.stop();
        }
      }
    }
The watcher class shuts down the server if there are no more active client
sessions at the time of receiving a 'NodeDeleted' notification from ZooKeeper.
service/src/java/org/apache/hive/service/server/HiveServer2.java