this is the code to start the jade platform:
import jade.core.Profile;
import jade.core.ProfileImpl;
import jade.core.Runtime;
import jade.wrapper.AgentContainer;
import jade.wrapper.AgentController;
public class Run {
public Run() {
Runtime rt = Runtime.instance();
rt.setCloseVM(true);
AgentContainer mc = rt.createMainContainer(new ProfileImpl());
Profile p = new ProfileImpl();
p.setParameter("container-name", "Foo");
AgentContainer ac = rt.createAgentContainer(p);
try{
AgentController rma = mc.createNewAgent("rma", "jade.tools.rma.rma", null);
rma.start();
AgentController ma = mc.createNewAgent("MA", "MobileAgent", null);
ma.start();
}
catch(Exception e){
e.printStackTrace();
}
}
public static void main(String[] args) {
new Run();
}
}
And this is the code for the mobile agent. After being created, the agent moves immediately to the container Foo.
import jade.core.Agent;
import jade.core.Location;
public class MobileAgent extends Agent {
private static final long serialVersionUID = 1L;
@Override
protected void setup() {
System.out.println("Hello World");
Location destination = new jade.core.ContainerID("Foo", null);
doMove(destination);
super.setup();
}
@Override
protected void beforeMove() {
System.out.println("Preparing to move");
super.beforeMove();
}
@Override
protected void afterMove() {
System.out.println("Arrived to destination");
super.afterMove();
}
}