Mercurial > hg > Database > Christie
changeset 166:f2218b5590d3
add CheckMyName
author | akahori |
---|---|
date | Tue, 22 Jan 2019 15:07:12 +0900 |
parents | e0fb4f8699f8 |
children | 240058b2ce3e |
files | src/main/java/christie/test/topology/paxos/CheckMyName.java src/main/java/christie/test/topology/paxos/StartLocalPaxos.java |
diffstat | 2 files changed, 39 insertions(+), 3 deletions(-) [+] |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/christie/test/topology/paxos/CheckMyName.java Tue Jan 22 15:07:12 2019 +0900 @@ -0,0 +1,33 @@ +package christie.test.topology.paxos; + +import christie.annotation.Peek; +import christie.codegear.CodeGear; +import christie.codegear.CodeGearManager; +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.regex.Matcher; +import java.util.regex.Pattern; + +public class CheckMyName extends CodeGear { + + @Peek + TopologyDataGear topoDG; + + Pattern pattern = Pattern.compile("^(proposer|acceptor|learner)([0-9]+)$"); + + @Override + protected void run(CodeGearManager cgm) { + String nodeName = topoDG.getNodeName(); + Matcher matcher = pattern.matcher(nodeName); + + matcher.find(); + String type = matcher.group(1); + + if(type.equals("proposer")) cgm.setup(new ProposerCodeGear()); + else if(type.equals("acceptor")) cgm.setup(new AcceptorCodeGear()); + else if(type.equals("learner")) cgm.setup(new LearnerCodeGear()); + } +}
--- a/src/main/java/christie/test/topology/paxos/StartLocalPaxos.java Tue Jan 22 14:48:02 2019 +0900 +++ b/src/main/java/christie/test/topology/paxos/StartLocalPaxos.java Tue Jan 22 15:07:12 2019 +0900 @@ -35,9 +35,12 @@ for(int i = 0; i < learnersNum; i++){ String nodeName = "learner" + i; acceptorTopoDG.addConnection(nodeName); + TopologyDataGear topoDG = new TopologyDataGear(); CodeGearManager learner = createCGM(learnerPort + i); - learner.setup(new LearnerCodeGear()); + topoDG.setNodeName(nodeName); + learner.getLocalDGM().put("topoDG", topoDG); + learner.setup(new CheckMyName()); learners.add(learner); } @@ -49,7 +52,7 @@ TopologyDataGear topoDG = acceptorTopoDG.clone(); topoDG.setNodeName(nodeName); acceptor.getLocalDGM().put("topoDG", topoDG); - acceptor.setup(new AcceptorCodeGear()); + acceptor.setup(new CheckMyName()); acceptors.add(acceptor); } @@ -71,7 +74,7 @@ acceptors.get(j).createRemoteDGM("proposer" + i, "localhost", proposers.get(i).localPort); } - proposers.get(i).setup(new ProposerCodeGear()); + proposers.get(i).setup(new CheckMyName()); } for(int i = 0; i < acceptorsNum; i++){