import jade.core.Profile;
import jade.core.ProfileImpl;
import jade.core.Runtime;
import jade.wrapper.AgentContainer;

/**
 * Program 3: Studentas (mobile agent) demo
 *
 * Creates 4 containers: Auditorija101, Auditorija508, Laboratorija208, and xxx.
 * The xxx container name is the first command-line argument (default: Sporto_Sale).
 *
 * Studentas starts in Auditorija101 and migrates whenever it receives
 * "Testas" or "Egzaminas", preferring unvisited containers.
 * Siuntejas sends those messages every 4 seconds.
 */
public class Run3 {
    public static void main(String[] args) throws Exception {

        String xxxName = (args.length > 0) ? args[0] : "Sporto_Sale";

        Runtime rt = Runtime.instance();
        rt.setCloseVM(true);

        ProfileImpl mainProf = new ProfileImpl();
        mainProf.setParameter(Profile.GUI, "true");
        AgentContainer mainC = rt.createMainContainer(mainProf);

        String[] subNames = {"Auditorija101", "Auditorija508", "Laboratorija208", xxxName};
        AgentContainer[] subContainers = new AgentContainer[subNames.length];
        for (int i = 0; i < subNames.length; i++) {
            ProfileImpl p = new ProfileImpl(false);
            p.setParameter(Profile.CONTAINER_NAME, subNames[i]);
            subContainers[i] = rt.createAgentContainer(p);
        }

        Thread.sleep(1500);

        subContainers[0].createNewAgent(
            "Studentas",
            "agents.Studentas",
            subNames
        ).start();

        Thread.sleep(500);

        mainC.createNewAgent(
            "Siuntejas",
            "agents.Siuntejas",
            new Object[]{"Studentas", "5000"}
        ).start();
    }
}
