首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >多平台JADE

多平台JADE
EN

Stack Overflow用户
提问于 2018-09-16 00:02:10
回答 1查看 391关注 0票数 0

我正在尝试在同一主机上生成更多的Jade实例。我知道这是可以通过cmd行,但我不能用一些java代码。我不能在Java中运行命令行,因为在这种情况下,我可能会丢失一些关于平台的信息。有人能帮我吗?下面是我的代码和错误:

代码语言:javascript
运行
复制
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;

    }
}

控制台

代码语言:javascript
运行
复制
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

代码语言:javascript
运行
复制
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 -

这里的错误

代码语言:javascript
运行
复制
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)
EN

回答 1

Stack Overflow用户

发布于 2018-10-05 15:39:15

关于你的最后一个问题:是的,这是可能的。

假设您使用的是Eclipse,那么您可能有两个(或更多) Run Configurations。每个配置都应该根据参数部分的不同而不同(对应于main方法中的args数组)。通过这些参数,您应该能够区分平台及其配置。

正如Runtime.instance();访问所表明的那样,JADE平台通过代码处理是由Singleton实现的。因此,您不能在一个JVM中拥有多个JADE平台。使用上述方法,每个运行配置将生成一个JVM,并且您真的可以发送ACL消息,而不是在平台中移动消息(如果您在同一平台中的代理之间发送消息,JADE将不会序列化/反序列化消息)。

希望这能有所帮助!

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/52346415

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档