-
Notifications
You must be signed in to change notification settings - Fork 0
/
acceptor.erl
31 lines (25 loc) · 900 Bytes
/
acceptor.erl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
%%% Paul Vidal (pv14) and Saturnin Pugnet (sp5414)
-module(acceptor).
-import(utils, [compare/2]).
-export([start/0]).
start() ->
Starting_ballot_number = {-1, 0},
next(Starting_ballot_number, []).
next(Ballot_number, Accepted) ->
receive
{p1a, Leader, Ballot} ->
case compare(Ballot, Ballot_number) > 0 of
true -> New_ballot_number = Ballot;
false -> New_ballot_number = Ballot_number
end,
Leader ! {p1b, self(), New_ballot_number, Accepted},
next(New_ballot_number, Accepted);
{p2a, Leader, {Ballot, Slot, Command}} ->
% io:format("~p ~n", [{Ballot, Slot, Command}]),
case compare(Ballot, Ballot_number) == 0 of
true -> New_accepted = Accepted ++ [{Ballot, Slot, Command}];
false -> New_accepted = Accepted
end,
Leader ! {p2b, self(), Ballot_number},
next(Ballot_number, New_accepted)
end.