Newer
Older
import java.util.concurrent.TimeUnit;
import com.typesafe.config.Config;
import com.typesafe.config.ConfigFactory;
Simon Könnecke
committed
import fucoin.wallet.WalletImpl;
import scala.concurrent.Await;
import javax.swing.*;
public static ActorRef remoteSuperVisorActor;
private static JTextField walletNameField = new JTextField(5);
private static JTextField pathField = new JTextField(5);
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");
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("Remote", config);
JPanel dialogPanel = createDialogPanel();
Timeout timeout = new Timeout(5, TimeUnit.SECONDS);
ActorRef preknownNeighbour = null;
String walletName = null;
String path = null;
while (preknownNeighbour == null) {
int result = JOptionPane.showConfirmDialog(null, dialogPanel, "Connect to wallet network", JOptionPane.OK_CANCEL_OPTION);
if (result == JOptionPane.OK_OPTION) {
walletName = walletNameField.getText();
path = pathField.getText();
}
// terminate if user clicked abort
if (path == null) {
system.terminate();
}
// tell the node that we want to join the network
ActorSelection selection = system.actorSelection(path);
try {
preknownNeighbour = Await.result(selection.resolveOne(timeout), timeout.duration());
} catch (Exception e) {
System.err.println("Something went wrong while resolving: " + e.getMessage());
}
}
system.actorOf(WalletImpl.props(preknownNeighbour, walletName), walletName);
}
private static JPanel createDialogPanel() {
JPanel dialogPanel = new JPanel();
dialogPanel.setLayout(new BoxLayout(dialogPanel, BoxLayout.PAGE_AXIS));
dialogPanel.add(new JLabel("Pick your wallet name: "));
dialogPanel.add(walletNameField);
dialogPanel.add(new JLabel("Enter a neighbour node address: "));
dialogPanel.add(pathField);
return dialogPanel;