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

fixed maven source directory. configurable number of local wallets in main

parent b3ed3a44
No related branches found
No related tags found
1 merge request!3Preliminary result of the software
......@@ -5,7 +5,6 @@
<artifactId>JavaAkkaFuCoin</artifactId>
<version>0.0.1-SNAPSHOT</version>
<build>
<sourceDirectory>src</sourceDirectory>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
......@@ -47,5 +46,10 @@
<artifactId>akka-actor_2.11</artifactId>
<version>2.4.7</version>
</dependency>
<dependency>
<groupId>com.typesafe.akka</groupId>
<artifactId>akka-remote_2.11</artifactId>
<version>2.4.7</version>
</dependency>
</dependencies>
</project>
\ No newline at end of file
......@@ -2,6 +2,7 @@ package fucoin;
import akka.actor.ActorRef;
import akka.actor.ActorSystem;
import akka.actor.Props;
import com.typesafe.config.Config;
import com.typesafe.config.ConfigFactory;
import fucoin.actions.join.ServerActionJoin;
......@@ -15,21 +16,47 @@ import java.util.List;
public class Main {
public static void main(String[] args) throws InterruptedException {
private static int numberOfWallets = 4;
private static ActorSystem cSystem;
private static ActorRef cSuperVisorActor;
private static List<ActorRef> cActiveActors = new ArrayList<>();
static {
//Load configuration from current directory or from resources directory of jar
File file = new File("application.conf");
System.out.println("config found? " + file.exists());
Config config = ConfigFactory.parseFile(file);
ActorSystem system = ActorSystem.create("Core", config);
ActorRef superVisorActor = system.actorOf(SuperVisorImpl.props(), "SuperVisorImpl");
List<ActorRef> activeActors = new ArrayList<>();
ActorRef a1 = system.actorOf(WalletImpl.props(null, "", "Main", superVisorActor), "Main");
ActorRef a2 = system.actorOf(WalletImpl.props(a1, "Main", "Main2", superVisorActor), "Main2");
superVisorActor.tell(new ServerActionJoin("Main"), a1);
superVisorActor.tell(new ServerActionJoin("Main2"), a2);
if (!file.exists()) {
System.out.println("Load default application.conf");
config = ConfigFactory.parseResources("application.config");
} else {
System.out.println("Load local application.conf");
}
//Init System Actor System
cSystem = ActorSystem.create("Core", config);
cSuperVisorActor = cSystem.actorOf(SuperVisorImpl.props(), "SuperVisorImpl");
}
private static void startSupervisor() {
public static void main(String[] args) throws InterruptedException {
createWallets();
}
private static void createWallets() {
//Init Wallets
for (int i = 0; i < numberOfWallets; i++) {
String nameOfTheWallet = "Wallet" + String.valueOf(i);
//chain the wallets. wallet2 knows wallet1, wallet3 knows wallet2 and so on.
String nameOfThePreviousWallet = "";
if (i > 0) {
nameOfThePreviousWallet = "Wallet" + String.valueOf(i - 1);
}
Props props = WalletImpl.props(null, nameOfThePreviousWallet, nameOfTheWallet, cSuperVisorActor);
ActorRef actorRef = cSystem.actorOf(props, nameOfTheWallet);
cSuperVisorActor.tell(new ServerActionJoin(nameOfTheWallet), actorRef);
cActiveActors.add(actorRef);
}
}
}
......@@ -59,13 +59,7 @@ public class WalletGuiControlImpl implements WalletGuiControl {
JTextField sendToNewEdt = new JTextField();
centerup2.add(sendToNewEdt, BorderLayout.CENTER);
JButton addNewButton = new JButton("Add");
addNewButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
txtSendTo.addItem(sendToNewEdt.getText());
}
});
addNewButton.addActionListener(e -> txtSendTo.addItem(sendToNewEdt.getText()));
centerup2.add(addNewButton, BorderLayout.EAST);
centerPanel.add(centerup2);
......
akka {
actor {
provider = "akka.remote.RemoteActorRefProvider"
}
remote {
netty.tcp {
hostname = "127.0.0.1"
}
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment