Skip to content
Snippets Groups Projects
Select Git revision
  • 89c2be1f66a92550ef7cd45bf522df6c7cd87273
  • master default
  • dev-group3-qdigest
  • dev-group2-all-aggregations
  • dev-group2-graphs
  • dev-group2-limit-neighbors
  • dev-group1-stefan
  • dev-group3-kim
  • dev-group1-simon
9 results

Main.java

Blame
  • Code owners
    Assign users and groups as approvers for specific file changes. Learn more.
    Main.java 2.62 KiB
    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.ActionTellSupervisor;
    import fucoin.setup.NetworkInterfaceReader;
    import fucoin.supervisor.SuperVisorImpl;
    import fucoin.wallet.WalletImpl;
    
    import java.io.File;
    import java.util.ArrayList;
    import java.util.List;
    
    
    public class Main {
    
        private static int numberOfWallets = 2;
        private static boolean createGUI = false;
    
        private static ActorSystem cSystem;
    
        private static ActorRef cSuperVisorActor;
    
        private static List<ActorRef> cActiveActors = new ArrayList<>();
    
        static {
            String hostname = NetworkInterfaceReader.readDefaultHostname();
    
            //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
            cSystem = ActorSystem.create("Core", ConfigFactory.parseString("akka.remote.netty.tcp.hostname=" + hostname).withFallback(config));
            cSuperVisorActor = cSystem.actorOf(SuperVisorImpl.props(), "SuperVisorImpl");
        }
    
        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);
                Props props;
    
                if (i > 0) {
                    //chain the wallets. wallet2 knows wallet1, wallet3 knows wallet2 and so on.
                    props = WalletImpl.props(cActiveActors.get(i - 1), nameOfTheWallet, createGUI);
                } else {
                    props = WalletImpl.props(null, nameOfTheWallet, createGUI);
                }
    
                ActorRef actorRef = cSystem.actorOf(props, nameOfTheWallet);
    
                // first wallet does not have a neighbour, so it can't send a ActionJoin to anybody
                // instead we send directly an ActionJoinAnswer with the supervisor reference
                if (i == 0) {
                    //actorRef.tell(new ActionJoinAnswer(cSuperVisorActor), cSuperVisorActor);
                    actorRef.tell(new ActionTellSupervisor(cSuperVisorActor), cSuperVisorActor);
                }
    
                cActiveActors.add(actorRef);
            }
        }
    }