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

Fixed code styling of changed stuff and some small refactorings

parent b0a93ca8
Branches
No related tags found
1 merge request!3Preliminary result of the software
Showing
with 105 additions and 154 deletions
...@@ -6,12 +6,11 @@ import akka.actor.Props; ...@@ -6,12 +6,11 @@ import akka.actor.Props;
import com.typesafe.config.Config; import com.typesafe.config.Config;
import com.typesafe.config.ConfigFactory; import com.typesafe.config.ConfigFactory;
import fucoin.actions.join.ActionJoinAnswer; import fucoin.actions.join.ActionJoinAnswer;
import fucoin.setup.NetworkInterfaceReader;
import fucoin.supervisor.SuperVisorImpl; import fucoin.supervisor.SuperVisorImpl;
import fucoin.wallet.WalletImpl; import fucoin.wallet.WalletImpl;
import java.io.File; import java.io.File;
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
...@@ -27,13 +26,8 @@ public class Main { ...@@ -27,13 +26,8 @@ public class Main {
private static List<ActorRef> cActiveActors = new ArrayList<>(); private static List<ActorRef> cActiveActors = new ArrayList<>();
static { static {
String hostname = "127.0.0.1"; String hostname = NetworkInterfaceReader.readDefaultHostname();
try {
// Fetch IP address to enable network connection
hostname = InetAddress.getLocalHost().getHostAddress();
} catch (UnknownHostException e) {
e.printStackTrace();
}
//Load configuration from current directory or from resources directory of jar //Load configuration from current directory or from resources directory of jar
File file = new File("application.conf"); File file = new File("application.conf");
Config config = ConfigFactory.parseFile(file); Config config = ConfigFactory.parseFile(file);
...@@ -47,8 +41,6 @@ public class Main { ...@@ -47,8 +41,6 @@ public class Main {
//Init System Actor System //Init System Actor System
cSystem = ActorSystem.create("Core", ConfigFactory.parseString("akka.remote.netty.tcp.hostname=" + hostname).withFallback(config)); cSystem = ActorSystem.create("Core", ConfigFactory.parseString("akka.remote.netty.tcp.hostname=" + hostname).withFallback(config));
cSuperVisorActor = cSystem.actorOf(SuperVisorImpl.props(), "SuperVisorImpl"); cSuperVisorActor = cSystem.actorOf(SuperVisorImpl.props(), "SuperVisorImpl");
System.out.print("Supervisor address: ");
System.out.println(cSuperVisorActor.path().toStringWithAddress(cSystem.provider().getDefaultAddress()));
} }
public static void main(String[] args) throws InterruptedException { public static void main(String[] args) throws InterruptedException {
......
...@@ -6,6 +6,7 @@ import akka.actor.ActorSystem; ...@@ -6,6 +6,7 @@ import akka.actor.ActorSystem;
import akka.util.Timeout; import akka.util.Timeout;
import com.typesafe.config.Config; import com.typesafe.config.Config;
import com.typesafe.config.ConfigFactory; import com.typesafe.config.ConfigFactory;
import fucoin.setup.NetworkInterfaceReader;
import fucoin.setup.SelectableNetworkInterface; import fucoin.setup.SelectableNetworkInterface;
import fucoin.setup.SetupDialogPanel; import fucoin.setup.SetupDialogPanel;
import fucoin.wallet.WalletImpl; import fucoin.wallet.WalletImpl;
...@@ -14,20 +15,13 @@ import scala.concurrent.duration.FiniteDuration; ...@@ -14,20 +15,13 @@ import scala.concurrent.duration.FiniteDuration;
import javax.swing.*; import javax.swing.*;
import java.io.File; import java.io.File;
import java.net.*;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
public class MainRemote { public class MainRemote {
public static void main(String[] args) throws InterruptedException { public static void main(String[] args) throws InterruptedException {
String hostname = "127.0.0.1"; String hostname = NetworkInterfaceReader.readDefaultHostname();
try {
// Fetch IP address to enable network connection
hostname = InetAddress.getLocalHost().getHostAddress();
} catch (UnknownHostException e) {
e.printStackTrace();
}
//Load configuration from current directory or from resources directory of jar //Load configuration from current directory or from resources directory of jar
File file = new File("application.conf"); File file = new File("application.conf");
......
...@@ -5,13 +5,14 @@ import akka.actor.UntypedActorContext; ...@@ -5,13 +5,14 @@ import akka.actor.UntypedActorContext;
import fucoin.actions.ClientAction; import fucoin.actions.ClientAction;
import fucoin.actions.persist.ActionSearchMyWallet; import fucoin.actions.persist.ActionSearchMyWallet;
import fucoin.wallet.AbstractWallet; import fucoin.wallet.AbstractWallet;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map.Entry; import java.util.Map.Entry;
/** /**
* This action is the response from a wallet which is already in the network * This action is the response from a wallet which is already in the network
* to a wallet which wants to join the network. * to a wallet which wants to join the network.
* * <p>
* The node in the network sends all its known neighbours which then become * The node in the network sends all its known neighbours which then become
* neighbours of the new node. This action also contains a reference to the * neighbours of the new node. This action also contains a reference to the
* supervisor. If this is the first time the new node learned about the systems * supervisor. If this is the first time the new node learned about the systems
......
package fucoin.actions.transaction; package fucoin.actions.transaction;
import akka.actor.ActorRef;
import akka.actor.UntypedActorContext;
import fucoin.actions.Action; import fucoin.actions.Action;
import fucoin.supervisor.SuperVisorImpl; import fucoin.supervisor.SuperVisorImpl;
......
...@@ -5,7 +5,7 @@ import java.awt.*; ...@@ -5,7 +5,7 @@ import java.awt.*;
public class LogCellRenderer extends DefaultListCellRenderer { public class LogCellRenderer extends DefaultListCellRenderer {
private static final Color SUCCESS_COLOR = new Color(92, 184, 92); private static final Color SUCCESS_COLOR = new Color(56, 127, 56);
private static final Color FAIL_COLOR = new Color(217, 83, 79); private static final Color FAIL_COLOR = new Color(217, 83, 79);
@Override @Override
......
...@@ -5,7 +5,7 @@ public class LogMessage { ...@@ -5,7 +5,7 @@ public class LogMessage {
public enum Context { public enum Context {
TRANSACTION_SUCCESS, TRANSACTION_FAIL, DEBUG TRANSACTION_SUCCESS, TRANSACTION_FAIL, DEBUG
}; }
private String message; private String message;
private Context context; private Context context;
......
package fucoin.gui;
import akka.actor.Address;
import akka.actor.AddressFromURIString;
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
public class WalletCoreGui {
public WalletCoreGui() {
JFrame frame = new JFrame("Manager");
frame.setLayout(new GridLayout(3, 2));
frame.add(new JLabel("Connect to:"));
JTextField input = new JTextField("akka://MySystem/user/main");
frame.add(input);
frame.add(new JLabel("Name:"));
JTextField name = new JTextField("<Name>");
frame.add(name);
JButton button = new JButton("connect");
button.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
/*MessageDispatcherConfigurator mc = null;
String id = input.getText()+"-dispatched";
int hroughput = 1;
Duration d = Duration.ofSeconds(2);
Dispatcher d = new Dispatcher(mc,id, 1, d, Executors.newSingleThreadExecutor(),1000);*/
String path = "akka.tcp://Test@127.0.0.1:1234/user/main";
Address addr = AddressFromURIString.parse(path);
//RemoteScope remoteScope = new RemoteScope(addr);
//Deploy deploy = new Deploy(remoteScope);
//Props remoteWallet = Props.apply(deploy, WalletImpl.class, null);
}
});
frame.add(button);
frame.setSize(300, 300);
frame.setVisible(true);
}
}
package fucoin.setup; package fucoin.setup;
import java.net.Inet6Address; import java.net.*;
import java.net.InetAddress;
import java.net.NetworkInterface;
import java.net.SocketException;
import java.util.*; import java.util.*;
public class NetworkInterfaceReader { public class NetworkInterfaceReader {
...@@ -34,4 +31,19 @@ public class NetworkInterfaceReader { ...@@ -34,4 +31,19 @@ public class NetworkInterfaceReader {
return map; return map;
} }
/**
* Get the IP address, that is resolved by the system from the host name.
* As a fallback, we return 127.0.0.1, i.e. localhost
*/
public static String readDefaultHostname() {
String hostname = "127.0.0.1";
try {
hostname = InetAddress.getLocalHost().getHostAddress();
} catch (UnknownHostException e) {
e.printStackTrace();
}
return hostname;
}
} }
...@@ -55,12 +55,14 @@ public abstract class AbstractWallet extends AbstractNode implements Serializabl ...@@ -55,12 +55,14 @@ public abstract class AbstractWallet extends AbstractNode implements Serializabl
/** /**
* Set new Amount of the wallet. * Set new Amount of the wallet.
*
* @param amount New amount of the wallet * @param amount New amount of the wallet
*/ */
public abstract void setAmount(int amount); public abstract void setAmount(int amount);
/** /**
* Add amount to current amount. * Add amount to current amount.
*
* @param amount value to add to current account. * @param amount value to add to current account.
*/ */
public abstract void addAmount(int amount); public abstract void addAmount(int amount);
...@@ -88,7 +90,6 @@ public abstract class AbstractWallet extends AbstractNode implements Serializabl ...@@ -88,7 +90,6 @@ public abstract class AbstractWallet extends AbstractNode implements Serializabl
public abstract ActorRef getRemoteSuperVisorActor(); public abstract ActorRef getRemoteSuperVisorActor();
/** /**
*
* @param remoteSuperVisorActor * @param remoteSuperVisorActor
*/ */
public abstract void setRemoteSuperVisorActor(ActorRef remoteSuperVisorActor); public abstract void setRemoteSuperVisorActor(ActorRef remoteSuperVisorActor);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment