Class FastLeaderElection

  extended by org.apache.zookeeper.server.quorum.FastLeaderElection
All Implemented Interfaces:

public class FastLeaderElection
extends Object
implements Election

Implementation of leader election using TCP. It uses an object of the class QuorumCnxManager to manage connections. Otherwise, the algorithm is push-based as with the other UDP implementations. There are a few parameters that can be tuned to change its behavior. First, finalizeWait determines the amount of time to wait until deciding upon a leader. This is part of the leader election algorithm.

Nested Class Summary
static class FastLeaderElection.Notification
          Notifications are messages that let other peers know that a given peer has changed its vote, either because it has joined leader election or because it learned of another peer with higher zxid or same zxid and higher server id
static class FastLeaderElection.ToSend
          Messages that a peer wants to send to other peers.
Constructor Summary
FastLeaderElection(QuorumPeer self, QuorumCnxManager manager)
          Constructor of FastLeaderElection.
Method Summary
 QuorumCnxManager getCnxManager()
 long getLogicalClock()
          Returns the current vlue of the logical clock counter
 Vote lookForLeader()
          Starts a new round of leader election.
 void shutdown()
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

Constructor Detail


public FastLeaderElection(QuorumPeer self,
                          QuorumCnxManager manager)
Constructor of FastLeaderElection. It takes two parameters, one is the QuorumPeer object that instantiated this object, and the other is the connection manager. Such an object should be created only once by each peer during an instance of the ZooKeeper service.

self - QuorumPeer that created this object
manager - Connection manager
Method Detail


public long getLogicalClock()
Returns the current vlue of the logical clock counter


public QuorumCnxManager getCnxManager()


public void shutdown()
Specified by:
shutdown in interface Election


public Vote lookForLeader()
                   throws InterruptedException
Starts a new round of leader election. Whenever our QuorumPeer changes its state to LOOKING, this method is invoked, and it sends notifications to all other peers.

Specified by:
lookForLeader in interface Election

Copyright © 2011 The Apache Software Foundation