Mercurial > hg > Database > Christie
view src/main/java/christie/test/topology/paxos/StartLocalPaxos.java @ 272:b592fe1d4a4e default tip
create example Attendance
author | matac42 <matac@cr.ie.u-ryukyu.ac.jp> |
---|---|
date | Thu, 01 Jul 2021 20:41:07 +0900 |
parents | 218ad6b9ba87 |
children |
line wrap: on
line source
package christie.test.topology.paxos; import christie.codegear.CodeGearManager; import christie.codegear.StartCodeGear; 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 learnersNum1){ int proposerPort = 10000; int proposersNum = 2; int acceptorPort = proposerPort + proposersNum; int acceptorsNum = 3; int learnerPort = acceptorPort + acceptorsNum; int learnersNum = learnersNum1; 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); } } } }