-
Notifications
You must be signed in to change notification settings - Fork 4
/
Learner.java
28 lines (23 loc) · 937 Bytes
/
Learner.java
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
package com.maximilianmichels.paxos;
import akka.actor.ActorRef;
public class Learner extends Actor {
private long lastProposalNo = -1;
private long lastValue = -1;
Learner(int idx) {
super(idx);
}
@Override
public Receive createReceive() {
return receiveBuilder()
.match(Messages.Accepted.class,
(accepted) -> {
if (lastProposalNo < accepted.proposalNo) {
lastProposalNo = accepted.proposalNo;
lastValue = accepted.value;
LOG("Received accepted. No: " + accepted.proposalNo + " value: " + accepted.value);
accepted.client.tell(new Messages.Response(accepted.proposalNo, lastValue), ActorRef.noSender());
}
})
.build();
}
}