Skip to content
Snippets Groups Projects
Commit 9a20300e authored by Simon Könnecke's avatar Simon Könnecke
Browse files

By spawning new Wallets chose preKnownNeighbour randomly, chain the random transaction

parent 8fcac86d
Branches
No related tags found
No related merge requests found
......@@ -70,7 +70,7 @@ public class ActionCommitDistributedCommittedTransfer extends ClientAction {
}
// recipient should notify a possible observer
if (observer != null) {
if (observer != null && granted) {
observer.tell(new ActionNotifyObserver(source, target, amount, granted, timestamp, id), self);
}
//wallet.addLogMsg("wallet.amounts:" + wallet.amounts);
......
......@@ -20,12 +20,14 @@ public class ActionInvokeSentMoney extends Transaction {
@Override
protected void onAction(ActorRef sender, ActorRef self,
UntypedActorContext context, AbstractWallet wallet) {
wallet.addLogMsg(wallet.getKnownNeighbors() + "");
if (wallet.getKnownNeighbors().containsKey(name)) {
wallet.addLogMsg("Sender knows Wallet " + name);
wallet.getRemoteSuperVisorActor().tell(
new ActionInvokeDistributedCommittedTransfer(self, wallet.getKnownNeighbors().get(name),
amount, observer), sender);
} else {
wallet.addLogMsg("Sender don't knows Wallet " + name);
//Search the wallet
ActionSearchWalletReference aswr = new ActionSearchWalletReference(name);
//Ask all neighbors
......
......@@ -12,7 +12,6 @@ import fucoin.actions.control.ActionWalletSendMoney;
import fucoin.actions.join.ActionTellSupervisor;
import fucoin.actions.transaction.ActionGetAmount;
import fucoin.actions.transaction.ActionGetAmountAnswer;
import fucoin.actions.transaction.ActionInvokeDistributedCommittedTransfer;
import fucoin.actions.transaction.ActionNotifyObserver;
import fucoin.configurations.internal.ConfigurationCreator;
import fucoin.supervisor.SuperVisorImpl;
......@@ -37,7 +36,7 @@ public abstract class AbstractConfiguration extends AbstractNode {
private Timeout timeout = new Timeout(Duration.create(10, "seconds"));
private int remainingTransactions;
protected int remainingTransactions;
public static Props props(Class configurationClass) {
......@@ -65,20 +64,18 @@ public abstract class AbstractConfiguration extends AbstractNode {
if (numOfWallets == 0) {
props = WalletImpl.props(null, name, createGUI);
} else {
props = WalletImpl.props(activeActors.get(numOfWallets - 1), name, createGUI);
ActorRef knownNeighbour = activeActors.get(ThreadLocalRandom.current().nextInt(activeActors.size()));
props = WalletImpl.props(knownNeighbour, name, createGUI);
}
ActorRef actorRef = context().actorOf(props, name);
activeActors.add(actorRef);
//if (numOfWallets == 0) {
//Tell the new Wallet the SuperVisor,
//probably knownNeighbour isn't so far and can tell the him.
actorRef.tell(new ActionTellSupervisor(superVisor), superVisor);
/*
superVisor.tell( new ActionInvokeDistributedCommittedTransfer(superVisor,
actorRef, 100, superVisor), actorRef);
*/
//}
return actorRef;
}
......@@ -118,12 +115,16 @@ public abstract class AbstractConfiguration extends AbstractNode {
}
private void nextRandomTransaction() {
protected void nextRandomTransaction() {
if (remainingTransactions <= 0) {
return;
}
remainingTransactions--;
try {
randomTransaction();
} catch (Exception e) {
System.err.println("Error while trying to perform a random transaction: "+e.getMessage());
System.err.println("Error while trying to perform a random transaction: " + e.getMessage());
remainingTransactions = 0;
}
}
......@@ -139,8 +140,8 @@ public abstract class AbstractConfiguration extends AbstractNode {
Future<Object> futureNeighbour = Patterns.ask(sender, new ActionWalletGetNeighbours(), timeout);
ActionWalletGetNeighboursAnswer neighboursAnswer = (ActionWalletGetNeighboursAnswer) Await.result(futureNeighbour,
timeout.duration());
for (int i=1; i < wallets.size(); i++) {
if (neighboursAnswer.getNeighbour().containsValue(wallets.get(i))) {
for (int i = 1; i < wallets.size(); i++) {
if (!wallets.get(i).equals(sender) && neighboursAnswer.getNeighbour().containsValue(wallets.get(i))) {
recipient = wallets.get(i);
}
}
......
......@@ -8,6 +8,7 @@ import fucoin.configurations.internal.ConfigurationName;
*/
@ConfigurationName("Lots of Wallets")
public class MassWalletConfiguration extends AbstractConfiguration {
private boolean runRandomTransactions = false;
@Override
public void run() {
initSupervisor();
......@@ -18,12 +19,17 @@ public class MassWalletConfiguration extends AbstractConfiguration {
} catch (Exception e) {
System.out.println("Wallet spawning timed out!");
}
randomTransactions(100, 10);
remainingTransactions = 100;
runRandomTransactions = true;
nextRandomTransaction();
//randomTransactions(100, 10);
}
@Override
public void onReceive(Object message) {
if (message instanceof ActionNotifyObserver && runRandomTransactions) {
nextRandomTransaction();
}
super.onReceive(message);
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment