159
|
1 package christie.test.topology.paxos.acceptor;
|
37
|
2
|
148
|
3 import christie.annotation.Peek;
|
|
4 import christie.annotation.Take;
|
37
|
5 import christie.codegear.CodeGear;
|
|
6 import christie.codegear.CodeGearManager;
|
159
|
7 import christie.test.topology.paxos.Proposal;
|
164
|
8 import christie.topology.TopologyDataGear;
|
181
|
9 import org.apache.logging.log4j.LogManager;
|
|
10 import org.apache.logging.log4j.Logger;
|
157
|
11
|
|
12 import java.util.List;
|
37
|
13
|
|
14 public class AcceptCodeGear extends CodeGear {
|
|
15
|
157
|
16 @Peek
|
164
|
17 TopologyDataGear topoDG;
|
157
|
18
|
148
|
19 @Take
|
|
20 Proposal acceptProposal;
|
|
21
|
190
|
22
|
|
23 //PromiseProposal promiseProposal;
|
|
24
|
|
25 //@Take
|
|
26 //Proposal promisedProposal;
|
148
|
27
|
181
|
28 Logger logger = LogManager.getLogger(AcceptCodeGear.class);
|
|
29
|
190
|
30
|
37
|
31 @Override
|
|
32 protected void run(CodeGearManager cgm) {
|
164
|
33 List<String> _CLIST = topoDG.getConnectionList();
|
37
|
34
|
190
|
35 // promise codegearでも使うので, lock
|
|
36 PromiseProposal.getInstance().lock();
|
|
37 PromiseProposal promiseProposal = PromiseProposal.getInstance();
|
|
38 Proposal promisedProposal = promiseProposal.getPromiseProposal();
|
|
39
|
172
|
40 if(acceptProposal.getNumber() >= promisedProposal.getNumber()) {
|
190
|
41 logger.debug(acceptProposal + " >= " + promisedProposal);
|
157
|
42 acceptProposal.setAccepted(true);
|
164
|
43 acceptProposal.setAcceptorName(topoDG.getNodeName());
|
157
|
44
|
181
|
45 promisedProposal = acceptProposal;
|
|
46
|
172
|
47 for (String connectionNodeName : _CLIST){
|
183
|
48 if(connectionNodeName.matches("learner" + ".*")) {
|
190
|
49 //logger.debug("send " + topoDG.getNodeName() + " to "
|
|
50 // + connectionNodeName + " " + promisedProposal);
|
183
|
51 getDGM(connectionNodeName).put("acceptedProposal", promisedProposal);
|
172
|
52 }
|
|
53 }
|
181
|
54 }
|
190
|
55 promiseProposal.setPromiseProposal(promisedProposal);
|
|
56 promiseProposal.unLock();
|
|
57 logger.debug("accept " + topoDG.getNodeName() + " " + promisedProposal);
|
181
|
58 put(acceptProposal.getProposerName(), "acceptedProposal", promisedProposal);
|
|
59 put("promisedProposal", promisedProposal);
|
37
|
60
|
157
|
61 cgm.setup(new AcceptCodeGear());
|
190
|
62 }
|
157
|
63
|
190
|
64
|
37
|
65 }
|