简体   繁体   English

多平台JADE

[英]Multi-platform JADE

I'm trying to generate more instance of Jade on the same host. 我正在尝试在同一主机上生成更多的Jade实例。 I know that it is possible through cmd line but I'm not able to do it with some java code. 我知道可以通过cmd行,但是我无法使用某些Java代码来做到这一点。 I can't run the command line in Java because, in this way, I can lost some information about the platfomr... Anyone can help me? 我无法在Java中运行命令行,因为这样一来,我可能会丢失一些有关platfomr的信息。有人可以帮助我吗? Below my code and the error: 下面我的代码和错误:

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;

    }
}

Console 安慰

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: --------------------------------------

as you can see here start the Platform 1 如您所见,在这里启动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 -

here the error 这里的错误

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)

Regarding your last question: yes, it is possible. 关于您的最后一个问题:是的,有可能。

Assuming that you work with Eclipse, you could have two (or more) Run Configurations . 假设您使用Eclipse,则可以有两个(或更多) 运行配置 Each configuration should differ by the argument section (corresponding to the args array in your main method). 每个配置的参数部分都应不同(对应于main方法中的args数组)。 With the arguments, you should be able to distinguish the platform and its configuration. 使用参数,您应该能够区分平台及其配置。

As the Runtime.instance(); 作为Runtime.instance(); access indicates, JADE platform handling via code is realized by a Singleton . 访问指示,通过代码处理JADE平台是由Singleton实现的。 Thus, you will not be able to have more than one JADE platform in one JVM. 因此,一个JVM中将不能拥有多个JADE平台。 Using the above approach, each Run Configuration would produce one JVM and you really can send ACL-Messages, instead of moving messages in a platform (JADE won't serialize/ deserialize messages, if you are sending messages between agents in the same platform). 使用上述方法,每个运行配置将产生一个JVM,并且您确实可以发送ACL消息,而不是在平台上移动消息(如果要在同一平台的代理之间发送消息,JADE不会序列化/反序列化消息) 。

Hope this helps! 希望这可以帮助!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM