Skip to content
Snippets Groups Projects
Commit ef6818ee authored by sinur's avatar sinur
Browse files

Added some delays to broadcast when starting a snapshot

parent bf18ee3f
Branches
No related tags found
No related merge requests found
...@@ -12,6 +12,7 @@ import scala.concurrent.Promise; ...@@ -12,6 +12,7 @@ import scala.concurrent.Promise;
import java.io.Serializable; import java.io.Serializable;
import java.util.HashMap; import java.util.HashMap;
import org.openide.util.Exceptions;
public abstract class AbstractNode extends UntypedActor implements Serializable { public abstract class AbstractNode extends UntypedActor implements Serializable {
protected SnapshotToken currentSnapshotToken; protected SnapshotToken currentSnapshotToken;
...@@ -90,7 +91,7 @@ public abstract class AbstractNode extends UntypedActor implements Serializable ...@@ -90,7 +91,7 @@ public abstract class AbstractNode extends UntypedActor implements Serializable
} }
public Promise<Snapshot> makeSnapshot() { public Promise<Snapshot> makeSnapshot() throws InterruptedException{
String prefix = ""; String prefix = "";
if (this instanceof SuperVisorImpl) { if (this instanceof SuperVisorImpl) {
prefix = "supervisor"; prefix = "supervisor";
...@@ -105,8 +106,18 @@ public abstract class AbstractNode extends UntypedActor implements Serializable ...@@ -105,8 +106,18 @@ public abstract class AbstractNode extends UntypedActor implements Serializable
AbstractWallet wallet = (AbstractWallet) this; AbstractWallet wallet = (AbstractWallet) this;
this.snapshot.addState(wallet.getName(), wallet.getAmount()); this.snapshot.addState(wallet.getName(), wallet.getAmount());
} }
//Broadcast
int i = 0;
for (ActorRef act : getKnownNeighbors().values()) { for (ActorRef act : getKnownNeighbors().values()) {
act.tell(new SnapShotBegin(this.currentSnapshotToken), self()); act.tell(new SnapShotBegin(this.currentSnapshotToken), self());
if(i % 3 == 0){
try {
//Add a little delay now and then
Thread.sleep(3000);
} catch (InterruptedException ex) {
Exceptions.printStackTrace(ex);
}
}
} }
return this.snapshot.promise(); return this.snapshot.promise();
} }
......
...@@ -26,6 +26,7 @@ import java.util.List; ...@@ -26,6 +26,7 @@ import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import java.util.stream.Stream; import java.util.stream.Stream;
import org.openide.util.Exceptions;
/** /**
* This configuration spawns 200 wallets to demonstrate the spawning of many headless wallets * This configuration spawns 200 wallets to demonstrate the spawning of many headless wallets
...@@ -185,7 +186,11 @@ public class GGBWalletConfiguration extends AbstractConfiguration { ...@@ -185,7 +186,11 @@ public class GGBWalletConfiguration extends AbstractConfiguration {
BALANCED_MIN, BALANCED_MAX, BALANCED_ADAPTION)); BALANCED_MIN, BALANCED_MAX, BALANCED_ADAPTION));
} }
start = System.currentTimeMillis() / 1000.; start = System.currentTimeMillis() / 1000.;
this.nextTransaction(); try {
this.nextTransaction();
} catch (InterruptedException ex) {
Exceptions.printStackTrace(ex);
}
simulationFinished.future().onSuccess(new OnSuccess<Void>() { simulationFinished.future().onSuccess(new OnSuccess<Void>() {
@Override @Override
public void onSuccess(Void result) { public void onSuccess(Void result) {
...@@ -195,7 +200,7 @@ public class GGBWalletConfiguration extends AbstractConfiguration { ...@@ -195,7 +200,7 @@ public class GGBWalletConfiguration extends AbstractConfiguration {
} }
}, context().dispatcher()); }, context().dispatcher());
} }
private void nextTransaction() { private void nextTransaction() throws InterruptedException {
for(;currentStep < n_steps; currentStep++) { for(;currentStep < n_steps; currentStep++) {
for (WalletSimulation currentWallet : simulations.values()) { for (WalletSimulation currentWallet : simulations.values()) {
if(currentWallet.willSend()){ if(currentWallet.willSend()){
...@@ -269,7 +274,11 @@ public class GGBWalletConfiguration extends AbstractConfiguration { ...@@ -269,7 +274,11 @@ public class GGBWalletConfiguration extends AbstractConfiguration {
notification.source.path().name() + " to " + notification.target.path().name()); notification.source.path().name() + " to " + notification.target.path().name());
if (currentStep < n_steps) { if (currentStep < n_steps) {
nextTransaction(); try {
nextTransaction();
} catch (InterruptedException ex) {
Exceptions.printStackTrace(ex);
}
} else { } else {
if (simulationFinished != null) { if (simulationFinished != null) {
simulationFinished.success(null); simulationFinished.success(null);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment