Skip to content

File PhysicalHostIntra.java

File List > java > skydata > PhysicalHostIntra.java

Go to the documentation of this file

package skydata;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.io.Reader;
import java.util.Map;

import org.yaml.snakeyaml.Yaml;

import com.fasterxml.jackson.databind.ObjectMapper;

import jade.core.ProfileImpl;
import jade.core.Runtime;
import jade.util.ExtendedProperties;
import jade.util.leap.Properties;
import jade.wrapper.AgentContainer;
import jade.wrapper.AgentController;
import jade.wrapper.ControllerException;
import jade.wrapper.StaleProxyException;

public class PhysicalHostIntra {

    public static void main(String[] args) {

        try {
            Reader reader = new FileReader(args[0]);
            int waitingTimeAfterSending = Integer.parseInt(args[1]);
            Yaml yaml = new Yaml();
            Runtime rt = Runtime.instance();
            @SuppressWarnings("unchecked")
            Map<String, Object> data = (Map<String, Object>) yaml.load(reader);

            String mainAddress = args[2];
            String mainPort = args[3];

            Properties p = new ExtendedProperties();
            p.setProperty("gui", (String) data.get("gui"));

            String name = (String) data.get("name");

            ProfileImpl pci = new ProfileImpl(false);
            pci.setParameter(ProfileImpl.CONTAINER_NAME, name);
            pci.setParameter(ProfileImpl.MAIN_HOST, mainAddress);
            pci.setParameter(ProfileImpl.MAIN_PORT, mainPort);
            pci.setParameter(ProfileImpl.ACCEPT_FOREIGN_AGENTS, "true");
            AgentContainer agc = rt.createAgentContainer(pci);
            Object[] platformParams = new Object[] { null, null, null, waitingTimeAfterSending };
            ObjectMapper objectMapper = new ObjectMapper();
            AgentController h = agc.createNewAgent(name + "_manager", "skydata.internal.agents.SKHM",
                    new Object[] { name, mainAddress, objectMapper.writeValueAsString(data), platformParams });
            h.start();
        } catch (IOException | ControllerException e) {
            e.printStackTrace();
        }

    }
}