Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create containers and add agents into it in JADE?

I'm just a beginner at JADE. I would like to know how to create containers other than the main container and add multiple agents into it. A full code of creation would be appreciated.

Thanks!

like image 239
user3382935 Avatar asked Mar 13 '14 21:03

user3382935


1 Answers

As stated in Tafadzwa Chikudo answer, the usual way to start a container is by launching jade.Boot from the command line (or in a shell script).

But it is also possible to do it inside another Java program, using the "JADE in-process interface" (package jade.wrapper, class jade.core.Runtime).

For instance, the following code creates a "peripheral" container (connecting to a main container on localhost) and launch one agent in it.

//Get the JADE runtime interface (singleton)
jade.core.Runtime runtime = jade.core.Runtime.instance();
//Create a Profile, where the launch arguments are stored
Profile profile = new ProfileImpl();
profile.setParameter(Profile.CONTAINER_NAME, "TestContainer");
profile.setParameter(Profile.MAIN_HOST, "localhost");
//create a non-main agent container
ContainerController container = runtime.createAgentContainer(profile);
try {
        AgentController ag = container.createNewAgent("agentnick", 
                                      "my.agent.package.AgentClass", 
                                      new Object[] {});//arguments
        ag.start();
} catch (StaleProxyException e) {
    e.printStackTrace();
}
like image 130
Rémi Avatar answered Oct 14 '22 13:10

Rémi