[java]
/**
* Section 5.6 page 112
*
**/
import jade.core.Runtime;
import jade.core.*;
import jade.wrapper.*;
public class StartBuyerAgent {
public static void main(String args[]) {
StartBuyerAgent s = new StartBuyerAgent();
s.startBuyerAgent("localhost", "1099", "newBuyer");
}
public AgentController startBuyerAgent(String host, // JADE Book Trading environment Main Container host
String port, // JADE Book Trading environment Main Container port
String name // Book Buyer agent name
) {
// Retrieve the singleton instance of the JADE Runtime
Runtime rt = Runtime.instance();
// Create a main container to host the Book Buyer agent
Profile p = new ProfileImpl();
p.setParameter(Profile.MAIN_HOST, host);
p.setParameter(Profile.MAIN_PORT, port);
ContainerController cc = rt.createMainContainer(p); // notice that in the book it was rt.createAgentContainer(p) which requires a main-container to be already active
if (cc != null) {
// Create the Book Buyer agent and start it
try {
AgentController ac = cc.createNewAgent(name, "bookTrading.buyer.BookBuyerAgent", null);
ac.start();
return ac;
}
catch (Exception e) {
e.printStackTrace();
}
}
return null;
}
}
[/java]