File PhysicalHostInter.java¶
File List > java > skydata > PhysicalHostInter.java
Go to the documentation of this file
package skydata;
import java.io.FileReader;
import java.io.IOException;
import java.io.Reader;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import org.yaml.snakeyaml.Yaml;
import com.fasterxml.jackson.databind.ObjectMapper;
import jade.core.AID;
import jade.core.Profile;
import jade.core.ProfileImpl;
import jade.core.Runtime;
import jade.util.ExtendedProperties;
import jade.wrapper.AgentContainer;
import jade.wrapper.AgentController;
import jade.wrapper.ControllerException;
public class PhysicalHostInter {
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 hostAddress = "localhost";
ExtendedProperties p = new ExtendedProperties();
p.setProperty("gui", data.get("gui").toString());
p.setIntProperty("jade_core_messaging_MessageManager_poolsize", (int)data.getOrDefault("nb_thread", 5));
p.setIntProperty("jade_core_messaging_MessageManager_maxqueuesize", (int)data.getOrDefault("maxqueuesize", 10000000));
ProfileImpl pc = new ProfileImpl(p);
pc.setParameter(ProfileImpl.SERVICES,
"jade.core.event.NotificationService;jade.core.mobility.AgentMobilityService;jade.core.migration.InterPlatformMobilityService");
pc.setParameter(ProfileImpl.ACCEPT_FOREIGN_AGENTS, "true");
int platformPort = (Integer)data.get("port");
String name = (String)data.get("name");
pc.setParameter(ProfileImpl.MAIN_PORT, String.valueOf(platformPort));
pc.setParameter(ProfileImpl.PLATFORM_ID, (String) data.get("name"));
String platformIP = p.getProperty("PLATFORM_IP");
String platformID = (String) data.get("p_id");
Object[] platformParams = new Object[] { platformIP, platformPort, platformID, waitingTimeAfterSending };
AgentContainer container = rt.createMainContainer(pc);
container.start();
ProfileImpl pci = new ProfileImpl((String) platformParams[0], (int) platformParams[1],
(String) platformParams[2], false);
pci.setParameter(ProfileImpl.MAIN_HOST, hostAddress);
pci.setParameter(ProfileImpl.CONTAINER_NAME, "Harbour");
pci.setParameter(Profile.SERVICES,
"jade.core.event.NotificationService;jade.core.mobility.AgentMobilityService;jade.core.migration.InterPlatformMobilityService");
pci.setParameter(ProfileImpl.ACCEPT_FOREIGN_AGENTS, "true");
AgentContainer agc = rt.createAgentContainer(pci);
ObjectMapper objectMapper = new ObjectMapper();
HashMap<String, Object> argsSKHM = new HashMap<>();
argsSKHM.put("name", name);
argsSKHM.put("address", hostAddress);
argsSKHM.put("params", objectMapper.writeValueAsString(data));
argsSKHM.put("platform", platformParams);
Set<AID> harbours = new HashSet<>();
AgentController h = agc.createNewAgent("Harbour_manager", "skydata.internal.agents.SKHM",
new Object[] { argsSKHM, harbours });
h.start();
} catch (IOException | ControllerException e) {
e.printStackTrace();
}
}
}