The previous example doesn't actually do anything, all code is just run inside the setup() method. Typical agents implement cmplex behaviours, which may involve multiple simultaneous related or unrelated tasks, rather than forcing you to write multithreaded agents (with all of the problems that this can cause) jade introduces a system of Behaviours to assist you in building and re-using agent functionality.
Essentially when using Jade's behaviours each agent can be seen as a set of cooperatively multithreading processes ,that is to say that each process gets run, and performs a portion of its task before actively yeilding controll back to the process scheduler. While this may seem old-fashioned it adds a degree of determinism to writing agents, and allows for a fairly natural decomposition of the agents overall behaviour.
Let us return to the previous example, instead of printing out the information in the setup() method let us place it into the simplest type of behaviour: a SimpleBehaviour
Showing you cm30174/jade/examples/behaviours/HelloWorldBehaviors.javapackage owen.agent.tutorials;
import jade.core.*;
import jade.core.behaviours.SimpleBehaviour;
public class HelloWorldBehaviours extends Agent{
public void setup(){
SimpleBehaviour hello_behaviour = new SimpleBehaviour(this){
boolean finished = false;
public void action(){
System.out.println("Hello World Behaviour run: Hello World!");
System.out.println("-----About Me:-----");
System.out.println("My local name is:"+getLocalName());
System.out.println("My globally unique name is:"+getName() );
System.out.println("-----About Here:-----");
Location l = here();
System.out.println("I am running in a location called:"+l.getName());
System.out.println("Which is identified uniquely as:"+l.getID());
System.out.println("And is contactable at:"+l.getAddress());
System.out.println("Using the protocol:"+l.getProtocol());
finished = true;
}
public boolean done(){
return finished;
}
};
addBehaviour(hello_behaviour);
}
}