diff --git a/src/main/java/fucoin/AbstractNode.java b/src/main/java/fucoin/AbstractNode.java index c30bdfdc2104f016ff6e3d130c77a1fbdbf2e2b3..016e3f21d22186b001cb2b7ea171832842a9b3e4 100644 --- a/src/main/java/fucoin/AbstractNode.java +++ b/src/main/java/fucoin/AbstractNode.java @@ -12,6 +12,7 @@ import scala.concurrent.Promise; import java.io.Serializable; import java.util.HashMap; +import org.openide.util.Exceptions; public abstract class AbstractNode extends UntypedActor implements Serializable { protected SnapshotToken currentSnapshotToken; @@ -90,7 +91,7 @@ public abstract class AbstractNode extends UntypedActor implements Serializable } - public Promise<Snapshot> makeSnapshot() { + public Promise<Snapshot> makeSnapshot() throws InterruptedException{ String prefix = ""; if (this instanceof SuperVisorImpl) { prefix = "supervisor"; @@ -105,8 +106,18 @@ public abstract class AbstractNode extends UntypedActor implements Serializable AbstractWallet wallet = (AbstractWallet) this; this.snapshot.addState(wallet.getName(), wallet.getAmount()); } + //Broadcast + int i = 0; for (ActorRef act : getKnownNeighbors().values()) { 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(); } diff --git a/src/main/java/fucoin/configurations/GGBWalletConfiguration.java b/src/main/java/fucoin/configurations/GGBWalletConfiguration.java index 5a59c5d6bb3ccacf66665c3e01a2c2f4819f355d..94059b85d68a2f6872265cfd75748a2ad684e01e 100644 --- a/src/main/java/fucoin/configurations/GGBWalletConfiguration.java +++ b/src/main/java/fucoin/configurations/GGBWalletConfiguration.java @@ -26,6 +26,7 @@ import java.util.List; import java.util.Map; import java.util.stream.Collectors; import java.util.stream.Stream; +import org.openide.util.Exceptions; /** * This configuration spawns 200 wallets to demonstrate the spawning of many headless wallets @@ -185,7 +186,11 @@ public class GGBWalletConfiguration extends AbstractConfiguration { BALANCED_MIN, BALANCED_MAX, BALANCED_ADAPTION)); } start = System.currentTimeMillis() / 1000.; - this.nextTransaction(); + try { + this.nextTransaction(); + } catch (InterruptedException ex) { + Exceptions.printStackTrace(ex); + } simulationFinished.future().onSuccess(new OnSuccess<Void>() { @Override public void onSuccess(Void result) { @@ -195,7 +200,7 @@ public class GGBWalletConfiguration extends AbstractConfiguration { } }, context().dispatcher()); } - private void nextTransaction() { + private void nextTransaction() throws InterruptedException { for(;currentStep < n_steps; currentStep++) { for (WalletSimulation currentWallet : simulations.values()) { if(currentWallet.willSend()){ @@ -269,7 +274,11 @@ public class GGBWalletConfiguration extends AbstractConfiguration { notification.source.path().name() + " to " + notification.target.path().name()); if (currentStep < n_steps) { - nextTransaction(); + try { + nextTransaction(); + } catch (InterruptedException ex) { + Exceptions.printStackTrace(ex); + } } else { if (simulationFinished != null) { simulationFinished.success(null);