164
|
1 package christie.test.topology.paxos;
|
|
2
|
|
3 import christie.codegear.CodeGearManager;
|
|
4 import christie.codegear.StartCodeGear;
|
|
5 import christie.test.topology.paxos.acceptor.AcceptorCodeGear;
|
|
6 import christie.test.topology.paxos.learner.LearnerCodeGear;
|
|
7 import christie.test.topology.paxos.proposer.ProposerCodeGear;
|
|
8 import christie.topology.TopologyDataGear;
|
|
9
|
|
10 import java.util.ArrayList;
|
|
11 import java.util.List;
|
|
12
|
|
13 public class StartLocalPaxos extends StartCodeGear{
|
|
14
|
|
15 public StartLocalPaxos(CodeGearManager cgm) {
|
|
16 super(cgm);
|
|
17
|
|
18 }
|
|
19
|
|
20 public static void main(String args[]){
|
|
21 int proposerPort = 10000;
|
|
22 int proposersNum = 2;
|
|
23 int acceptorPort = proposerPort + proposersNum;
|
|
24 int acceptorsNum = 3;
|
|
25 int learnerPort = acceptorPort + acceptorsNum;
|
|
26 int learnersNum = 1;
|
|
27
|
|
28 List<CodeGearManager> proposers = new ArrayList<>(proposersNum);
|
|
29 List<CodeGearManager> acceptors = new ArrayList<>(acceptorsNum);
|
|
30 List<CodeGearManager> learners = new ArrayList<>(learnersNum);
|
|
31 TopologyDataGear proposerTopoDG = new TopologyDataGear();
|
|
32 TopologyDataGear acceptorTopoDG = new TopologyDataGear();
|
|
33
|
|
34
|
|
35 for(int i = 0; i < learnersNum; i++){
|
|
36 String nodeName = "learner" + i;
|
|
37 acceptorTopoDG.addConnection(nodeName);
|
166
|
38 TopologyDataGear topoDG = new TopologyDataGear();
|
164
|
39
|
|
40 CodeGearManager learner = createCGM(learnerPort + i);
|
166
|
41 topoDG.setNodeName(nodeName);
|
|
42 learner.getLocalDGM().put("topoDG", topoDG);
|
|
43 learner.setup(new CheckMyName());
|
164
|
44 learners.add(learner);
|
|
45 }
|
|
46
|
|
47 for(int i = 0; i < acceptorsNum; i++){
|
|
48 String nodeName = "acceptor" + i;
|
|
49 proposerTopoDG.addConnection(nodeName);
|
|
50
|
|
51 CodeGearManager acceptor = createCGM(acceptorPort + i);
|
|
52 TopologyDataGear topoDG = acceptorTopoDG.clone();
|
|
53 topoDG.setNodeName(nodeName);
|
|
54 acceptor.getLocalDGM().put("topoDG", topoDG);
|
166
|
55 acceptor.setup(new CheckMyName());
|
164
|
56 acceptors.add(acceptor);
|
|
57 }
|
|
58
|
|
59 for(int i = 0; i < proposersNum; i++){
|
|
60 String nodeName = "proposer" + i;
|
|
61
|
|
62 CodeGearManager proposer = createCGM(proposerPort + i);
|
|
63 TopologyDataGear topoDG = proposerTopoDG.clone();
|
|
64 topoDG.setNodeName(nodeName);
|
|
65 topoDG.setTotalNodeNum(proposersNum);
|
|
66 proposer.getLocalDGM().put("topoDG", topoDG);
|
|
67
|
|
68 proposers.add(proposer);
|
|
69 }
|
|
70
|
|
71 for(int i = 0; i < proposersNum; i++){
|
|
72 for(int j = 0; j < acceptorsNum; j++){
|
|
73 proposers.get(i).createRemoteDGM(proposerTopoDG.getConnectionList().get(j), "localhost", acceptors.get(j).localPort);
|
|
74 acceptors.get(j).createRemoteDGM("proposer" + i, "localhost", proposers.get(i).localPort);
|
|
75
|
|
76 }
|
166
|
77 proposers.get(i).setup(new CheckMyName());
|
164
|
78 }
|
|
79
|
|
80 for(int i = 0; i < acceptorsNum; i++){
|
|
81 for(int j = 0; j < learnersNum; j++){
|
|
82 acceptors.get(i).createRemoteDGM(acceptorTopoDG.getConnectionList().get(j), "localhost", learners.get(j).localPort);
|
|
83 learners.get(j).createRemoteDGM(proposerTopoDG.getConnectionList().get(j), "localhost", acceptors.get(i).localPort);
|
|
84 }
|
|
85 }
|
|
86 }
|
|
87 } |