/**
  * A private method used to re-establish a zookeeper session with a peer cluster.
  *
  * @param ke
  * @param peer
  */
 private void reconnectPeer(KeeperException ke, ReplicationPeer peer) {
   if (ke instanceof ConnectionLossException
       || ke instanceof SessionExpiredException
       || ke instanceof AuthFailedException) {
     LOG.warn("Lost the ZooKeeper connection for peer " + peer.getClusterKey(), ke);
     try {
       peer.reloadZkWatcher();
       peer.getZkw().registerListener(new PeerRegionServerListener(peer));
     } catch (IOException io) {
       LOG.warn("Creation of ZookeeperWatcher failed for peer " + peer.getClusterKey(), io);
     }
   }
 }
 /**
  * This method connects this cluster to another one and registers it in this region server's
  * replication znode
  *
  * @param peerId id of the peer cluster
  */
 public boolean connectToPeer(String peerId) throws IOException {
   if (this.clientOnly) {
     return false;
   }
   if (this.peerClusters.containsKey(peerId)) {
     return false;
     // TODO remove when we support it
   } else if (this.peerClusters.size() > 0) {
     LOG.warn("Multiple slaves feature not supported");
     return false;
   }
   ReplicationPeer peer = getPeer(peerId);
   if (peer == null) {
     return false;
   }
   this.peerClusters.put(peerId, peer);
   this.zookeeperWrapper.ensureExists(
       this.zookeeperWrapper.getZNode(this.rsServerNameZnode, peerId));
   LOG.info("Added new peer cluster " + peer.getClusterKey());
   return true;
 }
 @Override
 public boolean connectToPeer(String peerId) throws ReplicationException {
   if (peerClusters == null) {
     return false;
   }
   if (this.peerClusters.containsKey(peerId)) {
     return false;
   }
   ReplicationPeer peer = null;
   try {
     peer = getPeer(peerId);
   } catch (Exception e) {
     throw new ReplicationException("Error connecting to peer with id=" + peerId, e);
   }
   if (peer == null) {
     return false;
   }
   this.peerClusters.put(peerId, peer);
   LOG.info("Added new peer cluster " + peer.getClusterKey());
   return true;
 }