Skip to content
Snippets Groups Projects
Commit 8cbbf76e authored by Luca Keidel's avatar Luca Keidel
Browse files

Implemented remote address selection dialog

parent 35e9d4e5
No related branches found
No related tags found
1 merge request!3Preliminary result of the software
...@@ -16,7 +16,7 @@ import java.util.List; ...@@ -16,7 +16,7 @@ import java.util.List;
public class Main { public class Main {
private static int numberOfWallets = 2; private static int numberOfWallets = 1;
private static ActorSystem cSystem; private static ActorSystem cSystem;
......
...@@ -15,9 +15,17 @@ public class MainRemote { ...@@ -15,9 +15,17 @@ public class MainRemote {
public static void main(String[] args) throws InterruptedException { public static void main(String[] args) throws InterruptedException {
//Load configuration from current directory or from resources directory of jar
File file = new File("application.conf"); File file = new File("application.conf");
System.out.println("config found? " + file.exists());
Config config = ConfigFactory.parseFile(file); Config config = ConfigFactory.parseFile(file);
if (!file.exists()) {
System.out.println("Load default application.conf");
config = ConfigFactory.parseResources("application.conf");
} else {
System.out.println("Load local application.conf");
}
//Init System Actor System
ActorSystem system = ActorSystem.create("Test", config); ActorSystem system = ActorSystem.create("Test", config);
Address address = new Address("akka.tcp", "Core", "127.0.0.1", 1234); Address address = new Address("akka.tcp", "Core", "127.0.0.1", 1234);
......
...@@ -4,7 +4,9 @@ import akka.actor.ActorRef; ...@@ -4,7 +4,9 @@ import akka.actor.ActorRef;
import akka.actor.UntypedActorContext; import akka.actor.UntypedActorContext;
import fucoin.AbstractNode; import fucoin.AbstractNode;
public abstract class Action<T extends AbstractNode> { import java.io.Serializable;
public abstract class Action<T extends AbstractNode> implements Serializable{
private ActorRef self; private ActorRef self;
public final void doAction(T abstractNode) { public final void doAction(T abstractNode) {
......
...@@ -12,6 +12,7 @@ public class ActionJoin extends GeneralAction { ...@@ -12,6 +12,7 @@ public class ActionJoin extends GeneralAction {
UntypedActorContext context, AbstractNode node) { UntypedActorContext context, AbstractNode node) {
ActionJoinAnswer aja = new ActionJoinAnswer(); ActionJoinAnswer aja = new ActionJoinAnswer();
aja.someNeighbors.putAll(node.getKnownNeighbors()); aja.someNeighbors.putAll(node.getKnownNeighbors());
System.out.println("Answer to "+sender.path().name());
sender.tell(aja, self); sender.tell(aja, self);
} }
......
package fucoin.gui; package fucoin.gui;
import akka.actor.ActorSelection;
import fucoin.wallet.AbstractWallet; import fucoin.wallet.AbstractWallet;
import javax.swing.*; import javax.swing.*;
...@@ -59,7 +60,12 @@ public class WalletGuiControlImpl implements WalletGuiControl { ...@@ -59,7 +60,12 @@ public class WalletGuiControlImpl implements WalletGuiControl {
JTextField sendToNewEdt = new JTextField(); JTextField sendToNewEdt = new JTextField();
centerup2.add(sendToNewEdt, BorderLayout.CENTER); centerup2.add(sendToNewEdt, BorderLayout.CENTER);
JButton addNewButton = new JButton("Add"); JButton addNewButton = new JButton("Add");
addNewButton.addActionListener(e -> txtSendTo.addItem(sendToNewEdt.getText())); addNewButton.addActionListener(e -> {
ActorSelection selection = wallet.getContext().actorSelection(sendToNewEdt.getText());
System.out.println(selection);
//selection.tell("Hallo!", self());
//txtSendTo.addItem();
});
centerup2.add(addNewButton, BorderLayout.EAST); centerup2.add(addNewButton, BorderLayout.EAST);
centerPanel.add(centerup2); centerPanel.add(centerup2);
......
package fucoin.wallet; package fucoin.wallet;
import akka.actor.ActorRef; import akka.actor.ActorRef;
import akka.actor.ActorSelection;
import akka.actor.Props; import akka.actor.Props;
import fucoin.actions.ClientAction; import fucoin.actions.ClientAction;
import fucoin.actions.join.ActionJoin; import fucoin.actions.join.ActionJoin;
...@@ -11,6 +12,8 @@ import fucoin.actions.transaction.ActionGetAmountAnswer; ...@@ -11,6 +12,8 @@ import fucoin.actions.transaction.ActionGetAmountAnswer;
import fucoin.actions.transaction.ActionInvokeSentMoney; import fucoin.actions.transaction.ActionInvokeSentMoney;
import fucoin.gui.WalletGuiControl; import fucoin.gui.WalletGuiControl;
import javax.swing.*;
public class WalletImpl extends AbstractWallet { public class WalletImpl extends AbstractWallet {
private ActorRef preKnownNeighbour; private ActorRef preKnownNeighbour;
...@@ -29,6 +32,14 @@ public class WalletImpl extends AbstractWallet { ...@@ -29,6 +32,14 @@ public class WalletImpl extends AbstractWallet {
this.preKnownNeighbourName = preKnownNeighbourName; this.preKnownNeighbourName = preKnownNeighbourName;
this.preKnownNeighbour = preKnownNeighbour; this.preKnownNeighbour = preKnownNeighbour;
this.remoteSuperVisorActor = remoteSuperVisorActor; this.remoteSuperVisorActor = remoteSuperVisorActor;
if(remoteSuperVisorActor == null){
String path = JOptionPane.showInputDialog(null, "Enter a neighbour address: ");
System.out.println(path);
ActorSelection selection = getContext().actorSelection(path);
selection.tell(new ActionJoin(), self());
//selection.tell("Hallo!", self());
}
} }
public static Props props(ActorRef preKnownNeighbour, String preKnownNeighbourName, public static Props props(ActorRef preKnownNeighbour, String preKnownNeighbourName,
...@@ -59,6 +70,10 @@ public class WalletImpl extends AbstractWallet { ...@@ -59,6 +70,10 @@ public class WalletImpl extends AbstractWallet {
((ClientAction) message).doAction(this); ((ClientAction) message).doAction(this);
} }
if (message instanceof ActionJoin){
((ActionJoin) message).doAction(this);
}
} }
@Override @Override
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment