[英]Multi-platform JADE
我正在尝试在同一主机上生成更多的Jade实例。 我知道可以通过cmd行,但是我无法使用某些Java代码来做到这一点。 我无法在Java中运行命令行,因为这样一来,我可能会丢失一些有关platfomr的信息。有人可以帮助我吗? 下面我的代码和错误:
public class MainCMD_ {
static String classAgentName= "Agents.MyAgent";
static int agentNum=6;
public static void main(String[] args) throws IOException {
// TODO Auto-generated method stub
String platformHost= "localhost";
String platformName="Platform_";
int platformPort= 2000;
for (int i =1; i<3;i++) {
platformName="Platform_"+i;
while(!isAvailablePort(platformPort)){
platformPort++;
}
//new jade.Boot3(new String[] {"-local-host",platformHost,"-local-port",Integer.toString(platformPort),"-name",platformName,"-gui"});
genPlatform(platformHost,platformName,platformPort);
System.out.println("Platform "+platformName+" created!");
}
}
private static void genPlatform (String platformHost, String platformName, int platformPort) {
Runtime runtime = Runtime.instance();
ProfileImpl profile = new ProfileImpl();
profile.setParameter(Profile.PLATFORM_ID, platformName);
profile.setParameter(Profile.LOCAL_HOST, platformHost);
profile.setParameter(Profile.LOCAL_PORT, Integer.toString(platformPort));
profile.setParameter(Profile.GUI, "true");
profile.setParameter(Profile.MAIN, "false");
//profile.setParameter(Profile.CONTAINER_NAME, "MainContainer");
//System.out.println(profile.getProperties());
ContainerController cc = runtime.createMainContainer(profile);
AgentController ac;
for(int i = 1; i<agentNum;i++) {
try {
ac=cc.createNewAgent("MyAgent"+i, classAgentName, null);
ac.start();
} catch (StaleProxyException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
private static boolean isAvailablePort(int port) {
//metodo per verificare che la porta sia disponibile
ServerSocket ss = null;
DatagramSocket ds = null;
try {
ss = new ServerSocket(port);
ss.setReuseAddress(true);
ds = new DatagramSocket(port);
ds.setReuseAddress(true);
return true;
} catch (IOException e) {
} finally {
if (ds != null) {
ds.close();
}
if (ss != null) {
try {
ss.close();
} catch (IOException e) {
}
}
}
return false;
}
}
安慰
set 15, 2018 5:56:06 PM jade.core.Runtime beginContainer
INFORMAZIONI: ----------------------------------
This is JADE 4.4.0 - revision 6778 of 21-12-2015 12:24:43
downloaded in Open Source, under LGPL restrictions,
at http://jade.tilab.com/
----------------------------------------
set 15, 2018 5:56:06 PM jade.imtp.leap.LEAPIMTPManager initialize
INFORMAZIONI: Listening for intra-platform commands on address:
- jicp://192.168.1.100:2000
set 15, 2018 5:56:06 PM jade.core.AgentContainerImpl init
AVVERTENZA: Automatic main-detection mechanism initialization failed
(Error setting up multicast socket - Caused by: Can't assign requested
address). Mechanism disabled!
set 15, 2018 5:56:06 PM jade.core.BaseService init
INFORMAZIONI: Service jade.core.management.AgentManagement initialized
set 15, 2018 5:56:07 PM jade.core.BaseService init
INFORMAZIONI: Service jade.core.messaging.Messaging initialized
set 15, 2018 5:56:07 PM jade.core.BaseService init
INFORMAZIONI: Service jade.core.resource.ResourceManagement initialized
set 15, 2018 5:56:07 PM jade.core.BaseService init
INFORMAZIONI: Service jade.core.mobility.AgentMobility initialized
set 15, 2018 5:56:07 PM jade.core.BaseService init
INFORMAZIONI: Service jade.core.event.Notification initialized
set 15, 2018 5:56:07 PM jade.mtp.http.HTTPServer <init>
INFORMAZIONI: HTTP-MTP Using XML parser .
com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl$JAXPSAXParser
set 15, 2018 5:56:07 PM jade.core.messaging.MessagingService boot
INFORMAZIONI: MTP addresses:
http://mbp-di-mauro:7778/acc
set 15, 2018 5:56:07 PM jade.core.AgentContainerImpl joinPlatform
INFORMAZIONI: --------------------------------------
如您所见,在这里启动Platform 1
Agent container Main-Container@192.168.1.100 is ready.
--------------------------------------------
Hello, I'm agent
I'm going to ...
Hello, I'm agent
I'm going to ...
Hello, I'm agent
I'm going to ...
Hello, I'm agent
I'm going to ...
Platform Platform_1 created!
Hello, I'm agent
I'm going to ...
set 15, 2018 5:56:07 PM jade.core.Runtime beginContainer
INFORMAZIONI: ----------------------------------
This is JADE 4.4.0 - revision 6778 of 21-12-2015 12:24:43
downloaded in Open Source, under LGPL restrictions,
at http://jade.tilab.com/
----------------------------------------
set 15, 2018 5:56:07 PM jade.imtp.leap.LEAPIMTPManager initialize
INFORMAZIONI: Listening for intra-platform commands on address:
- jicp://192.168.1.100:2000
- jicp://192.168.1.100:2001
set 15, 2018 5:56:07 PM jade.core.AgentContainerImpl init
AVVERTENZA: Automatic main-detection mechanism initialization failed
(Error setting up multicast socket - Caused by: Can't assign requested
address). Mechanism disabled!
set 15, 2018 5:56:07 PM jade.core.AgentContainerImpl joinPlatform
GRAVE: Some problem occurred while joining agent platform.
jade.core.ProfileException: Can't get a proxy to the Platform Manager -
这里的错误
Caused by: Wrong platform name Platform_1. It should be Platform_2
at jade.core.ProfileImpl.createPlatformManager(ProfileImpl.java:529)
at jade.core.ProfileImpl.getPlatformManager(ProfileImpl.java:442)
at jade.core.ProfileImpl.getServiceManager(ProfileImpl.java:456)
at jade.core.AgentContainerImpl.init(AgentContainerImpl.java:347)
at
jade.core.AgentContainerImpl.joinPlatform(AgentContainerImpl.java:494)
at jade.core.Runtime.createMainContainer(Runtime.java:159)
at MainCMD_.genPlatform(MainCMD_.java:55)
at MainCMD_.main(MainCMD_.java:33)
Nested Exception:
jade.core.IMTPException: Wrong platform name Platform_1. It should be
Platform_2
at jade.imtp.leap.CommandDispatcher.
setPlatformManager(CommandDispatcher.java:231)
at jade.imtp.leap.CommandDispatcher.
registerSkeleton(CommandDispatcher.java:731)
at jade.imtp.leap.LEAPIMTPManager.exportPlatformManager
(LEAPIMTPManager.java:198)
at jade.core.ProfileImpl.createPlatformManager(ProfileImpl.java:518)
at jade.core.ProfileImpl.getPlatformManager(ProfileImpl.java:442)
at jade.core.ProfileImpl.getServiceManager(ProfileImpl.java:456)
at jade.core.AgentContainerImpl.init(AgentContainerImpl.java:347)
at
jade.core.AgentContainerImpl.joinPlatform(AgentContainerImpl.java:494)
at jade.core.Runtime.createMainContainer(Runtime.java:159)
at MainCMD_.genPlatform(MainCMD_.java:55)
at MainCMD_.main(MainCMD_.java:33)
Exception in thread "main" java.lang.NullPointerException
at MainCMD_.genPlatform(MainCMD_.java:61)
at MainCMD_.main(MainCMD_.java:33)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.