/** * start a state tracker to check whether this peer is enabled or not * * @param zookeeper zk watcher for the local cluster * @param peerStateNode path to zk node which stores peer state * @throws KeeperException */ public void startStateTracker(ZooKeeperWatcher zookeeper, String peerStateNode) throws KeeperException { if (ZKUtil.checkExists(zookeeper, peerStateNode) == -1) { // There is a race b/w PeerWatcher and ReplicationZookeeper#add method to create the // peer-state znode. This happens while adding a peer. // The peer state data is set as "ENABLED" by default. ZKUtil.createNodeIfNotExistsAndWatch(zookeeper, peerStateNode, Bytes.toBytes(PeerState.ENABLED.name())); } this.peerStateTracker = new PeerStateTracker(peerStateNode, zookeeper, this); this.peerStateTracker.start(); this.readPeerStateZnode(); }
private void readPeerStateZnode() { String currentState = Bytes.toString(peerStateTracker.getData(false)); this.peerEnabled.set(PeerState.ENABLED.equals(PeerState .valueOf(currentState))); }