@Override
    public void processResult(int rc, String path, Object ctx) {
      switch (KeeperException.Code.get(rc)) {
        case CONNECTIONLOSS:
          // Connectionloss while deleting task, deleting again
          recreateZKConnection();
          deleteTask(path);
          break;

        case OK:
          LOG.info("Task Deleted successfully!");
          LOG.info("Closing ZooKeeper Connection");
          try {
            zk.close();
          } catch (InterruptedException e) {
            LOG.error("Error while closing ZooKeeper Connection.");
          }
          break;

        default:
          LOG.error("ERROR while deleting task: " + path + " ERROR: "
            + KeeperException.create(KeeperException.Code.get(rc)));
      }
    }
Watcher to get notification whenever status of task changes.
hbase-it/src/test/java/org/apache/hadoop/hbase/ChaosZKClient.java