package pl.pw.edu.mini.dos.master;

import javafx.scene.paint.Material;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import pl.pw.edu.mini.dos.master.rmi.RMIServer;

import java.net.UnknownHostException;
import java.rmi.RemoteException;
import java.util.Scanner;
import pl.pw.edu.mini.dos.communication.ErrorEnum;
import pl.pw.edu.mini.dos.master.node.Node;

import java.util.HashMap;
import java.util.Map;

public class Master {
    private static final Logger logger = LoggerFactory.getLogger(Master.class);

    private Map<String, Node> nodes;

    public Master() {
        nodes = new HashMap<String, Node>();
    }

    /**
     * Register  a new node.
     * @param host node's IP
     * @return ErrorEnum
     */
    public ErrorEnum addNode(String host){
        Node newNode = new Node(host);
        // TODO check status
        nodes.put(host, new Node(host));
        return ErrorEnum.SUCCESS;
    }

    public static void main(String[] args) {
        System.setProperty("java.rmi.server.hostname", "localhost");
        System.setProperty("java.security.policy", "/home/ghash/Dokumenty/mini-dos/src/main/resources/client.policy");
        logger.info("Server started!");
        try {
            Master master = new Master();
            RMIServer server = new RMIServer(master);
            
            logger.info("Server closed!");
        } catch (UnknownHostException e) {
            e.printStackTrace();
            logger.error(e.getMessage().toString());
        } catch (RemoteException e) {
            e.printStackTrace();
            logger.error(e.getMessage().toString());
        }
    }
}

@@ -1303,16 +1303,17 @@
 aster);%0A
+%0A
         
@@ -1316,16 +1316,356 @@
         
+System.out.print(%22*Enter 'q' to stop master.%22);%0A            Scanner scanner = new Scanner (System.in);%0A            while(scanner.hasNext()) %7B%0A                String text = scanner.next();%0A                if(text.equals(%22q%22)) %7B%0A                    break;%0A                %7D%0A                // operate%0A            %7D%0A            server.close();
 %0A       

Add console to master