comparison src/main/java/christie/test/topology/paxos/acceptor/PromiseProposal.java @ 190:2d0d41b648fa

add PromiseProposal and refactor acceptor
author akahori
date Tue, 12 Feb 2019 16:10:15 +0900
parents
children
comparison
equal deleted inserted replaced
189:9b0a7f8dde81 190:2d0d41b648fa
1 package christie.test.topology.paxos.acceptor;
2
3 import christie.test.topology.paxos.Proposal;
4
5 // singleton
6 public class PromiseProposal {
7 Proposal promiseProposal = null;
8
9 private static PromiseProposal instance = new PromiseProposal();
10
11
12 private Object _lock = new Object();
13
14 private boolean sync = false;
15
16 public void setPromiseProposal(Proposal promiseProposal){
17 this.promiseProposal = promiseProposal;
18 }
19
20 public Proposal getPromiseProposal() {
21 return promiseProposal;
22 }
23
24 public synchronized static PromiseProposal getInstance(){
25 return instance;
26 }
27
28 public void lock(){
29 synchronized (_lock){
30 while(sync){
31 try {
32 _lock.wait();
33 } catch (InterruptedException e) {
34 }
35 }
36 }
37 sync = true;
38 }
39
40 public void unLock(){
41 synchronized (_lock){
42 _lock.notify();
43 sync = false;
44 }
45 }
46 }