Mercurial > hg > Database > Christie
view src/main/java/christie/test/topology/paxos/StartLocalPaxos.java @ 166:f2218b5590d3
add CheckMyName
author | akahori |
---|---|
date | Tue, 22 Jan 2019 15:07:12 +0900 |
parents | c6250ad544e0 |
children | dd3c0ba6a0a6 |
line wrap: on
line source
package christie.test.topology.paxos; import christie.codegear.CodeGearManager; import christie.codegear.StartCodeGear; import christie.test.topology.paxos.acceptor.AcceptorCodeGear; import christie.test.topology.paxos.learner.LearnerCodeGear; import christie.test.topology.paxos.proposer.ProposerCodeGear; import christie.topology.TopologyDataGear; import java.util.ArrayList; import java.util.List; public class StartLocalPaxos extends StartCodeGear{ public StartLocalPaxos(CodeGearManager cgm) { super(cgm); } public static void main(String args[]){ int proposerPort = 10000; int proposersNum = 2; int acceptorPort = proposerPort + proposersNum; int acceptorsNum = 3; int learnerPort = acceptorPort + acceptorsNum; int learnersNum = 1; List<CodeGearManager> proposers = new ArrayList<>(proposersNum); List<CodeGearManager> acceptors = new ArrayList<>(acceptorsNum); List<CodeGearManager> learners = new ArrayList<>(learnersNum); TopologyDataGear proposerTopoDG = new TopologyDataGear(); TopologyDataGear acceptorTopoDG = new TopologyDataGear(); for(int i = 0; i < learnersNum; i++){ String nodeName = "learner" + i; acceptorTopoDG.addConnection(nodeName); TopologyDataGear topoDG = new TopologyDataGear(); CodeGearManager learner = createCGM(learnerPort + i); topoDG.setNodeName(nodeName); learner.getLocalDGM().put("topoDG", topoDG); learner.setup(new CheckMyName()); learners.add(learner); } for(int i = 0; i < acceptorsNum; i++){ String nodeName = "acceptor" + i; proposerTopoDG.addConnection(nodeName); CodeGearManager acceptor = createCGM(acceptorPort + i); TopologyDataGear topoDG = acceptorTopoDG.clone(); topoDG.setNodeName(nodeName); acceptor.getLocalDGM().put("topoDG", topoDG); acceptor.setup(new CheckMyName()); acceptors.add(acceptor); } for(int i = 0; i < proposersNum; i++){ String nodeName = "proposer" + i; CodeGearManager proposer = createCGM(proposerPort + i); TopologyDataGear topoDG = proposerTopoDG.clone(); topoDG.setNodeName(nodeName); topoDG.setTotalNodeNum(proposersNum); proposer.getLocalDGM().put("topoDG", topoDG); proposers.add(proposer); } for(int i = 0; i < proposersNum; i++){ for(int j = 0; j < acceptorsNum; j++){ proposers.get(i).createRemoteDGM(proposerTopoDG.getConnectionList().get(j), "localhost", acceptors.get(j).localPort); acceptors.get(j).createRemoteDGM("proposer" + i, "localhost", proposers.get(i).localPort); } proposers.get(i).setup(new CheckMyName()); } for(int i = 0; i < acceptorsNum; i++){ for(int j = 0; j < learnersNum; j++){ acceptors.get(i).createRemoteDGM(acceptorTopoDG.getConnectionList().get(j), "localhost", learners.get(j).localPort); learners.get(j).createRemoteDGM(proposerTopoDG.getConnectionList().get(j), "localhost", acceptors.get(i).localPort); } } } }