Skip to content
Snippets Groups Projects
Commit dd54aa44 authored by rimesime's avatar rimesime
Browse files

cleanup

parent 63313ef1
No related branches found
No related tags found
No related merge requests found
Showing
with 0 additions and 453 deletions
File moved
File moved
File moved
import java.util.HashMap;
import akka.actor.ActorRef;
import akka.actor.UntypedActor;
import java.io.Serializable;
public abstract class AbstractWallet extends UntypedActor implements Serializable {
// Used to join the network (a pre known participant/Wallet must be known)
public static class ActionJoin implements Serializable {}
// Returns some neighbors that might be used as known
// and/or local neighbors
public class ActionJoinAnswer implements Serializable {
public final HashMap<String, ActorRef> someNeighbors = new HashMap<>();
}
// Used to push the state of my/a wallet to another participant
public static class ActionStoreOrUpdate implements Serializable {
public final AbstractWallet w;
public ActionStoreOrUpdate(AbstractWallet w) {
this.w = w;
}
}
// May be used to delete a stored Wallet on another participant
public static class ActionInvalidate implements Serializable {
public final String name;
public ActionInvalidate(String name) {
this.name = name;
}
}
// Used to send (positive amount) or retreive money (negative amount)
public static class ActionReceiveTransaction implements Serializable {
public final int amount;
public ActionReceiveTransaction(int amount) {
this.amount = amount;
}
}
// Used to search a Wallet by name, i.e. when we want to
// perform a transaction on it
public static class ActionSearchWalletReference implements Serializable {
public final String name;
public ActionSearchWalletReference(String name) {
this.name = name;
}
}
// Used to return a Wallet reference (akka-style string which can
// be transformed to an ActorRef)
public static class ActionSearchWalletReferenceAnswer implements Serializable {
public final String address;
public ActionSearchWalletReferenceAnswer(String address) {
this.address = address;
}
}
// Used to search a Wallet by name, i.e. the own wallet if we just
// joined the network; If a receiving participant holds the stored Wallet,
// he returns it, otherwise, he might use gossiping methods to go on
// with the search;
// Note: You should also forward the sender (the participant who actually
// searches for this Wallet, so that it can be returnd the direct way)
public static class ActionSearchMyWallet implements Serializable {
public final String name;
public ActionSearchMyWallet(String name) {
this.name = name;
}
}
// Used to return a searched Wallet
public static class ActionSearchMyWalletAnswer implements Serializable {
public final AbstractWallet w;
public ActionSearchMyWalletAnswer(AbstractWallet w) {
this.w = w;
}
}
// Constructor
public AbstractWallet(String name) {
this.name = name;
}
// Returns the name of this wallet, e.g. "Lieschen Müller"
public String getName() {
return this.name;
}
// Returns the akka-style address as String, which
// could be converted to an ActorRef object later
public abstract String getAddress();
// Performs housekeeping operations, e.g. pushes
// backedUpNeighbor-entries to other neighbors
public abstract void leave();
// The which receives Action objects
public abstract void onReceive(Object message);
// Holds references to neighbors that were in
// contact with this wallet during runtime;
// The key corresponds to the Wallet's name
public transient HashMap<String, ActorRef> knownNeighbors;
// Holds references to neighbors this wallet
// synchronizes itself to (the Wallet object);
// The key corresponds to the Wallet's name
public transient HashMap<String, ActorRef> localNeighbors;
// Holds all Wallets from network participants
// which synchronize their state (Wallet object)
// with us;
// The key corresponds to the Wallet's name
public transient HashMap<String, AbstractWallet> backedUpNeighbors;
// The name of this wallet (does never change, no
// duplicates in network assumed)
public final String name;
// The amount this wallet currently holds
public int amount;
}
\ No newline at end of file
import akka.actor.ActorRef;
import akka.actor.UntypedActor;
import akka.actor.ActorSystem;
import akka.actor.Props;
import akka.actor.Inbox;
import java.io.Serializable;
public class Wallet extends AbstractWallet {
public static void main(String[] args) {
// Create the 'helloakka' actor system
final ActorSystem system = ActorSystem.create("FuCoin");
// Create the 'greeter' actor
final ActorRef greeter = system.actorOf(Props.create(Wallet.class, "Hans Wurst"), "wallet");
// Create the "actor-in-a-box"
final Inbox inbox = Inbox.create(system);
}
public Wallet(String name)
{
super(name);
}
public void onReceive(Object message) {
// TODO implement
/*
if (message instanceof ActionReceiveTransaction)
{
System.out.println("hello, " + ((ActionReceiveTransaction) message).amount;
}
else if (message instanceof ActionReceiveTransaction) {
// Send the current greeting back to the sender
getSender().tell(new ActionReceiveTransaction(0.01), getSelf());
}
else {
unhandled(message);
}
*/
}
public String getAddress() {
// TODO implement
return "";
}
public void leave() {
// TODO implement
}
}
\ No newline at end of file
\relax
\providecommand\hyper@newdestlabel[2]{}
\@writefile{toc}{\contentsline {section}{\numberline {1}Introduction}{1}{section.1}}
\@setckpt{1_introduction}{
\setcounter{page}{2}
\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}{1}
\setcounter{subsection}{0}
\setcounter{subsubsection}{0}
\setcounter{paragraph}{0}
\setcounter{subparagraph}{0}
\setcounter{figure}{0}
\setcounter{table}{0}
\setcounter{vrcnt}{0}
\setcounter{lstnumber}{1}
\setcounter{Item}{0}
\setcounter{Hfootnote}{0}
\setcounter{bookmark@seq@number}{1}
\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}
For a transaction in the FUCoin system 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.
\bigskip
\\
\\
\\
\\
\includegraphics[width=1.0\textwidth]{pictures/TimelineCorrectTransfer.pdf}
\relax
\providecommand\hyper@newdestlabel[2]{}
\@writefile{toc}{\contentsline {section}{\numberline {2}ActionInvokeSentMoney}{2}{section.2}}
\@setckpt{2_actioninvokesentmoney}{
\setcounter{page}{3}
\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}{2}
\setcounter{subsection}{0}
\setcounter{subsubsection}{0}
\setcounter{paragraph}{0}
\setcounter{subparagraph}{0}
\setcounter{figure}{0}
\setcounter{table}{0}
\setcounter{vrcnt}{0}
\setcounter{lstnumber}{17}
\setcounter{Item}{0}
\setcounter{Hfootnote}{0}
\setcounter{bookmark@seq@number}{2}
\setcounter{lstlisting}{0}
\setcounter{section@level}{1}
}
\section{ActionInvokeSentMoney}
This action is invoked by the graphical user interface of the wallets.
The goal is to transfer an amount of FUCoins to a given wallet ID.
If this ID already has a mapping to an ActorRef, an
ActionInvokeDistributedCommitedTransfer will be send to the supervisor.
Otherwise a gossip is invoked using the ActionSearchWalletReference
following by ActionInvokeSentMoney after 200 ms.
\\
\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}
\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]{}
\@writefile{toc}{\contentsline {section}{\numberline {3}ActionInvokeDistributedCommitedTransfer}{3}{section.3}}
\@setckpt{3_actioninvokedistributedcommitedtransfer}{
\setcounter{page}{4}
\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}{3}
\setcounter{subsection}{0}
\setcounter{subsubsection}{0}
\setcounter{paragraph}{0}
\setcounter{subparagraph}{0}
\setcounter{figure}{0}
\setcounter{table}{0}
\setcounter{vrcnt}{0}
\setcounter{lstnumber}{16}
\setcounter{Item}{0}
\setcounter{Hfootnote}{0}
\setcounter{bookmark@seq@number}{3}
\setcounter{lstlisting}{0}
\setcounter{section@level}{1}
}
\section{ActionInvokeDistributedCommitedTransfer}
The ActionInvokeDistributedCommitedTransfer creates a
DistributedCommitedTransferRequest, which contains a random generated
ID, on the Server with a timout of 500 ms, and stores 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 that 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}
\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]{}
\@writefile{toc}{\contentsline {section}{\numberline {4}ActionPrepareDistributedCommitedTransfer}{4}{section.4}}
\@setckpt{4_actionpreparedistributedcommitedtransfer}{
\setcounter{page}{5}
\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}{4}
\setcounter{subsection}{0}
\setcounter{subsubsection}{0}
\setcounter{paragraph}{0}
\setcounter{subparagraph}{0}
\setcounter{figure}{0}
\setcounter{table}{0}
\setcounter{vrcnt}{0}
\setcounter{lstnumber}{12}
\setcounter{Item}{0}
\setcounter{Hfootnote}{0}
\setcounter{bookmark@seq@number}{4}
\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