Skip to content
Snippets Groups Projects
6_actioncommitdistributedcommitedtransfer.tex 986 B
Newer Older
Michael Kmoch's avatar
Michael Kmoch committed
\section{ActionCommitDistributedCommitedTransfer}
If a client has to commit the given changes, it will perform the
transaction on the amounts map. Otherwise it will just print an abort
transaction message.
\\
\begin{lstlisting}
protected void onAction(ActorRef sender, ActorRef self, UntypedActorContext context,
                        Wallet wallet) {
  log("ActionCommitDistributedCommitedTransfer is granted?"+granted);
  if(granted){
    Integer sourceAmount = wallet.amounts.getOrDefault(source,0);
    Integer targetAmount = wallet.amounts.getOrDefault(target,0);
    wallet.amounts.put(source,sourceAmount-amount);
    wallet.amounts.put(target,targetAmount+amount);
    if(source.compareTo(self)==0)
      wallet.amount-=amount;
    else if(target.compareTo(self)==0)
      wallet.amount+=amount;
    wallet.log("have now "+wallet.amounts.get(self)+" Fucoins");
  }else{
    log("abort transaction with id"+id);
  }
  log("wallet.amounts:"+wallet.amounts);	
}
\end{lstlisting}