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

3

6

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!

Kristin answered 13/3, 2014 at 21:45 Comment(0)
T
7

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();
}
Tuberculous answered 16/3, 2016 at 16:51 Comment(2)
how do you receive the object you pass (third argument) while creating the agent in the Agent Class?Parted
@joedavid With the getArguments method of the Agent class.Slagle
L
1

A Peripheral container can be started as follows java jade.Boot -container -host x.x.x.x -agents z:package.agent;y:package.agent where x.x.x.x is ip of main contaner, z is the name you give to the first agent, y is the name you give to the second agent and package is the package that contains the agents in a jar file

Larkins answered 20/2, 2015 at 17:1 Comment(0)
B
0

Just to add to the solution given by Tafadzwa Chikudo, first you need to create a Main container, you can do so with the following command java jade.boot -gui, this simply creates a main container with the GUI. You can find the IP of the main container either from the GUI or the command line output you get from running the initial commands.

To add additional agents in their own containers, you can run java jade.Boot -container -host IP -agents agent_name1:package.agent_classname;agent_name2:package.agent_classname. "package" is the folder where the class is stored.

Bedpan answered 3/5, 2023 at 9:31 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.