Source code analysis of leader election-quorumPeer.createElectionAlgorithm

Create an election algorithm based on the corresponding logo

protected Election createElectionAlgorithm(int electionAlgorithm){ 
	Election le=null; 
	//TODO: use a factory rather than a switch 
	switch (electionAlgorithm) { 
		case 0: 
		le = new LeaderElection(this); 
		break; 
		case 1: 
		le = new AuthFastLeaderElection(this); 
		break; 
		case 2: 
		le = new AuthFastLeaderElection(this, true); 
		break; 
		case 3: 
		qcm = createCnxnManager(); 
		QuorumCnxManager.Listener listener = 
		qcm.listener; 
		if(listener != null){ 
			listener.start(); //启动监听器,这个监听具体做什么的暂时不管,后面遇到需要了解的地方再回过头来看 
			le = new FastLeaderElection(this, qcm);//初始化FastLeaderElection 
		} else { 
			LOG.error("Null listener when 
			initializing cnx manager"); 
		} 
		break; 
		default: 
		assert false; 
	} 
	return le; 
}

 

Guess you like

Origin blog.csdn.net/Leon_Jinhai_Sun/article/details/112971786