📄 bookbuyeragenttest.java
字号:
package bookTrading.buyer;
import java.util.Date;
import jade.core.Profile;
import jade.core.ProfileImpl;
import jade.core.Runtime;
import jade.wrapper.AgentController;
import jade.wrapper.ContainerController;
public class BookBuyerAgentTest {
public static 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 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);
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;
}
/**
* @param args
*/
public static void main(String[] args) {
AgentController buyerAgentController =
BookBuyerAgentTest.startBuyerAgent(
"202.114.215.6", "1099", "buyer");
Date deadline = new Date();
deadline.setTime(deadline.getTime() + 1000 * 3600);
BookInfo info = new BookInfo("Book1", 80, 120, deadline);
try {
buyerAgentController.putO2AObject(info, false);
}
catch(Exception e) {
e.printStackTrace();
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -