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