Skip to content
Snippets Groups Projects
Unverified Commit b165a568 authored by David Bohn's avatar David Bohn
Browse files

Added helper to handle cases, where label fields are not well-formed

parent 727b008a
No related branches found
No related tags found
1 merge request!6Overlay topology
...@@ -14,6 +14,7 @@ import fucoin.actions.transaction.ActionGetAmount; ...@@ -14,6 +14,7 @@ import fucoin.actions.transaction.ActionGetAmount;
import fucoin.actions.transaction.ActionGetAmountAnswer; import fucoin.actions.transaction.ActionGetAmountAnswer;
import fucoin.actions.transaction.ActionNotifyObserver; import fucoin.actions.transaction.ActionNotifyObserver;
import fucoin.configurations.internal.ConfigurationCreator; import fucoin.configurations.internal.ConfigurationCreator;
import fucoin.configurations.internal.NodeHelper;
import fucoin.supervisor.SuperVisorImpl; import fucoin.supervisor.SuperVisorImpl;
import fucoin.wallet.WalletImpl; import fucoin.wallet.WalletImpl;
import org.gephi.graph.api.Edge; import org.gephi.graph.api.Edge;
...@@ -98,7 +99,7 @@ public abstract class AbstractConfiguration extends AbstractNode { ...@@ -98,7 +99,7 @@ public abstract class AbstractConfiguration extends AbstractNode {
public void spawnWalletsFromNodes(Collection<Node> nodes, boolean createGUI) throws Exception { public void spawnWalletsFromNodes(Collection<Node> nodes, boolean createGUI) throws Exception {
Future<Object> future = Patterns.ask(superVisor, new ActionAnnounceWalletCreation(nodes.size(), self()), timeout); Future<Object> future = Patterns.ask(superVisor, new ActionAnnounceWalletCreation(nodes.size(), self()), timeout);
for (Node node : nodes) { for (Node node : nodes) {
String nameOfTheWallet = node.getLabel(); String nameOfTheWallet = NodeHelper.nameOfNode(node);
createWallet(nameOfTheWallet, createGUI); createWallet(nameOfTheWallet, createGUI);
} }
Await.result(future, timeout.duration()); Await.result(future, timeout.duration());
...@@ -108,7 +109,7 @@ public abstract class AbstractConfiguration extends AbstractNode { ...@@ -108,7 +109,7 @@ public abstract class AbstractConfiguration extends AbstractNode {
* Fetch a random wallet * Fetch a random wallet
*/ */
public ActorRef getRandomWallet() { public ActorRef getRandomWallet() {
return activeActors.get(ThreadLocalRandom.current().nextInt(activeActors.size())); return wallets().get(ThreadLocalRandom.current().nextInt(activeActors.size()));
} }
public List<ActorRef> wallets() { public List<ActorRef> wallets() {
...@@ -218,7 +219,7 @@ public abstract class AbstractConfiguration extends AbstractNode { ...@@ -218,7 +219,7 @@ public abstract class AbstractConfiguration extends AbstractNode {
} }
nodes.stream().forEach(node -> { nodes.stream().forEach(node -> {
ActorRef wallet = walletByName(node.getLabel()); ActorRef wallet = getWalletForNode(node);
Edge[] edges = g.getEdges(node).toArray(); Edge[] edges = g.getEdges(node).toArray();
// Search for all reachable neighbours of the node // Search for all reachable neighbours of the node
...@@ -229,9 +230,13 @@ public abstract class AbstractConfiguration extends AbstractNode { ...@@ -229,9 +230,13 @@ public abstract class AbstractConfiguration extends AbstractNode {
return edge.getTarget(); return edge.getTarget();
} }
return edge.getSource(); return edge.getSource();
}).map(target -> walletByName(target.getLabel())).collect(Collectors.toList()); }).map(this::getWalletForNode).collect(Collectors.toList());
wallet.tell(new ActionAddOverlayNeighbours(overlayNeighbours), self()); wallet.tell(new ActionAddOverlayNeighbours(overlayNeighbours), self());
}); });
} }
protected ActorRef getWalletForNode(Node node) {
return walletByName(NodeHelper.nameOfNode(node));
}
} }
...@@ -8,9 +8,11 @@ import fucoin.actions.transaction.ActionGetAmount; ...@@ -8,9 +8,11 @@ import fucoin.actions.transaction.ActionGetAmount;
import fucoin.actions.transaction.ActionGetAmountAnswer; import fucoin.actions.transaction.ActionGetAmountAnswer;
import fucoin.configurations.internal.ConfigurationName; import fucoin.configurations.internal.ConfigurationName;
import fucoin.configurations.internal.GephiLoader; import fucoin.configurations.internal.GephiLoader;
import fucoin.configurations.internal.NodeHelper;
import fucoin.gui.gephi.GephiFileSelector; import fucoin.gui.gephi.GephiFileSelector;
import fucoin.gui.gephi.GraphWindow; import fucoin.gui.gephi.GraphWindow;
import org.gephi.graph.api.Graph; import org.gephi.graph.api.Graph;
import org.gephi.graph.api.Node;
import scala.concurrent.Future; import scala.concurrent.Future;
import scala.concurrent.duration.Duration; import scala.concurrent.duration.Duration;
...@@ -50,7 +52,7 @@ public class GephiConfiguration extends AbstractConfiguration { ...@@ -50,7 +52,7 @@ public class GephiConfiguration extends AbstractConfiguration {
graphWindow.addNodeClickHandler((node, event) -> { graphWindow.addNodeClickHandler((node, event) -> {
// get associated wallet and ask for its amount // get associated wallet and ask for its amount
ActorRef wallet = walletByName(node.getLabel()); ActorRef wallet = getWalletForNode(node);
Future<Object> future = Patterns.ask(wallet, new ActionGetAmount(), timeout); Future<Object> future = Patterns.ask(wallet, new ActionGetAmount(), timeout);
future.onSuccess(new OnSuccess<Object>() { future.onSuccess(new OnSuccess<Object>() {
...@@ -58,7 +60,7 @@ public class GephiConfiguration extends AbstractConfiguration { ...@@ -58,7 +60,7 @@ public class GephiConfiguration extends AbstractConfiguration {
public void onSuccess(Object result) throws Throwable { public void onSuccess(Object result) throws Throwable {
// display the amount when an answer is received // display the amount when an answer is received
ActionGetAmountAnswer answer = (ActionGetAmountAnswer) result; ActionGetAmountAnswer answer = (ActionGetAmountAnswer) result;
graphWindow.setInfobarText(node.getLabel()+" has "+answer.amount+" FUCs"); graphWindow.setInfobarText(NodeHelper.nameOfNode(node)+" has "+answer.amount+" FUCs");
} }
}, context().dispatcher()); }, context().dispatcher());
}); });
......
package fucoin.configurations.internal;
import org.gephi.graph.api.Node;
public class NodeHelper {
public static String nameOfNode(Node n) {
String label = n.getLabel();
if (label == null || label.isEmpty()) {
return "Wallet" + n.getId();
}
if (Character.isDigit(label.charAt(0))) {
return "Wallet" + label;
}
return label;
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment