Search in sources :

Example 1 with ObserverBean

use of org.apache.zookeeper.server.ObserverBean in project zookeeper by apache.

the class Observer method observeLeader.

/**
 * the main method called by the observer to observe the leader
 * @throws Exception
 */
void observeLeader() throws Exception {
    zk.registerJMX(new ObserverBean(this, zk), self.jmxLocalPeerBean);
    try {
        QuorumServer leaderServer = findLeader();
        LOG.info("Observing " + leaderServer.addr);
        try {
            connectToLeader(leaderServer.addr, leaderServer.hostname);
            long newLeaderZxid = registerWithLeader(Leader.OBSERVERINFO);
            if (self.isReconfigStateChange())
                throw new Exception("learned about role change");
            syncWithLeader(newLeaderZxid);
            QuorumPacket qp = new QuorumPacket();
            while (this.isRunning()) {
                readPacket(qp);
                processPacket(qp);
            }
        } catch (Exception e) {
            LOG.warn("Exception when observing the leader", e);
            try {
                sock.close();
            } catch (IOException e1) {
                e1.printStackTrace();
            }
            // clear pending revalidations
            pendingRevalidations.clear();
        }
    } finally {
        zk.unregisterJMX(this);
    }
}
Also used : ObserverBean(org.apache.zookeeper.server.ObserverBean) QuorumServer(org.apache.zookeeper.server.quorum.QuorumPeer.QuorumServer) IOException(java.io.IOException) IOException(java.io.IOException)

Aggregations

IOException (java.io.IOException)1 ObserverBean (org.apache.zookeeper.server.ObserverBean)1 QuorumServer (org.apache.zookeeper.server.quorum.QuorumPeer.QuorumServer)1