Skip to content
Snippets Groups Projects
Commit 0456efe1 authored by Michael Kmoch's avatar Michael Kmoch
Browse files

cleaned up code

added paper v0.5 will be updated
parent 40b677aa
No related branches found
No related tags found
1 merge request!1Kmoch lewash
Showing
with 372 additions and 45 deletions
File added
......@@ -32,15 +32,11 @@ public class ActionSearchWalletReference extends Search{
answer = new ActionSearchWalletReferenceAnswer(name,wallet.getAddress(wallet.getKnownNeighbors().get(name)),ttl);
} else if (ttl.size()<5){
for(ActorRef neighbor : wallet.getKnownNeighbors().values()){
if(!ttl.contains(neighbor)){
if(!ttl.contains(neighbor)){
neighbor.tell(this, self);
}
}
}
//System.out.println("ttl:"+ttl.size());
//User unknown by this Wallet
if(answer!=null&&ttl.size()>0){
ttl.get(ttl.size()-1).tell(answer, self);
......
......@@ -39,7 +39,7 @@ public class ActionCommitDistributedCommitedTransfer extends ClientAction{
@Override
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);
......@@ -51,8 +51,7 @@ public class ActionCommitDistributedCommitedTransfer extends ClientAction{
}else{
log("abort transaction with id"+id);
}
log("wallet.amounts:"+wallet.amounts);
log("wallet.amounts:"+wallet.amounts);
}
}
......@@ -24,12 +24,13 @@ public class ActionInvokeDistributedCommitedTransfer extends CoordinatorTransact
@Override
protected void onAction(ActorRef sender, ActorRef self,
UntypedActorContext context, SuperVisor superVisor) {
log("invoke transaction "+source.path().name()+" "+amount+" "+target.path().name());
long timestamp = System.currentTimeMillis()+500;
DistributedCommitedTransferRequest ds = new DistributedCommitedTransferRequest(source,target,timestamp);
log("invoke transaction "+source.path().name()+" sends "+amount+" to "+target.path().name());
long timeout = System.currentTimeMillis()+500;
DistributedCommitedTransferRequest ds = new DistributedCommitedTransferRequest(source,target,timeout);
superVisor.addDistributedCommitedTransferRequest(ds);
ActionPrepareDistributedCommitedTransfer apdct = new ActionPrepareDistributedCommitedTransfer(source,target,amount,timeout,ds.getId());
for(ActorRef neighbor : superVisor.getKnownNeighbors().values()){
neighbor.tell(new ActionPrepareDistributedCommitedTransfer(source,target,amount,timestamp,ds.getId()), self);
neighbor.tell(apdct, self);
}
}
......
......@@ -21,21 +21,21 @@ public class ActionInvokeSentMoney extends Transaction{
wallet.getRemoteSuperVisorActor().tell(
new ActionInvokeDistributedCommitedTransfer(self,wallet.getKnownNeighbors().get(name),amount), sender);
}else{
ActionSearchWalletReference aswr = new ActionSearchWalletReference(name);
for(ActorRef neighbor : wallet.getKnownNeighbors().values()){
neighbor.tell(new ActionSearchWalletReference(name), self);
neighbor.tell(aswr, self);
}
try {
context.unwatch(self);
Thread.sleep(200);
context.watch(self);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
//getContext().unwatch(getSelf());
self.tell(new ActionInvokeSentMoney(name, amount), self);
sleep(self, context, 200);
self.tell(this, self);
}
}
private void sleep(ActorRef self, UntypedActorContext context, int sleeptime) {
try {
context.unwatch(self);
Thread.sleep(sleeptime);
context.watch(self);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
......@@ -24,17 +24,9 @@ public class ActionPrepareDistributedCommitedTransfer extends Transaction{
@Override
protected void onAction(ActorRef sender, ActorRef self,
UntypedActorContext context, Wallet wallet) {
//log("wallet.amounts:"+wallet.amounts);
//log("amount:"+amount);
//log("source:"+source);
//log("check if "+source.path().name()+" has more than "+amount+" he has now "+wallet.amounts.getOrDefault(source,0));
//log("and sender.compareTo(source)==0?"+sender.compareTo(source));
boolean granted = sender.compareTo(source)==0 //sender is supervisor(bank) has allways money
||(wallet.amounts.containsKey(source) //sender is unknown, might be valid
&&wallet.amounts.getOrDefault(source,0)>=amount) ; //sender have enough money
//log("granted?:"+granted);
//log("contains?:"+wallet.amounts.containsKey(source) );
sender.tell(new ActionPrepareDistributedCommitedTransferAnswer(source, target, amount,timestamp,granted,id),self);
}
......
......@@ -35,16 +35,19 @@ public class ActionPrepareDistributedCommitedTransferAnswer extends CoordinatorT
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(new ActionCommitDistributedCommitedTransfer(source,target,amount,true,timestamp,id), self);
neighbor.tell(acdct, self);
}
superVisor.deleteRequest(request);
}
}else{
//A client wants to rollback
if(request!=null)
for(ActorRef neighbor : request.getAnswers()){
neighbor.tell(new ActionCommitDistributedCommitedTransfer(source,target,amount,false,timestamp,id), self);
if(request!=null){
ActionCommitDistributedCommitedTransfer acdct = new ActionCommitDistributedCommitedTransfer(source,target,amount,false,timestamp,id);
for(ActorRef neighbor : request.getAnswers()){
neighbor.tell(acdct, self);
}
}
}
}
......
......@@ -132,6 +132,12 @@ public WalletGui(IWalletControle walletControle) {
super.windowClosing(e);
}
@Override
public void windowClosed(WindowEvent e) {
System.out.println("window closing");
walletControle.leave();
super.windowClosing(e);
}
});
}
......
......@@ -22,18 +22,16 @@ public class ActionUpdateQueue extends SuperVisorAction{
neighbor.tell(acdct, self);
}
}
context.unwatch(self);
sleep(1000);
context.watch(self);
sleep(self,context,1000);
self.tell(this, self);
}
private void sleep(long time) {
private void sleep(ActorRef self, UntypedActorContext context, int sleeptime) {
try {
Thread.sleep(time);
context.unwatch(self);
Thread.sleep(sleeptime);
context.watch(self);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
......
......@@ -65,7 +65,10 @@ public class SuperVisor extends AbstractNode {
requestQueue = new HashMap<Long,DistributedCommitedTransferRequest>();
self().tell(new ActionUpdateQueue(), self());
}
/**
* filters the request for outdated and removes them
* @return deleted outdated request
*/
public List<DistributedCommitedTransferRequest> updateList(){
List<Long> deletesIds = new ArrayList<Long>();
List<DistributedCommitedTransferRequest> deletes = new ArrayList<DistributedCommitedTransferRequest>();
......
\relax
\providecommand\hyper@newdestlabel[2]{}
\@writefile{toc}{\contentsline {section}{\numberline {1}Introduction}{1}{section.1}}
\@writefile{toc}{\contentsline {section}{\numberline {2}ActionInvokeSentMoney}{1}{section.2}}
\@writefile{toc}{\contentsline {section}{\numberline {3}ActionInvokeDistributedCommitedTransfer}{2}{section.3}}
\@writefile{toc}{\contentsline {section}{\numberline {4}ActionPrepareDistributedCommitedTransfer}{3}{section.4}}
\@writefile{toc}{\contentsline {section}{\numberline {5}ActionPrepareDistributedCommitedTransferAnswer}{3}{section.5}}
\@writefile{toc}{\contentsline {section}{\numberline {6}ActionCommitDistributedCommitedTransfer}{4}{section.6}}
\@writefile{toc}{\contentsline {section}{\numberline {7}ActionUpdateQueue}{5}{section.7}}
\@setckpt{1_introduction}{
\setcounter{page}{6}
\setcounter{equation}{0}
\setcounter{enumi}{0}
\setcounter{enumii}{0}
\setcounter{enumiii}{0}
\setcounter{enumiv}{0}
\setcounter{footnote}{0}
\setcounter{mpfootnote}{0}
\setcounter{part}{0}
\setcounter{section}{7}
\setcounter{subsection}{0}
\setcounter{subsubsection}{0}
\setcounter{paragraph}{0}
\setcounter{subparagraph}{0}
\setcounter{figure}{0}
\setcounter{table}{0}
\setcounter{vrcnt}{0}
\setcounter{lstnumber}{15}
\setcounter{Item}{0}
\setcounter{Hfootnote}{0}
\setcounter{bookmark@seq@number}{7}
\setcounter{lstlisting}{0}
\setcounter{section@level}{1}
}
This is pdfTeX, Version 3.1415926-2.5-1.40.14 (TeX Live 2013/Debian) (format=pdflatex 2015.7.23) 23 JUL 2015 11:55
entering extended mode
restricted \write18 enabled.
file:line:error style messages enabled.
%&-line parsing enabled.
**1_introduction.tex
(./1_introduction.tex
LaTeX2e <2011/06/27>
Babel <3.9h> and hyphenation patterns for 7 languages loaded.
./1_introduction.tex:2: LaTeX Error: Missing \begin{document}.
See the LaTeX manual or LaTeX Companion for explanation.
Type H <return> for immediate help.
...
l.2 W
e have to make sure, that either all operational participants commit the
?
./1_introduction.tex:2: Emergency stop.
...
l.2 W
e have to make sure, that either all operational participants commit the
You're in trouble here. Try typing <return> to proceed.
If that doesn't work, type X <return> to quit.
Here is how much of TeX's memory you used:
6 strings out of 494976
294 string characters out of 6179137
46219 words of memory out of 5000000
3331 multiletter control sequences out of 15000+600000
3640 words of font info for 14 fonts, out of 8000000 for 9000
14 hyphenation exceptions out of 8191
5i,0n,4p,94b,14s stack positions out of 5000i,500n,10000p,200000b,80000s
./1_introduction.tex:2: ==> Fatal error occurred, no output PDF file produced!
\section{Introduction}
We have to make sure, that either all operational participants commit the
transaction or none of them. Each participant has one of two votes for the
possible transaction: YES or NO. For the transaction to happen all participants
have to vote YES, so a decision cannot be reversed.
The init participant acts as the coordinator and sends a 'vote request' to all
other participants. After a participant receives this request, it responds with
either YES or NO. In case of NO the decision is already 'Abort'. If all
participants vote YES, the coordinator decides 'Commit' and sends a commit
message to all participants. Otherwise it sends an abort message to all
participants that voted YES.
\includegraphics[width=1.0\textwidth]{pictures/TimelineCorrectTransfer.png}
\section{ActionInvokeSentMoney}
This action is invoked by the graphical user interface of the wallets.
The target is to transfer an amount of money to a given Walletname.
If the targetname has a allready a mapping to an ActorRef,
an ActionInvokeDistributedCommitedTransfer will be sent to the Supervisor.
Otherwise an Gossip is invoked using the ActionSearchWalletReference,
and the same ActionInvokeSentMoney is invoked after 200ms.
\begin{lstlisting}
protected void onAction(ActorRef sender,
ActorRef self,
UntypedActorContext context,
Wallet wallet) {
log(wallet.getKnownNeighbors()+"");
if(wallet.getKnownNeighbors().containsKey(name)){
wallet.getRemoteSuperVisorActor().tell(
new ActionInvokeDistributedCommitedTransfer(
self,
wallet.getKnownNeighbors().get(name),
amount),
sender);
}else{
ActionSearchWalletReference aswr = new ActionSearchWalletReference(name);
for(ActorRef neighbor : wallet.getKnownNeighbors().values()){
neighbor.tell(aswr, self);
}
sleep(self, context, 200);
self.tell(this, self);
}
}
\end{lstlisting}
\section{ActionInvokeDistributedCommitedTransfer}
The ActionInvokeDistributedCommitedTransfer creates an DistributedCommitedTransferRequest,
which contains a random generated id, on the Server,
with a timout of 500ms, and store this to a map Long --> Request accoring to the id.
The Timeout is handled by the ActionUpdateQueue explained later.
The request will spread out to all clients. The clients can answer with an acknowledgement or an abort afterwards(see below).
\begin{lstlisting}
protected void onAction(ActorRef sender,
ActorRef self,
UntypedActorContext context,
SuperVisor superVisor) {
log("invoke transaction "+source.path().name()+
" sends "+amount+" to "+target.path().name());
long timeout = System.currentTimeMillis()+500;
DistributedCommitedTransferRequest ds =
new DistributedCommitedTransferRequest(source,target,timeout);
superVisor.addDistributedCommitedTransferRequest(ds);
ActionPrepareDistributedCommitedTransfer apdct =
new ActionPrepareDistributedCommitedTransfer(
source,
target,
amount,
timeout,
ds.getId());
for(ActorRef neighbor : superVisor.getKnownNeighbors().values()){
neighbor.tell(apdct, self);
}
}
\end{lstlisting}
\section{ActionPrepareDistributedCommitedTransfer}
The clients will reply an request with an acknowlegment if one of two cases occurs.
The first case will appear if the Supervisor(Bank) will send a user some money.
Otherwise it would be neccessary that the sender is known by this client and have enough money.
\begin{lstlisting}
protected void onAction(ActorRef sender,
ActorRef self,
UntypedActorContext context,
Wallet wallet) {
//sender is supervisor(bank) has allways money
boolean granted = sender.compareTo(source)==0
//sender is unknown, might be valid
||(wallet.amounts.containsKey(source)
//sender have enough money
&&wallet.amounts.getOrDefault(source,0)>=amount);
sender.tell(
new ActionPrepareDistributedCommitedTransferAnswer(source,
target,
amount,
timestamp,
granted,
id),
self);
}
\end{lstlisting}
\section{ActionPrepareDistributedCommitedTransferAnswer}
After an answer of a client reaches the server, the server tries to find the correspong request.
If the answer was a acknowlegement, the request will get another positive answers.
When the same amount of positive answers equals the count of knownneighbors received on the server,
all client will be informed to commit the change, and the request will be deleted.
If the answer was a Abort all client will be invoked 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}
\section{ActionCommitDistributedCommitedTransfer}
If a client shall commit the given changes, it will perforrm the
changes on the amounts map. Othwise it will just print a 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}
\section{ActionUpdateQueue}
the ActionUpdateQueue Event will be invoked each second on the server,
and removes all outdated request. If a request is deleted all clients,
will be informed to abort this transaction.
\begin{lstlisting}
protected void onAction(ActorRef sender, ActorRef self,
UntypedActorContext context, SuperVisor superVisor) {
List<DistributedCommitedTransferRequest> deletes = superVisor.updateList();
for(DistributedCommitedTransferRequest outdatedRequest : deletes){
ActionCommitDistributedCommitedTransfer acdct = new ActionCommitDistributedCommitedTransfer(outdatedRequest);
for(ActorRef neighbor : superVisor.getKnownNeighbors().values()){
neighbor.tell(acdct, self);
}
}
sleep(self,context,1000);
self.tell(this, self);
}
\end{lstlisting}
\relax
\providecommand\hyper@newdestlabel[2]{}
\@setckpt{2_fundamentals}{
\setcounter{page}{6}
\setcounter{equation}{0}
\setcounter{enumi}{0}
\setcounter{enumii}{0}
\setcounter{enumiii}{0}
\setcounter{enumiv}{0}
\setcounter{footnote}{0}
\setcounter{mpfootnote}{0}
\setcounter{part}{0}
\setcounter{section}{7}
\setcounter{subsection}{0}
\setcounter{subsubsection}{0}
\setcounter{paragraph}{0}
\setcounter{subparagraph}{0}
\setcounter{figure}{0}
\setcounter{table}{0}
\setcounter{vrcnt}{0}
\setcounter{lstnumber}{15}
\setcounter{Item}{0}
\setcounter{Hfootnote}{0}
\setcounter{bookmark@seq@number}{7}
\setcounter{lstlisting}{0}
\setcounter{section@level}{1}
}
\relax
\providecommand\hyper@newdestlabel[2]{}
\@setckpt{3_main}{
\setcounter{page}{6}
\setcounter{equation}{0}
\setcounter{enumi}{0}
\setcounter{enumii}{0}
\setcounter{enumiii}{0}
\setcounter{enumiv}{0}
\setcounter{footnote}{0}
\setcounter{mpfootnote}{0}
\setcounter{part}{0}
\setcounter{section}{7}
\setcounter{subsection}{0}
\setcounter{subsubsection}{0}
\setcounter{paragraph}{0}
\setcounter{subparagraph}{0}
\setcounter{figure}{0}
\setcounter{table}{0}
\setcounter{vrcnt}{0}
\setcounter{lstnumber}{15}
\setcounter{Item}{0}
\setcounter{Hfootnote}{0}
\setcounter{bookmark@seq@number}{7}
\setcounter{lstlisting}{0}
\setcounter{section@level}{1}
}
\relax
\providecommand\hyper@newdestlabel[2]{}
\@setckpt{4_conclusion}{
\setcounter{page}{6}
\setcounter{equation}{0}
\setcounter{enumi}{0}
\setcounter{enumii}{0}
\setcounter{enumiii}{0}
\setcounter{enumiv}{0}
\setcounter{footnote}{0}
\setcounter{mpfootnote}{0}
\setcounter{part}{0}
\setcounter{section}{7}
\setcounter{subsection}{0}
\setcounter{subsubsection}{0}
\setcounter{paragraph}{0}
\setcounter{subparagraph}{0}
\setcounter{figure}{0}
\setcounter{table}{0}
\setcounter{vrcnt}{0}
\setcounter{lstnumber}{15}
\setcounter{Item}{0}
\setcounter{Hfootnote}{0}
\setcounter{bookmark@seq@number}{7}
\setcounter{lstlisting}{0}
\setcounter{section@level}{1}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment