private void handleMasterNodeChange() {
    // Watch the node and check if it exists.
    try {
      synchronized (clusterHasActiveMaster) {
        if (ZKUtil.watchAndCheckExists(watcher, watcher.getZNodePaths().masterAddressZNode)) {
          // A master node exists, there is an active master
          LOG.trace("A master is now available");
          clusterHasActiveMaster.set(true);
        } else {
          // Node is no longer there, cluster does not have an active master
          LOG.debug("No master available. Notifying waiting threads");
          clusterHasActiveMaster.set(false);
          // Notify any thread waiting to become the active master
          clusterHasActiveMaster.notifyAll();
        }
        // Reset the active master sn. Will be re-fetched later if needed.
        // We don't want to make a synchronous RPC under a monitor.
        activeMasterServerName = null;
      }
    } catch (KeeperException ke) {
      master.abort("Received an unexpected KeeperException, aborting", ke);
    }
  }
Handle a change in the master node. Doesn't matter whether this was called from a nodeCreated
or nodeDeleted event because there are no guarantees that the current state of the master node
matches the event at the time of our next ZK request.
<p>
Uses the watchAndCheckExists method which watches the master address node regardless of whether
it exists or not. If it does exist (there is an active master), it returns true. Otherwise it
returns false.
<p>
A watcher is set which guarantees that this method will get called again if there is another
change in the master node.
hbase-server/src/main/java/org/apache/hadoop/hbase/master/ActiveMasterManager.java