Newer
Older
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
32
33
34
35
36
37
38
39
40
41
\section{ActionPrepareDistributedCommitedTransferAnswer}
After an answer from a client reached the server, the server tries to
find the corresponding request. If the answer was a acknowlegement, the
request will get another positive answer. When the same amount of
positive answers equals the count of known neighbors received on the
server, all client will be informed to commit the change and the
request will be deleted. If the answer was an abort, all clients will be
informed to abort the transaction.
\\
\begin{lstlisting}
protected void onAction(ActorRef sender, ActorRef self, UntypedActorContext context,
SuperVisor superVisor) {
log(""+superVisor.getKnownNeighbors());
log("granted?"+granted);
DistributedCommitedTransferRequest request = superVisor.getRequest(id);
if(granted){
if(request==null) //unknown DistributedCommitedTransferRequest ignore
return;
int newCount = request.addPositiveAnswer(sender);
if(newCount == superVisor.getKnownNeighbors().size()){
ActionCommitDistributedCommitedTransfer acdct =
new ActionCommitDistributedCommitedTransfer(source, target, amount, true,
timestamp, id);
for(ActorRef neighbor : request.getAnswers()){
neighbor.tell(acdct, self);
}
superVisor.deleteRequest(request);
}
}else{
// A client wants to rollback
if(request!=null){
ActionCommitDistributedCommitedTransfer acdct =
new ActionCommitDistributedCommitedTransfer(source, target, amount, false,
timestamp, id);
for(ActorRef neighbor : request.getAnswers()){
neighbor.tell(acdct, self);
}
}
}
}
\end{lstlisting}