Skip to content
Snippets Groups Projects
MainRemote.java 2.02 KiB
Newer Older
Michael Kmoch's avatar
Michael Kmoch committed
package fucoin;

import java.io.File;
import java.util.concurrent.TimeUnit;
Michael Kmoch's avatar
Michael Kmoch committed

import akka.actor.ActorRef;
import akka.actor.ActorSelection;
Michael Kmoch's avatar
Michael Kmoch committed
import akka.actor.ActorSystem;
import akka.actor.Address;

import akka.util.Timeout;
Michael Kmoch's avatar
Michael Kmoch committed
import com.typesafe.config.Config;
import com.typesafe.config.ConfigFactory;
import scala.concurrent.Await;

import javax.swing.*;
Michael Kmoch's avatar
Michael Kmoch committed

public class MainRemote {
    public static ActorRef remoteSuperVisorActor;

    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);


        Timeout timeout = new Timeout(5, TimeUnit.SECONDS);
        ActorRef preknownNeighbour = null;

        while (preknownNeighbour == null) {

            // get an address from a node which should be our preknown neighbour
            String path = JOptionPane.showInputDialog(null, "Enter a neighbour node address: ");

            // 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());
            }
        }

        // spawn wallet
        system.actorOf(WalletImpl.props(preknownNeighbour, "Remote1"), "Remote1");
Michael Kmoch's avatar
Michael Kmoch committed
}