code: protected void addShutdownHook() {
        Runtime.getRuntime().addShutdownHook(
          new Thread() {
              @Override
              public void run() {
                  LOG.info("Cleaning up ephemeral ZooKeeper state");
                  completeShutdown();
              }
          });
      }
docs: registers a shutdown hook which causes cleanup of ephemeral state in zookeeper
  when the JVM exits normally (via Ctrl+C or SIGTERM for example)
  
  this alerts other applications which have discovered this instance that it is
  down so they may avoid re-submitting requests. otherwise this will not happen until
  the default zookeeper timeout of 10s during which requests will fail until
  the application is up and accepting requests again